/* ============================================================
   Design tokens
   ============================================================ */
:root {
  /* Warm dark palette — deep near-black with subtle brown/blue undertone,
     honey-wood board, muted gold accent for CTAs and title. */
  --bg:            #0f1114;
  --bg-elev:       #16191e;
  --panel:         #1a1d22;
  --panel-hi:      #23272e;
  --panel-hover:   #2a2f37;
  --border:        #2b2f36;
  --border-hi:     #3a3f48;
  --text:          #f3ede0;
  --text-dim:      #b4ad9f;
  --muted:         #7c7568;
  --board:         #e6c087;
  --board-edge:    #b8935e;
  --line:          #2f1c0a;
  --brand:         #f0b840;      /* title gold */
  --accent:        #d4a24c;      /* primary CTA gold */
  --accent-hover:  #e8b45a;
  --accent-ink:    #1a1200;
  --danger:        #e88484;
  --danger-hi:     #f19c9c;
  --ok:            #7cd88f;
  --ok-hi:         #9be6ab;

  --shadow-sm:     0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md:     0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg:     0 20px 60px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ============================================================
   Buttons + inputs
   ============================================================ */
button {
  font: 500 0.95em/1 'Inter', system-ui, sans-serif;
  background: linear-gradient(180deg, var(--panel-hi) 0%, var(--panel) 100%);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  padding: 0.6em 1em;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--shadow-sm);
}
button:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--panel-hover) 0%, var(--panel-hi) 100%);
  border-color: #4a505a;
}
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger {
  color: var(--danger-hi);
  border-color: #5a2e2e;
  background: linear-gradient(180deg, #2a1c1c 0%, #241717 100%);
}
button.danger:hover:not(:disabled) {
  background: linear-gradient(180deg, #3a2323 0%, #2c1c1c 100%);
  border-color: #7a3838;
}
button.primary {
  background: linear-gradient(180deg, var(--accent-hover) 0%, var(--accent) 100%);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(255,255,255,0.15) inset, 0 4px 14px rgba(212, 162, 76, 0.3);
}
button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #f2c065 0%, #e0ac52 100%);
  border-color: transparent;
  box-shadow: 0 1px 0 rgba(255,255,255,0.2) inset, 0 6px 20px rgba(212, 162, 76, 0.4);
}
input {
  font: 500 15px 'JetBrains Mono', ui-monospace, Menlo, monospace;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  padding: 0.55em 0.75em;
  width: 8em;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  transition: border-color 0.15s ease;
}
input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 162, 76, 0.15);
}
.muted { color: var(--muted); }

/* ============================================================
   Lobby
   ============================================================ */
#lobby {
  max-width: 32em;
  margin: 0 auto;
  padding: 5em 1.5em 1.5em;
  text-align: center;
}
/* back to the jahe.dev index */
.home-link {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  margin-bottom: 1.6em;
  padding: 0.45em 0.9em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.home-link:hover {
  color: var(--brand);
  border-color: var(--border-hi);
  background: var(--panel-hi);
}

#lobby h1 {
  font: 800 4.5rem/1 'Fraunces', 'Playfair Display', Georgia, serif;
  font-variation-settings: 'opsz' 144;
  margin: 0 0 0.3em;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, var(--brand) 0%, #c99b3a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 60px rgba(240, 184, 64, 0.15);
}
#lobby p {
  color: var(--text-dim);
  font-size: 1.05em;
  margin: 0 0 2.5em;
  line-height: 1.6;
}
.size-row {
  display: flex;
  gap: 0.7em;
  justify-content: center;
  margin: 0 0 3em;
}
.size-row button {
  flex: 1;
  padding: 1.1em 0.5em;
  font-size: 1.1em;
  font-weight: 600;
}
.join-row {
  display: flex;
  gap: 0.5em;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}
.join-row label {
  color: var(--muted);
  font-size: 0.95em;
}

/* ============================================================
   Game shell
   ============================================================ */
