:root {
  --red: #E0453A; --green: #1FA35B; --yellow: #F2B01E; --blue: #3D8BFF;
  --accent: #FFD23F; --accent-ink: #0B1733;
  --navy: #0C1D45; --navy-deep: #081533; --cell: #1B3572; --cell-line: #0C1D45;
  --bg: #EEF2FA; --surface: #FFFFFF; --surface-2: #F5F7FC; --ink: #0B1733; --muted: #52607F; --line: #D5DCEC;
  --danger: #D8342B;
  --radius-lg: 18px; --radius: 12px; --radius-sm: 8px;
  --head: 'Barlow Condensed', 'Arial Narrow', 'Roboto Condensed', system-ui, sans-serif;
  --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #061029; --surface: #0D1C42; --surface-2: #122554; --ink: #EDF1FF; --muted: #9CAAD0; --line: #213A74;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #061029; --surface: #0D1C42; --surface-2: #122554; --ink: #EDF1FF; --muted: #9CAAD0; --line: #213A74;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 16px; line-height: 1.45;
  min-height: 100svh; padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; font-size: 0.92rem; }
.center { text-align: center; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 14px 8px; background: var(--navy); color: #fff;
}
.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; line-height: 1; }
.brand-hub { font-size: 0.72rem; color: #AFC0EA; letter-spacing: 0.02em; }
.brand-game { font-family: var(--head); font-weight: 800; font-size: 1.6rem; color: var(--accent); }
.topbar-mid { flex: 1; text-align: center; font-size: 0.85rem; color: #C9D5F5; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid #28468C; background: #132A5E; color: #fff;
  cursor: pointer; font-size: 1.05rem; display: grid; place-items: center;
}
.icon-btn:hover { background: #1B3775; }

main { max-width: 1120px; margin: 0 auto; padding: 14px 12px 90px; }
.view { display: flex; flex-direction: column; gap: 14px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; }
.h2 { font-family: var(--head); font-weight: 700; font-size: 1.45rem; margin: 0 0 8px; letter-spacing: 0.01em; }
.h2 .count { color: var(--muted); font-weight: 600; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.field input, .field select, .join-row input {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; font-size: 1rem; color: var(--ink); min-height: 48px;
}
.field.small { flex: 1; }
.row { display: flex; gap: 10px; margin: 12px 0; }
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-weight: 600; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.05); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-wide { width: 100%; margin-top: 14px; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.2em; font-weight: 700; min-width: 0; }

/* Hero: the one orchestrated moment */
.hero { padding: 18px 4px 4px; }
.hero-bars { display: flex; gap: 6px; margin-bottom: 10px; }
.hero-bars span { height: 10px; flex: 1; border-radius: 5px; transform-origin: left; animation: bar-in 700ms cubic-bezier(.2,.8,.2,1) both; }
.hero-bars span:nth-child(1) { background: var(--red); }
.hero-bars span:nth-child(2) { background: var(--green); animation-delay: 90ms; }
.hero-bars span:nth-child(3) { background: var(--yellow); animation-delay: 180ms; }
.hero-bars span:nth-child(4) { background: var(--blue); animation-delay: 270ms; }
@keyframes bar-in { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.hero-title { font-family: var(--head); font-weight: 800; font-size: clamp(4.2rem, 18vw, 7.5rem); line-height: 0.85; margin: 0; letter-spacing: -0.01em; }
.hero-sub { max-width: 34ch; margin: 10px 0 0; color: var(--muted); font-size: 1.02rem; }

.swatches { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; padding: 0; }
.swatch[aria-checked="true"] { border-color: var(--ink); box-shadow: 0 0 0 2px var(--surface) inset; }

.solo { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }

.rules summary { cursor: pointer; font-weight: 600; min-height: 32px; }
.rules ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }
.rules li { margin: 4px 0; }

.house-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 10px; }
.house {
  position: relative; border-radius: var(--radius); padding: 12px; min-height: 76px; text-align: left; cursor: pointer;
  border: 2px solid transparent; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px;
}
.house::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 8px; border-radius: var(--radius) 0 0 var(--radius); background: var(--hc); }
.house .h-label { font-family: var(--head); font-weight: 800; font-size: 1.35rem; color: var(--hc); padding-left: 6px; letter-spacing: 0.03em; }
.house .h-owner { font-size: 0.86rem; color: var(--muted); padding-left: 6px; }
.house.mine { border-color: var(--hc); }
.house.taken { cursor: default; }
.house select { margin: 4px 0 0 6px; font-size: 0.8rem; padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); max-width: 92%; }

