:root {
  --bg: #0e1116;
  --panel: #161c24;
  --panel-2: #1c2430;
  --line: #2a3544;
  --text: #e9eef5;
  --muted: #8c9aad;
  --accent: #7fa650;
  --accent-soft: #2b3a24;
  --gold: #e0a34a;
  --danger: #d26464;
  --info: #5b9bd5;
  --light-sq: #e9edcc;
  --dark-sq: #6f9654;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1100px 500px at 15% -10%, #1b2634 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #17211a 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

a { color: var(--info); }

#topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(14, 17, 22, 0.86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  color: var(--text);
  text-decoration: none;
  font-size: 1.05rem;
}
.brand:hover { color: var(--accent); }

#topbar .conn {
  font-size: 0.8rem;
  color: var(--muted);
  flex: 1;
}
#topbar .conn.bad { color: var(--danger); }

#view {
  max-width: 1500px;
  margin: 0 auto;
  padding: 18px 16px 60px;
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.05s ease;
  white-space: nowrap;
}
.btn:hover { background: #24303e; border-color: #3a4a5e; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #10160c; }
.btn.primary:hover { background: #8cb75c; }
.btn.danger { border-color: #5a3030; color: #f0b4b4; }
.btn.danger:hover { background: #3a2020; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn.tiny { padding: 3px 8px; font-size: 0.74rem; border-radius: 7px; }

input, select {
  background: #0f141b;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 0.92rem;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus { outline: 2px solid #33465c; outline-offset: 0; border-color: #3d5470; }
label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 10px; }
label input, label select { margin-top: 5px; }

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

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.panel h2, .panel h3 { margin: 0 0 12px; font-size: 1rem; letter-spacing: 0.2px; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

.landing { max-width: 860px; margin: 4vh auto 0; }
.hero { text-align: center; margin-bottom: 26px; }
.hero h1 { font-size: 2.4rem; margin: 0 0 8px; letter-spacing: -0.5px; }
.hero p { color: var(--muted); margin: 0; font-size: 1.02rem; }
.landing-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 720px) { .landing-grid { grid-template-columns: 1fr; } }
.features { margin-top: 16px; }
.features ul { margin: 0; padding-left: 18px; color: var(--muted); line-height: 1.75; font-size: 0.9rem; }

.dash {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1040px) { .dash { grid-template-columns: 1fr; } }

.main-col { min-width: 0; }

.add-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 200px;
  border-style: dashed;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  font-family: inherit;
}
.add-tile:hover { border-color: #3d5470; color: var(--text); }

.room-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 14px;
}
.room-head .meta { color: var(--muted); font-size: 0.85rem; }
.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 6px 5px 14px;
  font-size: 0.85rem;
}
.code-chip b { letter-spacing: 2px; color: var(--gold); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.side { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 60px; }
@media (max-width: 1040px) { .side { position: static; } }

/* ------------------------------------------------------------------ board */

.board-wrap { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  container-type: inline-size;
  user-select: none;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}

.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
}
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq.last { box-shadow: inset 0 0 0 100px rgba(255, 213, 79, 0.32); }
.sq.sel { box-shadow: inset 0 0 0 100px rgba(255, 213, 79, 0.55); }
.sq.check { background: radial-gradient(circle, rgba(255,60,60,0.85), rgba(200,20,20,0.45) 70%, transparent 72%); }

.sq .cf, .sq .cr {
  position: absolute;
  font-size: 2.5cqw;
  font-weight: 700;
  pointer-events: none;
  line-height: 1;
}
.sq.dark .cf, .sq.dark .cr { color: rgba(236, 243, 226, 0.72); }
.sq.light .cf, .sq.light .cr { color: rgba(74, 97, 51, 0.75); }
.sq .cf { right: 5%; bottom: 3%; }
.sq .cr { left: 5%; top: 3%; }

.pc {
  font-size: 10.3cqw;
  line-height: 1;
  position: relative;
  z-index: 2;
  cursor: default;
}
.pc.w { color: #fdfdfd; text-shadow: 0 0.06cqw 0.2cqw rgba(0,0,0,0.55); -webkit-text-stroke: 0.12cqw #3a3a3a; }
.pc.b { color: #22262b; text-shadow: 0 0.06cqw 0.2cqw rgba(255,255,255,0.18); -webkit-text-stroke: 0.1cqw #0a0c0f; }
.board.live .pc { cursor: grab; }
.board.live .pc:active { cursor: grabbing; }

.sq.move::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(20, 30, 15, 0.32);
}
.sq.cap::after {
  content: "";
  position: absolute;
  inset: 7%;
  border-radius: 50%;
  border: 0.7cqw solid rgba(20, 30, 15, 0.4);
}

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  background: rgba(10, 14, 19, 0.74);
  backdrop-filter: blur(2px);
  z-index: 5;
}
.board-overlay .ov-title { font-weight: 800; font-size: 1.05rem; }
.board-overlay .ov-sub { color: var(--muted); font-size: 0.82rem; }
.board-overlay .ov-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ------------------------------------------------------------------ cards */

.boards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card.turn-me { border-color: #4d6b33; box-shadow: 0 0 0 1px rgba(127, 166, 80, 0.35); }
.card-head { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; }
.card-head .board-no { font-weight: 700; color: var(--muted); }
.card-head .player { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4a5a6e; margin-right: 5px; vertical-align: 1px; }
.dot.on { background: #64b45f; box-shadow: 0 0 6px rgba(100, 180, 95, 0.8); }
.dot.wait { background: var(--gold); }

.chip {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: #23303d;
  color: var(--muted);
  white-space: nowrap;
}
.chip.open { background: #2a3441; color: #a9b7c8; }
.chip.ready { background: #3a3320; color: var(--gold); }
.chip.live { background: var(--accent-soft); color: #a8d47c; }
.chip.over { background: #2c2c33; color: #c9c9d4; }
.chip.gone { background: #3a2528; color: #e39a9a; }

.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.clock {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  background: #10161e;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 9px;
  font-size: 0.8rem;
  color: var(--muted);
  overflow: hidden;
}
.clock .cname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clock .ctime { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95rem; color: var(--text); font-variant-numeric: tabular-nums; }
.clock.active { border-color: var(--accent); background: #1a2416; }
.clock.active .ctime { color: #c7e6a4; }
.clock.low .ctime { color: #ff8f8f; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

.card-foot { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ---------------------------------------------------------- player's board */

.own-board { max-width: 660px; }
.own-board .card { padding: 14px; }
.own-board .pc.movable { cursor: grab; }
.board.live .sq { cursor: pointer; }

.section-head { display: flex; align-items: center; gap: 10px; margin: 18px 0 10px; }
.section-head h3 { margin: 0; font-size: 0.95rem; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; }

/* -------------------------------------------------------------- move list */

.move-list { max-height: 260px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }
.mv-row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 4px; padding: 2px 4px; border-radius: 6px; }
.mv-row:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.mv-no { color: var(--muted); }

/* ------------------------------------------------------------------- chat */

.panel.chat { display: flex; flex-direction: column; min-height: 320px; }
.chat-list { flex: 1; overflow-y: auto; max-height: 340px; display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; font-size: 0.86rem; }
.chat-msg { line-height: 1.4; word-wrap: break-word; }
.chat-msg.sys { color: var(--muted); font-style: italic; font-size: 0.79rem; }
.chat-msg .who { font-weight: 700; color: #a8d47c; margin-right: 5px; }
.chat-msg .who.host { color: var(--gold); }
.chat-msg .who.spectator { color: var(--muted); }
#chat-form { display: flex; gap: 8px; }
#chat-form input { flex: 1; }

.players-list { display: flex; flex-direction: column; gap: 6px; font-size: 0.86rem; }
.players-list .p-row { display: flex; align-items: center; gap: 8px; }
.players-list .p-row .p-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- overlay */

#overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(6, 9, 13, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#overlay.hidden { display: none; }

.focus-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  width: 100%;
  max-width: 960px;
  max-height: 94vh;
  overflow: auto;
  padding: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.focus-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.focus-head h2 { margin: 0; font-size: 1.05rem; }
.focus-body { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; }
.focus-board { max-width: 560px; }
@media (max-width: 820px) { .focus-body { grid-template-columns: 1fr; } }
.focus-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.promo {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  min-width: 280px;
}
.promo h3 { margin: 0 0 12px; }
.promo-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.promo-btn {
  width: 64px;
  height: 64px;
  font-size: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f0f3f7;
  border: 2px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
}
.promo-btn:hover { border-color: var(--accent); }
.promo-btn .pc { font-size: 44px; }

.join-panel { max-width: 460px; margin: 7vh auto 0; }
.join-panel h1 { font-size: 1.4rem; margin: 0 0 6px; }
.join-panel .code { color: var(--gold); letter-spacing: 2px; font-family: ui-monospace, monospace; }
.join-actions { display: flex; gap: 10px; margin-top: 12px; }

/* ----------------------------------------------------------------- toasts */

#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--info);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.88rem;
  max-width: 340px;
  animation: slide-in 0.18s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--accent); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } }

.spinner { text-align: center; color: var(--muted); padding: 15vh 0; font-size: 1rem; }

.banner {
  background: #3a2528;
  border: 1px solid #5a3030;
  color: #f0b4b4;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .boards-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.9rem; }
  .card-foot .btn { flex: 1 1 auto; }
}
