:root {
  --board-size: min(88vw, 680px);
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Share button icon */
.share-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.share-icon::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 2px;
  position: relative;
  margin-right: -4px;
  margin-bottom: -6px;
}

.share-icon::after {
  content: "";
  width: 8px;
  height: 8px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  margin-left: -3px;
  margin-top: -5px;
  transform: rotate(45deg);
}

/* Board */
.gomoku-board {
  width: var(--board-size);
  aspect-ratio: 1;
  position: relative;
  border: 10px solid #b97927;
  border-radius: 8px;
  background-color: #d8a951;
  box-sizing: border-box;
  overflow: hidden;
  --board-pad: 5.5%;
  --cell-hit: 6.6%;
  --line-color: #6d431d;
  box-shadow: 0 18px 45px rgb(15 23 42 / 18%);
}

.gomoku-board::before {
  content: "";
  position: absolute;
  inset: var(--board-pad);
  background-image:
    linear-gradient(var(--line-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--line-color) 1px, transparent 1px);
  background-size: calc(100% / 14) calc(100% / 14);
  border-right: 1px solid var(--line-color);
  border-bottom: 1px solid var(--line-color);
  pointer-events: none;
}

.cell {
  position: absolute;
  left: var(--left);
  top: var(--top);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--cell-hit);
  height: var(--cell-hit);
  transform: translate(-50%, -50%);
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0;
}

.cell.playable {
  cursor: pointer;
}

.cell.playable:hover::after {
  content: "";
  width: 62%;
  height: 62%;
  border-radius: 999px;
  background: rgb(15 118 110 / 28%);
}

/* Anti-misclick: pending confirm frame */
.cell.pending-confirm::after {
  content: "";
  position: absolute;
  inset: -2px;
  border: 3px solid #dc2626;
  border-radius: 999px;
  width: auto;
  height: auto;
  background: none;
  z-index: 2;
  pointer-events: none;
}

.cell.pending-confirm.playable:hover::after {
  background: none;
  width: auto;
  height: auto;
}

.stone {
  width: 78%;
  height: 78%;
  border-radius: 999px;
  box-shadow: inset -3px -4px 8px rgb(0 0 0 / 25%), 0 2px 5px rgb(0 0 0 / 24%);
}

.stone.black {
  background: radial-gradient(circle at 35% 30%, #5b6470, #101318 62%, #050507);
}

.stone.white {
  background: radial-gradient(circle at 35% 30%, #fff, #e7e5df 60%, #c8c3b8);
  border: 1px solid rgb(71 85 105 / 28%);
}

.move-number {
  position: absolute;
  font-size: clamp(8px, 1.3vw, 12px);
  font-weight: 700;
  color: white;
  text-shadow: 0 1px 2px rgb(0 0 0 / 45%);
}

.stone.white + .move-number {
  color: #111827;
  text-shadow: none;
}

.player-pill {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 0.55rem;
  border-left-width: 4px;
  border-radius: 6px;
  background: #f8fafc;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.player-pill.active {
  background: #ccfbf1;
  color: #115e59;
}

.stone-mini {
  display: inline-block;
  height: 16px;
  width: 16px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid rgb(71 85 105 / 24%);
}

.timeline {
  accent-color: #0f766e;
}

.timeline-marker {
  position: absolute;
  top: 50%;
  width: 3px;
  height: 12px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: #172026;
}

/* Gift button & popup */
.gift-btn {
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}

.gift-btn:hover {
  background: #e2e8f0;
}

.gift-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  z-index: 30;
  min-width: 200px;
}

.gift-popup button {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  font-size: 22px;
  cursor: pointer;
  transition: all 0.12s;
  position: relative;
}

.gift-popup button:hover {
  background: #fef3c7;
  border-color: #f59e0b;
  transform: scale(1.08);
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.pagination button,
.pagination span {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 14px;
  border: 1px solid #e2e8f0;
  background: white;
  cursor: pointer;
  color: #334155;
}

.pagination button:hover:not(:disabled) {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pagination button.active {
  background: #0f766e;
  color: white;
  border-color: #0f766e;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-box {
  width: 100%;
  max-width: 400px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  padding: 24px;
}

.modal-box h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-box label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
  margin-bottom: 4px;
}

.modal-box input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 0.938rem;
  box-sizing: border-box;
}

.modal-box .modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-box .modal-actions button {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-primary {
  background: #172026;
  color: white;
  border: none;
}

.btn-primary:hover {
  background: #334155;
}

.btn-secondary {
  background: white;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.btn-secondary:hover {
  background: #f8fafc;
}

.btn-accent {
  background: #0f766e;
  color: white;
  border: none;
}

.btn-accent:hover {
  background: #0d6b63;
}

.modal-message {
  margin-top: 12px;
  min-height: 20px;
  font-size: 0.875rem;
}

@media (max-width: 640px) {
  :root {
    --board-size: min(94vw, 520px);
  }

  .gomoku-board {
    border-width: 6px;
  }
}