.room-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.room-code { font-family: var(--head); font-weight: 800; font-size: 3rem; letter-spacing: 0.14em; margin: 0; line-height: 1; }
.room-share { display: flex; gap: 8px; flex-wrap: wrap; }
.lobby-grid { display: grid; gap: 14px; }
@media (min-width: 900px) { .lobby-grid { grid-template-columns: 1fr 1fr; } }

.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); background: var(--surface-2); min-height: 48px; }
.p-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.p-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 0.75rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); }
.tag-host { background: var(--accent); color: var(--accent-ink); }
.tag-off { background: transparent; border: 1px dashed var(--muted); color: var(--muted); }
.kick { border: none; background: transparent; color: var(--danger); font-size: 1.1rem; cursor: pointer; width: 40px; height: 40px; border-radius: 50%; }
.kick:hover { background: rgba(216, 52, 43, 0.12); }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: none; }
.setting .s-text { display: flex; flex-direction: column; }
.setting .s-text small { color: var(--muted); }
.setting select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 40px; }
.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: background 150ms; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform 150ms; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(22px); }
.switch input:disabled + span { opacity: 0.5; }

.chat-log { max-height: 240px; min-height: 90px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px 2px 8px; font-size: 0.94rem; }
.chat-log .msg b { font-weight: 700; }
.chat-log .sys { color: var(--muted); font-size: 0.85rem; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; min-height: 46px; }

.game-layout { display: grid; gap: 12px; }
@media (min-width: 900px) {
  .game-layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  .chat-fab { display: none; }
}
.board-col { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.turn-banner {
  width: 100%; max-width: 640px; display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); min-height: 50px;
}
.turn-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--muted); flex: none; }
.turn-text { font-family: var(--head); font-weight: 700; font-size: 1.3rem; line-height: 1.1; }
.turn-banner.mine { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.timer-track { width: 100%; max-width: 640px; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.timer-bar { height: 100%; width: 0; background: var(--accent); }
.timer-bar.low { background: var(--danger); }

.board-wrap { position: relative; width: min(100%, 640px, calc(100svh - 290px)); min-width: min(100%, 300px); aspect-ratio: 1; }
.board { width: 100%; height: 100%; display: block; touch-action: manipulation; user-select: none; }
.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.float-emoji { position: absolute; font-size: 2.2rem; transform: translate(-50%, -50%); animation: float-up 1.8s ease-out forwards; text-shadow: 0 2px 6px rgba(0,0,0,.4); }
.float-emoji small { display: block; font-size: 0.7rem; text-align: center; color: #fff; font-family: var(--body); font-weight: 700; }
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }
.toast-board {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  background: rgba(8, 21, 51, 0.92); color: #fff; font-family: var(--head); font-weight: 700; font-size: 1.5rem;
  padding: 10px 18px; border-radius: 12px; opacity: 0; transition: opacity 200ms; white-space: nowrap; border: 2px solid var(--accent);
}
.toast-board.show { opacity: 1; }

.control-bar { width: 100%; max-width: 640px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.dice { display: flex; gap: 10px; }
.die {
  width: 58px; height: 58px; border-radius: 12px; background: #FFFDF5; border: 2px solid #D9D2BC; position: relative;
  box-shadow: 0 3px 0 #C8BFA5; transition: opacity 150ms;
}
.die.used { opacity: 0.35; }
.die.idle { opacity: 0.55; }
.die i { position: absolute; width: 11px; height: 11px; border-radius: 50%; background: #0B1733; transform: translate(-50%, -50%); }
.die.six i { background: #C0271E; }
.die.rolling { animation: shake 90ms linear infinite; }
@keyframes shake { 0% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } 100% { transform: rotate(-8deg); } }
.btn-roll { flex: 1; max-width: 220px; min-height: 58px; font-family: var(--head); font-size: 1.6rem; font-weight: 800; letter-spacing: 0.04em; }
.btn-roll.pulse:not(:disabled) { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 63, .7); } 50% { box-shadow: 0 0 0 10px rgba(255, 210, 63, 0); } }

.side-col { display: flex; flex-direction: column; gap: 10px; }
.seat-strip { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 900px) { .seat-strip { grid-template-columns: 1fr; } }
.seat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px 8px 16px; position: relative; min-height: 56px; }
.seat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 7px; background: var(--hc); border-radius: var(--radius) 0 0 var(--radius); }
.seat.active { border-color: var(--hc); box-shadow: 0 0 0 2px var(--hc) inset; }
.seat .s-top { display: flex; align-items: baseline; gap: 6px; }
.seat .s-house { font-family: var(--head); font-weight: 800; font-size: 1.15rem; color: var(--hc); letter-spacing: 0.03em; }
.seat .s-status { font-size: 0.75rem; color: var(--muted); }
.seat .s-name { font-size: 0.88rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .s-home { display: flex; gap: 3px; margin-top: 4px; }
.seat .s-home i { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--hc); }
.seat .s-home i.done { background: var(--hc); }