#game { display: flex; flex-direction: column; height: 100dvh; }
#game header {
  display: flex;
  align-items: center;
  gap: 0.8em;
  padding: 0.75em 1.1em;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
}
#back-btn {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 1.3em;
  line-height: 1;
  padding: 0.2em 0.4em;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
#back-btn:hover { color: var(--text); background: var(--panel-hi); }
.share { display: flex; align-items: center; gap: 0.7em; flex: 1; }
.room-code {
  font: 600 1.05em/1 'JetBrains Mono', ui-monospace, Menlo, monospace;
  letter-spacing: 0.18em;
  color: var(--brand);
}
.conn-status {
  font-size: 0.8em;
  padding: 0.3em 0.7em;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-weight: 500;
}
.conn-status[data-status="connecting"] { color: var(--muted); }
.conn-status[data-status="open"]       { color: var(--ok); border-color: rgba(124, 216, 143, 0.3); }
.conn-status[data-status="closed"]     { color: var(--danger); border-color: rgba(232, 132, 132, 0.3); }

#mute-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 1.15em;
  padding: 0.3em 0.5em;
  border-radius: 6px;
  box-shadow: none;
}
#mute-btn:hover { background: var(--panel-hi); color: var(--text); }

/* ============================================================
   Board area
   ============================================================ */
.play-area {
  flex: 1;
  display: flex;
  min-height: 0;
  min-width: 0;
  background: var(--bg-elev);
}
.board-slot {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6em;
}
#board {
  display: block;
  background: var(--board);
  touch-action: none;
  cursor: pointer;
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.25),
    0 20px 50px rgba(0, 0, 0, 0.35),
    0 8px 20px rgba(0, 0, 0, 0.25);
  transition: filter 0.2s ease, box-shadow 0.2s ease;
}
#board.inactive {
  cursor: not-allowed;
  filter: saturate(0.55) brightness(0.82);
}

/* ============================================================
   Controls sidebar
   ============================================================ */
