/* Shared components (plain CSS so it works alongside the Tailwind browser build). */
:root {
  --accent: #fbbf24;
  --panel: #111827;
  --panel-border: #1f2937;
  --muted: #94a3b8;
}

* { -webkit-tap-highlight-color: transparent; }

/* Toggled from JS; Tailwind's .hidden is layered and loses to the unlayered component styles below. */
.is-hidden { display: none !important; }

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  padding: 1.25rem;
}

.label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.input {
  width: 100%;
  border-radius: 0.6rem;
  border: 1px solid #334155;
  background: #0b1220;
  padding: 0.6rem 0.8rem;
  color: #f1f5f9;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(251 191 36 / 0.2); }

.btn-primary, .btn-secondary, .btn, .btn-danger, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 0.6rem;
  padding: 0.6rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #111827; }
.btn-primary:hover { background: #f59e0b; }
.btn-secondary { background: #1e293b; color: #f1f5f9; border-color: #334155; }
.btn-secondary:hover { background: #273449; }
.btn { background: #1e293b; color: #e2e8f0; border-color: #334155; padding: 0.5rem 0.8rem; }
.btn:hover { background: #273449; }
.btn-danger { background: #7f1d1d; color: #fecaca; padding: 0.5rem 0.8rem; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost { background: transparent; color: #cbd5e1; padding: 0.35rem 0.6rem; }
.btn-ghost:hover { background: #1e293b; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.segmented { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.segmented label { flex: 1 1 0; min-width: 6rem; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  text-align: center;
  padding: 0.55rem 0.5rem;
  border-radius: 0.6rem;
  border: 1px solid #334155;
  background: #0b1220;
  cursor: pointer;
  font-size: 0.9rem;
}
.segmented input:checked + span { border-color: var(--accent); background: rgb(251 191 36 / 0.12); color: var(--accent); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px rgb(251 191 36 / 0.3); }

/* ---- Room layout ------------------------------------------------------- */

.room-grid {
  --board-max: 720px;
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "board" "tabs" "panel";
}
.area-board { grid-area: board; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; min-width: 0; }
.area-board > * { width: 100%; max-width: var(--board-max); }
.tabs { grid-area: tabs; display: flex; gap: 0.25rem; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 0.8rem; padding: 0.25rem; }
.tabs button { flex: 1; padding: 0.5rem; border-radius: 0.6rem; font-weight: 600; font-size: 0.9rem; color: var(--muted); position: relative; }
.tabs button.active { background: #1e293b; color: #f8fafc; }
.tabs .badge { position: absolute; top: 0.25rem; right: 0.5rem; min-width: 1.1rem; height: 1.1rem; border-radius: 999px; background: #ef4444; color: white; font-size: 0.7rem; line-height: 1.1rem; display: none; }
.tabs .badge.show { display: inline-block; }

.panel {
  grid-area: panel;
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 1rem;
  padding: 0.9rem;
  height: 55vh;
  height: 55dvh;
}
.panel.active { display: flex; }
.panel h3 { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.5rem; }
.scroll { overflow-y: auto; min-height: 0; flex: 1; overscroll-behavior: contain; }

.board-wrap {
  aspect-ratio: 1 / 1;
  position: relative;
  flex-shrink: 0;
}
#board { width: 100%; height: 100%; }

@media (min-width: 768px) {
  .room-grid {
    --board-max: max(300px, calc(100dvh - 18rem));
    grid-template-columns: minmax(0, 1fr) 330px;
    grid-template-areas: "board tabs" "board panel";
    grid-template-rows: auto 1fr;
    height: calc(100dvh - 4.5rem);
  }
  .area-board { overflow-y: auto; }
  .panel { height: auto; }
}

@media (min-width: 1280px) {
  .room-grid {
    grid-template-columns: 280px minmax(0, 1fr) 340px;
    grid-template-areas: "people board chat" "moves board chat";
    grid-template-rows: auto 1fr;
  }
  .tabs { display: none; }
  .panel { display: flex; }
  .area-people { grid-area: people; max-height: 45dvh; }
  .area-moves { grid-area: moves; }
  .area-chat { grid-area: chat; }
}

/* ---- Player bars and clocks -------------------------------------------- */

.player-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.35rem 0.1rem;
}
.player-bar .who { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.player-bar .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 0.55rem; height: 0.55rem; border-radius: 999px; background: #475569; flex-shrink: 0; }
.dot.on { background: #22c55e; }
.clock {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.35rem;
  font-weight: 700;
  padding: 0.2rem 0.7rem;
  border-radius: 0.5rem;
  background: #1e293b;
  color: #94a3b8;
  min-width: 5.5rem;
  text-align: center;
}
.clock.running { background: #f1f5f9; color: #0f172a; }
.clock.low.running { background: #dc2626; color: #fff; }
.status-line { font-size: 0.95rem; color: #cbd5e1; text-align: center; min-height: 1.4rem; }

.banner {
  width: 100%;
  border-radius: 0.8rem;
  border: 1px solid #334155;
  background: #0f1a2e;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.banner .grow { flex: 1 1 12rem; }

.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.4rem; width: 100%; }

/* ---- Moves, people, chat ---------------------------------------------- */

.moves { display: grid; grid-template-columns: 2.5rem 1fr 1fr; font-family: ui-monospace, Menlo, monospace; font-size: 0.9rem; row-gap: 0.1rem; }
.moves .num { color: #64748b; }
.moves .mv { padding: 0.1rem 0.4rem; border-radius: 0.3rem; }
.moves .mv.last { background: rgb(251 191 36 / 0.18); color: var(--accent); }

.person { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid #1e293b; }
.person:last-child { border-bottom: none; }
.tag { font-size: 0.7rem; padding: 0.05rem 0.4rem; border-radius: 0.3rem; background: #1e293b; color: #cbd5e1; text-transform: uppercase; letter-spacing: 0.04em; }
.tag.white { background: #f1f5f9; color: #0f172a; }
.tag.black { background: #020617; color: #f1f5f9; border: 1px solid #475569; }
.tag.you { background: rgb(251 191 36 / 0.2); color: var(--accent); }

.chat-msg { padding: 0.25rem 0; font-size: 0.9rem; word-wrap: break-word; overflow-wrap: anywhere; }
.chat-msg .author { font-weight: 600; margin-right: 0.35rem; }
.chat-msg .author.player { color: var(--accent); }
.chat-msg .time { color: #64748b; font-size: 0.7rem; margin-left: 0.3rem; }
.chat-msg.system { color: #94a3b8; font-style: italic; font-size: 0.85rem; }

/* ---- Overlays ---------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgb(2 6 23 / 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}
.promo {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(2 6 23 / 0.55);
}
.promo .choices { display: flex; gap: 0.5rem; background: #0f172a; padding: 0.6rem; border-radius: 0.8rem; border: 1px solid #334155; }
.promo button { width: 4rem; height: 4rem; font-size: 2.8rem; line-height: 1; border-radius: 0.6rem; background: #e2e8f0; color: #0f172a; }
.promo button:hover { background: var(--accent); }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.4rem; width: min(92vw, 26rem); pointer-events: none; }
.toast { background: #1e293b; border: 1px solid #334155; color: #f1f5f9; padding: 0.6rem 0.9rem; border-radius: 0.6rem; font-size: 0.9rem; box-shadow: 0 10px 25px rgb(0 0 0 / 0.4); animation: toast-in 0.2s ease-out; }
.toast.error { border-color: #b91c1c; background: #450a0a; color: #fecaca; }
.toast.success { border-color: #15803d; background: #052e16; color: #bbf7d0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