.reactions { display: grid; grid-template-columns: repeat(8, minmax(0, 46px)); gap: 4px; justify-content: center; }
.reactions button { width: 100%; aspect-ratio: 1; max-width: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 1.3rem; cursor: pointer; padding: 0; }
.reactions button:active { transform: scale(.92); }

@media (max-width: 899px) {
  .game-chat {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; border-radius: 18px 18px 0 0;
    transform: translateY(105%); transition: transform 220ms ease; box-shadow: 0 -8px 30px rgba(0,0,0,.3);
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .game-chat.open { transform: translateY(0); }
}
.chat-fab {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 25; width: 56px; height: 56px; border-radius: 50%;
  background: var(--navy); border: 2px solid var(--accent); color: #fff; font-size: 1.4rem; cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.badge { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; font-size: 0.72rem; font-weight: 700; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 5px; }

/* Board SVG */
.b-frame { fill: var(--navy); }
.b-cell { fill: var(--cell); stroke: var(--cell-line); stroke-width: 0.02; }
.b-start { stroke: rgba(255,255,255,.5); stroke-width: 0.04; }
.b-star { fill: rgba(255, 255, 255, 0.28); }
.b-star-start { fill: rgba(255, 255, 255, 0.55); }
.b-homecell { stroke: rgba(0,0,0,.25); stroke-width: 0.03; }
.b-arrow { fill: none; stroke-width: 0.09; stroke-linecap: round; stroke-linejoin: round; }
.b-tri { stroke: var(--navy); stroke-width: 0.05; }
.b-emblem-ring { stroke: #fff; stroke-width: 0.06; }
.b-panel { fill: var(--navy-deep); }
.b-slot { fill: rgba(255,255,255,.06); stroke-width: 0.05; stroke-dasharray: 0.12 0.1; }
.b-label { font-family: var(--head); font-weight: 800; font-size: 0.78px; letter-spacing: 0.06px; }

.piece { cursor: default; outline: none; }
.pc-hit { fill: transparent; }
.pc-shadow { fill: rgba(0,0,0,.45); }
.pc-body { stroke: #fff; stroke-width: 0.08; }
.pc-core { fill: rgba(255,255,255,.92); }
.pc-glow { fill: none; stroke-width: 0.08; opacity: 0; }
.piece.movable { cursor: pointer; }
.piece.movable .pc-glow { opacity: 1; stroke: var(--accent); animation: glow 1s ease-in-out infinite; }
.piece.movable:focus-visible .pc-glow { stroke: #fff; }
@keyframes glow { 0%, 100% { stroke-opacity: 1; stroke-width: 0.08; } 50% { stroke-opacity: 0.35; stroke-width: 0.16; } }

.target { cursor: pointer; outline: none; }
.tg-hit { fill: transparent; }
.tg-ring { fill: rgba(255, 210, 63, 0.9); stroke: #fff; stroke-width: 0.06; }
.tg-num { font-family: var(--head); font-weight: 800; font-size: 0.5px; fill: #0B1733; }
.target:focus-visible .tg-ring { stroke: #0B1733; stroke-width: 0.1; }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(4, 10, 28, .72); display: grid; place-items: center; padding: 16px; }
.overlay-card { background: var(--surface); border-radius: var(--radius-lg); padding: 22px; width: min(440px, 100%); border-top: 8px solid var(--accent); }
.over-title { font-family: var(--head); font-weight: 800; font-size: 2.4rem; margin: 0 0 12px; line-height: 1; }
.rankings { margin: 0; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.rankings li { font-weight: 600; }
.rankings li span { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 20px); z-index: 60;
  background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: opacity 200ms, transform 200ms; max-width: 90vw; text-align: center; border: 1px solid #28468C;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (max-width: 380px) {
  .die { width: 50px; height: 50px; }
  .room-code { font-size: 2.4rem; }
}