.controls {
  width: 19em;
  padding: 1.2em 1.1em;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1em;
}
.status-line { display: flex; flex-direction: column; gap: 0.3em; }
.role {
  color: var(--muted);
  font-size: 0.82em;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.turn {
  font-size: 1.25em;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.caps {
  display: flex;
  flex-direction: column;
  gap: 0.4em;
  padding: 0.7em 0.8em;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.cap {
  display: flex;
  align-items: center;
  gap: 0.55em;
  font-size: 0.92em;
  color: var(--text-dim);
}
.cap b { color: var(--text); font-weight: 600; }
.cap .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid var(--border-hi);
  box-shadow: inset 0 -1px 2px rgba(0, 0, 0, 0.3);
}
.cap-black .dot { background: radial-gradient(circle at 30% 30%, #444, #0a0a0a); }
.cap-white .dot { background: radial-gradient(circle at 30% 30%, #fff, #cbc3b6); }

.actions { display: flex; flex-direction: column; gap: 0.6em; }
.actions button { width: 100%; padding: 0.75em 1em; }
.hint {
  color: var(--muted);
  margin: 0;
  font-size: 0.88em;
  min-height: 1.4em;
  line-height: 1.4;
}

/* ============================================================
   Error toast
   ============================================================ */
#toast {
  position: fixed;
  top: 5em;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(30em, calc(100% - 2em));
  padding: 0.85em 1.3em;
  background: linear-gradient(180deg, #3a2020, #2c1919);
  color: #ffdede;
  border: 1px solid #6a3030;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 0.95em;
  line-height: 1.4;
  font-weight: 500;
  animation: toastIn 0.28s cubic-bezier(0.4, 1.6, 0.6, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -14px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}
@keyframes toastOut { to { opacity: 0; transform: translate(-50%, -14px); } }
#toast.out { animation: toastOut 0.25s ease forwards; }

/* ============================================================
   Waiting-for-opponent banner
   ============================================================ */
.banner {
  display: flex;
  align-items: center;
  gap: 0.9em;
  padding: 0.85em 1.1em;
  background: linear-gradient(90deg, #2a3a5f, #3a4b7a);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
  animation: slideDown 0.35s ease;
}
.banner-text { flex: 1; }
.pulse-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #a3c3ff;
  box-shadow: 0 0 0 0 rgba(163, 195, 255, 0.7);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(163, 195, 255, 0.7); }
  70%  { box-shadow: 0 0 0 14px rgba(163, 195, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(163, 195, 255, 0); }
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}

/* ============================================================
   Game-end modal
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1em;
  animation: fadeIn 0.25s ease;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.modal-card {
  background: linear-gradient(180deg, var(--panel-hi) 0%, var(--panel) 100%);
  border: 1px solid var(--border-hi);
  border-radius: 18px;
  padding: 2.2em 2em 1.7em;
  max-width: 24em;
  width: 100%;
  text-align: center;
  animation: popIn 0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.modal-emoji {
  font-size: 3.5em;
  line-height: 1;
  margin-bottom: 0.15em;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.3));
}
.modal-card h2 {
  font: 800 2.1em/1.1 'Fraunces', 'Playfair Display', Georgia, serif;
  font-variation-settings: 'opsz' 144;
  margin: 0 0 0.5em;
  letter-spacing: -0.02em;
}
.modal-card.win h2  { color: var(--ok-hi); text-shadow: 0 0 30px rgba(124, 216, 143, 0.3); }
.modal-card.lose h2 { color: var(--danger-hi); text-shadow: 0 0 30px rgba(232, 132, 132, 0.3); }
.modal-card.neutral h2 { color: var(--text); }
.modal-card p {
  color: var(--text-dim);
  margin: 0 0 1.7em;
  font-size: 1em;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  gap: 0.6em;
  justify-content: center;
  flex-wrap: wrap;
}
.modal-actions button { min-width: 8.5em; padding: 0.75em 1.2em; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn {
  from { opacity: 0; transform: translateY(28px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 720px) {
  #lobby { padding: 3em 1.2em 1.5em; }
  #lobby h1 { font-size: 3.2rem; }

  #game header {
    padding: 0.55em 0.75em;
    gap: 0.5em;
    flex-wrap: nowrap;
  }
  #back-btn { font-size: 1.2em; padding: 0.15em 0.35em; }
  .share { gap: 0.5em; }
  .room-code { font-size: 0.95em; letter-spacing: 0.15em; }
  #copy-btn { padding: 0.45em 0.75em; white-space: nowrap; font-size: 0.88em; }
  #mute-btn { font-size: 1.1em; padding: 0.2em 0.35em; }
  .conn-status {
    padding: 0; width: 10px; height: 10px; border-radius: 50%;
    background: var(--muted);
    font-size: 0;
    color: transparent;
    flex: 0 0 10px;
    border: none;
  }
  .conn-status[data-status="open"]   { background: var(--ok); }
  .conn-status[data-status="closed"] { background: var(--danger); }

  .banner { padding: 0.65em 0.85em; font-size: 0.9em; gap: 0.6em; }
  .banner-text { font-size: 0.9em; }

  .play-area {
    flex-direction: column;
    justify-content: flex-start;
  }
  .board-slot {
    flex: 0 0 auto;
    padding: 0;
    width: 100%;
    aspect-ratio: 1 / 1;
  }
  #board { border-radius: 0; box-shadow: none; }
  .controls {
    width: auto;
    flex: 0 0 auto;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 0.9em 1em;
    gap: 0.7em;
  }
  .actions { flex-direction: row; }
  .actions button { flex: 1; }
  .caps { flex-direction: row; justify-content: space-between; padding: 0.55em 0.8em; }

  .modal-card { padding: 1.8em 1.5em 1.4em; border-radius: 16px; }
  .modal-card h2 { font-size: 1.8em; }
  .modal-emoji { font-size: 3em; }
}
