:root {
  --bg: #0f0f0f;
  --panel: #181818;
  --panel-2: #202020;
  --panel-3: #292929;
  --line: #343434;
  --line-strong: #555;
  --text: #f5f5f5;
  --muted: #b7b7b7;
  --dim: #777;
  --board: #55764a;
  --board-line: rgba(0, 0, 0, .34);
  --radius: 12px;
  --shadow: 0 20px 60px rgba(0, 0, 0, .28);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-family: var(--sans); line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { color: inherit; }
code, pre { font-family: var(--mono); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.12; }
h1 { margin-bottom: 0; font-size: clamp(1.5rem, 3vw, 2.35rem); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: 1.18rem; letter-spacing: -.02em; }
h3 { margin-bottom: 10px; font-size: .92rem; }

.topbar { position: sticky; z-index: 30; top: 0; min-height: 64px; padding: 0 clamp(16px, 3vw, 42px); display: flex; align-items: center; gap: 28px; border-bottom: 1px solid var(--line); background: rgba(15, 15, 15, .95); backdrop-filter: blur(14px); }
.brand { font-weight: 780; letter-spacing: -.02em; white-space: nowrap; }
.brand.centered { display: block; text-align: center; }
.topnav { display: flex; align-items: center; gap: 20px; margin-left: auto; }
.topnav a { color: var(--muted); font-size: .82rem; }
.topnav a:hover, .topnav a.active { color: var(--text); }
.link-button { border: 0; background: none; color: var(--muted); cursor: pointer; }
.connection-pill { min-width: 88px; padding: 7px 10px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font: 700 .65rem var(--mono); text-transform: uppercase; }
.connection-pill span { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.connection-pill.online span { background: var(--text); }

.page-shell, .docs-shell, .admin-shell { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 38px; }
.docs-shell { width: min(1120px, calc(100% - 40px)); }
.narrow-shell { width: min(430px, calc(100% - 40px)); min-height: 100vh; margin: 0 auto; padding: 80px 0; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { min-height: 74px; padding: 17px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.section-label { margin-bottom: 5px; color: var(--dim); font: 700 .61rem var(--mono); text-transform: uppercase; letter-spacing: .11em; }
.text-link { color: var(--muted); font-size: .75rem; text-decoration: underline; text-underline-offset: 3px; }
.match-state { padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font: 700 .62rem var(--mono); text-transform: uppercase; }
.muted { color: var(--dim); }

.summary-bar { margin-bottom: 18px; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.summary-bar > div { min-width: 0; padding: 14px 18px; border-right: 1px solid var(--line); }
.summary-bar > div:last-child { border-right: 0; }
.summary-bar strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 720 1rem var(--mono); }
.summary-bar span { display: block; margin-top: 3px; color: var(--dim); font-size: .62rem; text-transform: uppercase; }

.arena-grid { display: grid; grid-template-columns: minmax(700px, 1.55fr) minmax(430px, .75fr); gap: 18px; }
.broadcast-body { min-height: 650px; padding: 22px; display: grid; grid-template-columns: minmax(440px, 1fr) 240px; gap: 22px; }
.board-wrap { width: min(620px, 100%); margin: 0 auto; }
.reversi-board { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border: 7px solid #2f3c2a; border-radius: 7px; overflow: hidden; background: var(--board); box-shadow: 0 18px 40px rgba(0, 0, 0, .36); }
.board-cell { position: relative; display: grid; place-items: center; border-right: 1px solid var(--board-line); border-bottom: 1px solid var(--board-line); }
.board-cell:nth-child(8n) { border-right: 0; }
.board-cell:nth-last-child(-n+8) { border-bottom: 0; }
.board-cell.last-move::after { content: ""; position: absolute; inset: 7%; border: 2px solid rgba(255, 255, 255, .55); border-radius: 4px; }
.disc { position: relative; z-index: 1; width: 78%; aspect-ratio: 1; border-radius: 50%; box-shadow: 0 5px 10px rgba(0, 0, 0, .38); }
.disc.black { background: #080808; border: 1px solid #333; }
.disc.white { background: #f1f1f1; border: 1px solid #aaa; }
.legal-dot { width: 13%; aspect-ratio: 1; border-radius: 50%; background: rgba(0, 0, 0, .32); }
.player-ribbon { min-height: 57px; padding: 10px 13px; display: grid; grid-template-columns: 26px minmax(0, 1fr) 62px 36px 76px; align-items: center; gap: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.player-ribbon.top { border-radius: 8px 8px 0 0; border-bottom: 0; }
.player-ribbon.bottom { border-radius: 0 0 8px 8px; border-top: 0; }
.player-ribbon.active { background: var(--panel-3); outline: 1px solid var(--line-strong); }
.player-ribbon strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-ribbon em { color: var(--dim); font: normal .72rem var(--mono); text-align: right; }
.player-ribbon b { text-align: center; font-family: var(--mono); }
.player-clock { text-align: right; font: 760 .93rem var(--mono); }
.disc-mini { width: 22px; height: 22px; border-radius: 50%; }
.disc-mini.black { background: #080808; border: 1px solid #444; }
.disc-mini.white { background: #eee; border: 1px solid #999; }
.match-sidebar { min-width: 0; }
.match-sidebar h2 { margin: 3px 0 14px; }
.match-list { max-height: 520px; overflow: auto; display: grid; gap: 7px; }
.match-item { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; text-align: left; }
.match-item:hover, .match-item.active { border-color: var(--line-strong); background: var(--panel-2); color: var(--text); }
.match-item-line { display: grid; grid-template-columns: 8px minmax(0, 1fr) 24px; gap: 7px; align-items: center; font-size: .75rem; }
.match-item-line i { width: 7px; height: 7px; border-radius: 50%; }
.match-item-line i.black { background: #050505; border: 1px solid #555; }
.match-item-line i.white { background: #eee; }
.match-item-line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match-item small { display: block; margin-top: 6px; color: var(--dim); font: .61rem var(--mono); }
.match-meta { margin-top: 14px; padding-top: 14px; display: grid; gap: 5px; border-top: 1px solid var(--line); color: var(--dim); font-size: .68rem; }

.leaderboard-head, .leaderboard-row { display: grid; grid-template-columns: 34px minmax(120px, 1fr) 66px 110px 82px; align-items: center; gap: 9px; }
.leaderboard-head { padding: 9px 14px; color: var(--dim); font: 650 .58rem var(--mono); text-transform: uppercase; }
.leaderboard-row { padding: 12px 14px; border-top: 1px solid var(--line); font-size: .77rem; }
.leaderboard-row.top-three { background: var(--panel-2); }
.rank { color: var(--dim); font-family: var(--mono); }
.bot-cell { min-width: 0; }
.bot-cell strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot-cell small { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: .62rem; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); }
.status-dot.online, .status-dot.playing { background: var(--text); }
.record { color: var(--muted); font-family: var(--mono); }
.trend { min-width: 0; display: block; font-family: var(--mono); }
.trend b { display: block; font-size: .69rem; }
.trend small { display: block; color: var(--dim); font-size: .57rem; }
.rating-cell { text-align: right; font: 700 .9rem var(--mono); }
.rating-cell small { display: block; color: var(--dim); font-size: .57rem; }
.leaderboard-body { max-height: 648px; overflow: auto; }

.lower-grid { margin-top: 18px; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(360px, .75fr); gap: 18px; }
.recent-list { max-height: 510px; overflow: auto; }
.recent-row { padding: 12px 18px; display: grid; grid-template-columns: 52px minmax(180px, 1fr) 66px minmax(115px, .65fr) 120px; align-items: center; gap: 10px; border-top: 1px solid var(--line); font-size: .75rem; }
.recent-round, .recent-score { font-family: var(--mono); }
.recent-round { color: var(--dim); }
.recent-reason { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rules-groups { padding: 18px 20px 22px; display: grid; gap: 18px; }
.rules-groups section + section { padding-top: 17px; border-top: 1px solid var(--line); }
.rules-groups ul, .docs-card ul { margin: 0; padding-left: 18px; color: var(--muted); }
.rules-groups li, .docs-card li { margin: 7px 0; font-size: .78rem; }
.empty-state { padding: 40px 18px; color: var(--dim); text-align: center; font-size: .78rem; }
.empty-state.compact { padding: 22px 10px; }
.site-footer { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 0 0 36px; display: flex; justify-content: space-between; color: var(--dim); font-size: .72rem; }

.primary-button, .secondary-button, .small-button { cursor: pointer; border-radius: 7px; transition: .15s ease; }
.primary-button { min-height: 42px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--text); background: var(--text); color: #111; font-weight: 750; }
.primary-button:hover { background: #d9d9d9; border-color: #d9d9d9; }
.secondary-button, .small-button { padding: 8px 11px; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.secondary-button:hover, .small-button:hover { border-color: var(--line-strong); color: var(--text); }
.secondary-button.danger, .small-button.danger { border-style: dashed; }
.disabled { opacity: .45; pointer-events: none; }

.docs-card { padding: 24px; box-shadow: none; }
.hero-card { margin-bottom: 18px; }
.docs-card h2 { margin-bottom: 14px; }
.docs-card p { color: var(--muted); font-size: .82rem; }
.docs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.full-width { margin-bottom: 18px; }
.download-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
pre { margin: 12px 0; padding: 15px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: #e1e1e1; font-size: .73rem; line-height: 1.55; }
.protocol-table { margin-top: 16px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.protocol-table > div { padding: 12px; display: grid; grid-template-columns: minmax(240px, .7fr) 1fr; gap: 15px; border-top: 1px solid var(--line); }
.protocol-table > div:first-child { border-top: 0; }
.protocol-table span { color: var(--muted); font-size: .76rem; }
.protocol-table code { overflow: auto; white-space: nowrap; font-size: .72rem; }

.stack-form { display: grid; gap: 14px; }
.stack-form label, .inline-form label, .history-form label { display: grid; gap: 6px; color: var(--muted); font-size: .75rem; font-weight: 700; }
input, select { width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 7px; outline: none; background: var(--bg); color: var(--text); }
input:focus, select:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(255,255,255,.05); }
.login-card { margin-top: 28px; padding: 34px; }
.login-card h1 { margin-bottom: 24px; }
.alert { margin-bottom: 18px; padding: 13px 15px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-2); font-size: .8rem; }
.alert.error { border-style: dashed; }

.admin-control-card { margin-bottom: 18px; padding-bottom: 22px; }
.display-links { display: flex; flex-wrap: wrap; gap: 9px; }
.control-status { padding: 15px 20px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .76rem; }
.control-status strong { color: var(--text); font-family: var(--mono); }
.control-grid { padding: 20px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.compact-form { padding: 17px; align-content: start; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); }
.compact-form h2 { margin-bottom: 4px; }
.compact-form small { color: var(--dim); font-size: .68rem; }
.control-actions form { display: grid; }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.admin-card { padding: 22px; box-shadow: none; }
.inline-form { margin: 15px 0 20px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: .74rem; }
.admin-table th { padding: 9px 11px; color: var(--dim); text-align: left; font: 650 .58rem var(--mono); text-transform: uppercase; background: var(--bg); }
.admin-table td { padding: 11px; border-top: 1px solid var(--line); vertical-align: middle; }
.admin-table td > strong, .admin-table td > small { display: block; }
.admin-table td > small { color: var(--dim); font-size: .62rem; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions form { margin: 0; }
.empty-cell { padding: 28px !important; text-align: center; color: var(--dim); }
.token-reveal { margin-bottom: 18px; padding: 18px 20px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 20px; }
.token-reveal code { padding: 10px; overflow: auto; border-radius: 6px; background: var(--bg); word-break: break-all; }

.history-picker { margin-bottom: 18px; padding: 22px; }
.history-form { margin-top: 18px; display: grid; grid-template-columns: 1fr auto 1fr auto auto; align-items: end; gap: 10px; }
.versus { padding-bottom: 12px; color: var(--dim); }
.history-results-panel { min-height: 280px; }
.history-row { padding: 12px 16px; display: grid; grid-template-columns: 52px minmax(220px, 1fr) 70px minmax(170px, .8fr) auto; align-items: center; gap: 12px; border-top: 1px solid var(--line); font-size: .75rem; }
.history-row .round, .history-row .score { font-family: var(--mono); }
.history-row .pair small { display: block; color: var(--dim); }

.display-page { min-height: 100vh; overflow: hidden; }
.fullscreen-button { position: fixed; z-index: 100; top: 18px; right: 18px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 7px; background: var(--panel); color: var(--muted); cursor: pointer; }
:fullscreen .fullscreen-button { opacity: 0; pointer-events: none; }
.match-display { min-height: 100vh; display: grid; place-items: center; padding: 4vh 4vw; }
.display-stage { width: min(1450px, 100%); min-height: 88vh; display: grid; place-items: center; }
.display-message { text-align: center; }
.display-message h1 { margin: 12px 0 18px; font-size: clamp(2rem, 6vw, 5rem); }
.display-message > strong { font: 800 clamp(3rem, 11vw, 9rem) var(--mono); }
.display-game { width: 100%; height: 100%; display: grid; grid-template-columns: minmax(360px, .6fr) minmax(580px, 1fr); align-items: center; gap: 5vw; }
.display-game-header { align-self: center; }
.display-game-header p { color: var(--muted); font-family: var(--mono); }
.display-game-header h1 { margin: 15px 0 20px; font-size: clamp(2.3rem, 5vw, 5rem); }
.display-game-header span { color: var(--muted); font: 700 clamp(1rem, 2vw, 1.7rem) var(--mono); }
.display-board-column { width: min(78vh, 760px); justify-self: end; }
.reversi-board.large { border-width: 9px; }
.player-ribbon.large { min-height: 72px; grid-template-columns: 32px minmax(0, 1fr) 80px 48px 106px; font-size: 1.05rem; }
.player-ribbon.large .player-clock { font-size: 1.28rem; }

.leaderboard-display { width: min(1500px, calc(100% - 8vw)); min-height: 100vh; margin: 0 auto; padding: 6vh 0; }
.leaderboard-display > header { margin-bottom: 4vh; display: flex; align-items: end; justify-content: space-between; }
.leaderboard-display h1 { font-size: clamp(3rem, 7vw, 6rem); }
.display-status { text-align: right; }
.display-status strong { display: block; font: 800 clamp(1.3rem, 2.5vw, 2.2rem) var(--mono); }
.display-status span { color: var(--muted); font: .9rem var(--mono); }
.big-leaderboard-head, .big-leaderboard-row { display: grid; grid-template-columns: 90px minmax(280px, 1fr) 160px 300px 180px; align-items: center; gap: 20px; }
.big-leaderboard-head { padding: 12px 22px; color: var(--dim); font: 700 .75rem var(--mono); text-transform: uppercase; }
.big-leaderboard { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.big-leaderboard-row { min-height: 78px; padding: 13px 22px; border-top: 1px solid var(--line); background: var(--panel); }
.big-leaderboard-row:first-child { border-top: 0; }
.big-leaderboard-row:nth-child(-n+3) { background: var(--panel-2); }
.big-rank { color: var(--dim); font: 800 1.5rem var(--mono); }
.big-name strong { display: block; font-size: 1.35rem; }
.big-name small { color: var(--dim); text-transform: uppercase; }
.big-record, .big-trend { color: var(--muted); font: 1rem var(--mono); }
.big-rating { text-align: right; font: 800 1.8rem var(--mono); }
.big-rating small { display: block; color: var(--dim); font-size: .7rem; }

@media (max-width: 1160px) {
  .arena-grid { grid-template-columns: 1fr; }
  .broadcast-body { grid-template-columns: minmax(400px, 1fr) 230px; }
  .lower-grid, .admin-grid { grid-template-columns: 1fr; }
  .control-grid { grid-template-columns: 1fr 1fr; }
  .display-game { grid-template-columns: 1fr; gap: 3vh; }
  .display-game-header { text-align: center; }
  .display-board-column { justify-self: center; width: min(62vh, 680px); }
  .big-leaderboard-head, .big-leaderboard-row { grid-template-columns: 70px minmax(220px, 1fr) 130px 220px 150px; }
}

@media (max-width: 820px) {
  .topbar { padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
  .topnav { order: 3; width: 100%; overflow-x: auto; margin: 0; padding-bottom: 2px; }
  .connection-pill { margin-left: auto; }
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .summary-bar > div { border-bottom: 1px solid var(--line); }
  .broadcast-body { grid-template-columns: 1fr; min-height: auto; }
  .match-list { max-height: 260px; }
  .docs-grid, .control-grid { grid-template-columns: 1fr; }
  .leaderboard-head, .leaderboard-row { grid-template-columns: 30px minmax(100px, 1fr) 62px 90px 72px; gap: 6px; padding-left: 9px; padding-right: 9px; }
  .recent-row { grid-template-columns: 42px minmax(150px, 1fr) 55px; }
  .recent-row > :nth-child(4), .recent-row > :nth-child(5) { display: none; }
  .history-form { grid-template-columns: 1fr; }
  .versus { display: none; }
  .history-row { grid-template-columns: 45px 1fr 55px; }
  .history-row > :nth-child(4), .history-row > :nth-child(5) { display: none; }
  .protocol-table > div { grid-template-columns: 1fr; }
  .token-reveal { grid-template-columns: 1fr; }
  .big-leaderboard-head, .big-leaderboard-row { grid-template-columns: 50px minmax(150px, 1fr) 100px; }
  .big-leaderboard-head > :nth-child(3), .big-leaderboard-head > :nth-child(4),
  .big-leaderboard-row > :nth-child(3), .big-leaderboard-row > :nth-child(4) { display: none; }
  .big-rating { font-size: 1.25rem; }
}
