:root {
  color-scheme: dark;
  font-family: 'DM Sans', Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #edf0e8;
  background: #101815;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --bg: #101815;
  --surface: #19221e;
  --surface-raised: #202c26;
  --border: #304039;
  --muted: #9aa79e;
  --muted-soft: #748279;
  --accent: #c7f36b;
  --light-square: #d7d8bf;
  --dark-square: #687b69;
  --red: #e65350;
  --amber: #efaa45;
  --purple: #a879e8;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: radial-gradient(ellipse at 15% 0%, #213228 0, transparent 34rem), var(--bg); }
button, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.app-shell { width: min(1380px, calc(100% - 64px)); margin: 0 auto; }
.topbar { height: 76px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(157, 176, 162, .15); }
.brand { display: inline-flex; gap: 10px; align-items: center; color: #f3f4ed; text-decoration: none; font-weight: 700; letter-spacing: -.035em; font-size: 18px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #4a5c4d; border-radius: 11px; color: var(--accent); font-size: 22px; }
.brand-light { color: #9da99f; font-weight: 500; }
.connection { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.connection-dot { width: 7px; height: 7px; border-radius: 50%; background: #e4a957; box-shadow: 0 0 0 4px #e4a9571c; }
.connection.online .connection-dot { background: var(--accent); box-shadow: 0 0 0 4px #c7f36b1b; }
.connection.offline .connection-dot { background: #e35e56; box-shadow: 0 0 0 4px #e35e561b; }

.page-heading { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); align-items: end; gap: 32px; padding: 46px 0 30px; }
.eyebrow { margin: 0 0 9px; color: var(--accent); font: 500 10px/1.2 'DM Mono', monospace; letter-spacing: .12em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 13px; font: 500 clamp(40px, 5vw, 65px)/.99 'Playfair Display', Georgia, serif; letter-spacing: -.04em; }
h1 span { color: #aab8a8; }
.intro { margin: 0; max-width: 480px; color: #aab5ab; font-size: 14px; line-height: 1.6; }
.room-card { padding: 20px 21px 18px; border: 1px solid #38473f; border-radius: 15px; background: linear-gradient(140deg, #202c26, #18211d); box-shadow: 0 15px 42px #00000020; }
.room-card h2, .panel-heading h2, .legend-card h2 { margin: 0 0 5px; font: 600 17px/1.25 'DM Sans', sans-serif; letter-spacing: -.02em; }
.room-card p { margin: 0 0 16px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.button { display: inline-flex; justify-content: center; align-items: center; gap: 10px; border: 1px solid transparent; border-radius: 8px; padding: 10px 14px; cursor: pointer; font-size: 12px; font-weight: 700; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .48; cursor: not-allowed; }
.button-primary { color: #1c271d; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: #d6ff85; }
.button-secondary { color: #e7ece3; background: #2d3c33; border-color: #405248; }
.button-secondary:hover:not(:disabled), .button-quiet:hover:not(:disabled) { background: #33463a; }
.rejoin-button { margin-top: 8px; }
.button-quiet { color: #b5c0b5; background: transparent; border-color: #405047; }
.button-danger { color: #f3a09a; background: #422b29; border-color: #67413c; }
.button-danger:hover:not(:disabled) { background: #583431; }
.full-width { width: 100%; }
.divider { display: flex; align-items: center; gap: 10px; margin: 15px 0 12px; color: var(--muted-soft); font-size: 10px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: #34423a; }
label { display: block; color: #b9c3b7; font-size: 10px; font-weight: 600; }
.join-row { display: flex; gap: 8px; margin-top: 7px; }
input, select { min-width: 0; height: 38px; padding: 0 11px; color: #edf0e8; background: #111a16; border: 1px solid #3a4b41; border-radius: 7px; }
input { flex: 1; font-size: 12px; }
input::placeholder { color: #748178; }
.room-title-row { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.room-title-row h2 { margin-bottom: 0; }
.seat-pill { margin-top: 4px; padding: 5px 8px; color: #c8d1c6; background: #2e3c33; border: 1px solid #425349; border-radius: 20px; font: 10px 'DM Mono', monospace; white-space: nowrap; }
.room-message { padding: 9px 10px; background: #152019; border-radius: 7px; }
.invite-share { margin: 12px 0; }
.invite-share input { font-size: 10px; }
.room-actions { display: flex; gap: 8px; margin-top: 12px; }
.room-actions .button { flex: 1; }
.guest-lobby { margin-top: 18px; padding-top: 16px; border-top: 1px solid #34423a; }
.guest-lobby h2 { margin: 0 0 5px; font: 600 16px/1.25 'DM Sans', sans-serif; letter-spacing: -.02em; }
.guest-lobby-copy { margin: 0 0 13px !important; }
.lobby-entry .join-row { align-items: stretch; }
.lobby-entry .button { white-space: nowrap; }
.lobby-status { margin: 9px 0 0 !important; color: #b7c7ad !important; font-size: 10px !important; }
.lobby-directory { margin-top: 13px; }
.lobby-directory h3 { margin: 14px 0 7px; color: #9aa79e; font: 500 9px 'DM Mono', monospace; letter-spacing: .1em; text-transform: uppercase; }
.lobby-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.lobby-row-item, .lobby-challenge { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 8px; border: 1px solid #34443a; border-radius: 7px; background: #141d18; }
.lobby-name, .lobby-empty, .lobby-challenge-title { color: #d4ddd2; font-size: 10px; line-height: 1.4; }
.lobby-empty { padding: 4px 2px; color: var(--muted-soft); }
.lobby-action { flex: 0 0 auto; padding: 6px 9px; font-size: 10px; }
.lobby-challenges { display: grid; gap: 6px; }
.lobby-challenge { align-items: start; }
.lobby-challenge-body { min-width: 0; }
.lobby-challenge-title { display: block; margin-bottom: 5px; }
.lobby-challenge-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.lobby-leave { margin-top: 10px; }

.play-area { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(275px, 330px); gap: 44px; align-items: start; padding: 16px 0 44px; }
.board-column { width: 100%; max-width: 690px; justify-self: center; }
.board-toolbar { display: flex; align-items: center; justify-content: space-between; margin: 0 0 12px; }
.turn-status { display: inline-flex; align-items: center; gap: 9px; color: #d2d9d0; font-size: 12px; font-weight: 600; }
.turn-indicator { width: 10px; height: 10px; border-radius: 50%; background: #aeb8a9; border: 1px solid #6a776a; }
.turn-indicator.white { background: #f1f0dc; border-color: #b5b89f; }
.turn-indicator.black { background: #343c35; border-color: #879087; }
.orientation-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 10px; }
.orientation-control select { height: 32px; padding: 0 25px 0 9px; font-size: 10px; }
.board-wrap { display: grid; grid-template-columns: 20px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) 19px; gap: 5px 7px; width: 100%; aspect-ratio: 1 / 1.04; }
.rank-labels { grid-column: 1; grid-row: 1; display: grid; grid-template-rows: repeat(8, 1fr); align-items: center; justify-items: center; color: #819087; font: 10px 'DM Mono', monospace; }
.board { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); overflow: hidden; border: 1px solid #536557; border-radius: 7px; box-shadow: 0 18px 48px #0005; }
.file-labels { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(8, 1fr); align-items: center; justify-items: center; color: #819087; font: 10px 'DM Mono', monospace; }
.square { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; padding: 1px; border: 0; cursor: pointer; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.selected { box-shadow: inset 0 0 0 4px #c7f36b; z-index: 1; }
.square.legal::after { content: ''; position: absolute; width: 20%; height: 20%; border-radius: 50%; background: #12221753; pointer-events: none; }
.square.legal.has-piece::after { width: 76%; height: 76%; border: 5px solid #17271970; background: transparent; }
.square.last-move { background-image: linear-gradient(#f4dc5e45, #f4dc5e45); }
.piece-token { z-index: 2; display: flex; flex-direction: column; justify-content: center; align-items: center; line-height: 1; color: #1c261e; pointer-events: none; filter: drop-shadow(0 1px 1px #0004); }
.piece-token.black-piece { color: #222923; }
.piece-glyph { font-family: 'DejaVu Sans', 'Segoe UI Symbol', serif; font-size: clamp(24px, 4.25vw, 52px); }
.square .piece-token.black-piece .piece-glyph { color: #26302a; text-shadow: 0 1px #aab5a2; }
.square .piece-token.white-piece .piece-glyph { color: #f4f0d9; text-shadow: 0 1px 1px #192119, 0 0 2px #192119; }
.status-chip { display: inline-grid; place-items: center; min-width: 18px; height: 15px; padding: 0 4px; border: 1px solid #ffffff40; border-radius: 10px; color: white; font: 700 8px/1 'DM Mono', monospace; box-shadow: 0 1px 3px #0005; }
.piece-token .status-chip { margin-top: -2px; }
.status-chip.devastated { background: var(--red); }
.status-chip.guilty { background: var(--amber); color: #2b1a07; }
.status-chip.psycho { background: var(--purple); }
.square:focus-visible { outline: 3px solid var(--accent); outline-offset: -4px; z-index: 3; }
.board-caption { min-height: 20px; margin-top: 7px; color: var(--muted-soft); font-size: 10px; line-height: 1.5; text-align: right; }

.game-panel { display: flex; flex-direction: column; gap: 12px; }
.die-card, .legend-card, .activity-card { border: 1px solid #35443c; border-radius: 12px; background: linear-gradient(140deg, #1d2822, #17201b); }
.die-card { padding: 17px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; }
.panel-heading .eyebrow { margin-bottom: 6px; }
.d6-icon { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid #56614e; border-radius: 11px; color: var(--accent); background: #2a382c; font: 500 11px 'DM Mono', monospace; transform: rotate(-4deg); }
.die-result { display: flex; align-items: center; gap: 12px; min-height: 68px; margin: 15px 0 11px; padding: 9px 10px; border: 1px solid #35443a; border-radius: 9px; background: #121a16; }
.die-face { display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; border-radius: 10px; color: #202a1e; background: var(--accent); font: 600 22px 'DM Mono', monospace; box-shadow: inset 0 -3px #6a8943; }
.die-face.empty { color: #92a18f; background: #28352c; box-shadow: none; font-size: 18px; }
.die-copy { color: #bcc6bc; font-size: 11px; line-height: 1.45; }
.die-note { margin: 9px 0 0; color: var(--muted-soft); font-size: 10px; text-align: center; }
.legend-card { padding: 17px; }
.legend-card h2 { margin-bottom: 13px; }
.status-legend { display: flex; flex-direction: column; gap: 11px; padding: 0; margin: 0; list-style: none; }
.status-legend li { display: flex; align-items: center; gap: 10px; }
.status-legend .status-chip { width: 25px; height: 22px; font-size: 11px; }
.status-legend strong, .status-legend small { display: block; }
.status-legend strong { color: #dce2d9; font-size: 11px; }
.status-legend small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.legend-footnote { margin: 13px 0 0; padding-top: 10px; border-top: 1px solid #34423a; color: var(--muted-soft); font-size: 9px; line-height: 1.5; }
.activity-card { padding: 13px 15px; }
.activity-heading { display: flex; justify-content: space-between; }
.activity-heading .eyebrow { margin: 0; }
.revision { color: #819087; font: 9px 'DM Mono', monospace; }
.activity-card p:last-child { margin: 9px 0 0; color: #bac4ba; font-size: 10px; line-height: 1.45; }
.page-footer { display: flex; justify-content: space-between; gap: 12px; padding: 17px 0 24px; border-top: 1px solid #27352d; color: #738077; font-size: 10px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: min(390px, calc(100% - 32px)); padding: 12px 15px; border: 1px solid #52664f; border-radius: 9px; color: #eaf0e6; background: #26352c; box-shadow: 0 12px 36px #0007; font-size: 12px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .2s ease; }
.toast.visible { opacity: 1; transform: translateY(0); }
.promotion-dialog { width: min(350px, calc(100% - 32px)); padding: 22px; border: 1px solid #51614f; border-radius: 14px; color: #edf0e8; background: #1d2922; box-shadow: 0 22px 70px #0009; }
.promotion-dialog::backdrop { background: #070c09bf; backdrop-filter: blur(4px); }
.promotion-dialog h2 { margin: 0 0 14px; font: 600 20px 'Playfair Display', Georgia, serif; }
.promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.promotion-options button { aspect-ratio: 1; border: 1px solid #4a5b50; border-radius: 8px; color: var(--accent); background: #26362c; font: 32px 'DejaVu Sans', 'Segoe UI Symbol', serif; cursor: pointer; }
.promotion-options button:hover { background: #374b3b; }

@media (max-width: 900px) {
  .app-shell { width: min(100% - 40px, 720px); }
  .page-heading { grid-template-columns: 1fr; align-items: start; gap: 22px; padding-top: 34px; }
  .room-card { width: 100%; }
  .play-area { grid-template-columns: minmax(0, 1fr) minmax(230px, .72fr); gap: 24px; }
  .board-wrap { grid-template-columns: 16px minmax(0, 1fr); gap: 4px; }
}
@media (max-width: 650px) {
  .app-shell { width: calc(100% - 28px); }
  .topbar { height: 62px; }
  .brand { font-size: 16px; }
  .connection { font-size: 10px; }
  .page-heading { padding: 28px 0 17px; gap: 17px; }
  h1 { font-size: clamp(38px, 12vw, 52px); }
  .intro { font-size: 12px; }
  .room-card { padding: 15px; }
  .play-area { display: flex; flex-direction: column; gap: 17px; padding-top: 9px; }
  .board-column { max-width: 560px; }
  .board-wrap { aspect-ratio: 1 / 1.035; }
  .piece-glyph { font-size: clamp(24px, 8vw, 44px); }
  .square.selected { box-shadow: inset 0 0 0 3px #c7f36b; }
  .square.legal.has-piece::after { border-width: 3px; }
  .game-panel { display: grid; width: 100%; grid-template-columns: 1fr 1fr; align-items: stretch; gap: 10px; }
  .die-card { grid-column: 1 / -1; }
  .activity-card { grid-column: 1 / -1; }
  .die-card, .legend-card { padding: 14px; }
  .status-legend { gap: 8px; }
  .status-legend small { font-size: 8px; }
  .page-footer { flex-direction: column; gap: 5px; font-size: 9px; }
  .board-caption { text-align: left; }
}
@media (max-width: 390px) {
  .orientation-control { gap: 5px; }
  .orientation-control select { max-width: 112px; }
  .turn-status { gap: 6px; font-size: 10px; }
  .game-panel { grid-template-columns: 1fr; }
  .die-card, .activity-card { grid-column: auto; }
}
