/* Page layouts: shell, home, play, players, settings. */

/* ---------- shell: side menu (wide) / icon rail (medium) / floating bar (phones) ---------- */
.shell { display: grid; grid-template-columns: 208px minmax(0, 1fr); min-height: 100dvh; }
.nav {
  position: sticky; top: 0; z-index: 20; height: 100dvh; display: flex; flex-direction: column; padding: 18px 12px 14px;
  background: linear-gradient(90deg, rgb(255 255 255 / 0.03), transparent), color-mix(in srgb, var(--md-sys-color-surface) 58%, transparent);
  backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: inset -1px 0 0 rgb(255 255 255 / 0.07), 8px 0 30px -14px rgb(0 0 0 / 0.5);
}
:root[data-mode="light"] .nav { background: var(--glass); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 4px 22px; color: inherit; text-decoration: none; font: 750 1.1875rem/1 var(--font); letter-spacing: -0.02em; }
.brand small { display: block; margin-top: 3px; font: 600 0.75rem/1 var(--font); letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent-text); }
.mark {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; border-radius: 13px;
  background: linear-gradient(160deg, var(--md-sys-color-accent-hi), var(--md-sys-color-accent-lo)); color: var(--md-sys-color-on-accent);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.55), inset 0 -2px 0 rgb(0 0 0 / 0.2), 0 6px 16px -6px var(--accent); transition: transform var(--t-slow) var(--spring);
}
.mark .icon { width: 26px; height: 26px; }
.brand:hover .mark { transform: rotate(-8deg) scale(1.06); }
.nav-list { position: relative; display: grid; gap: 2px; }
/* The chosen page's pill. Its leading edge moves faster, so it stretches like a drop. */
.nav-pill {
  position: absolute; top: var(--top, 0); bottom: var(--bottom, 100%); left: var(--left, 0); right: var(--right, 0); opacity: 0; border-radius: var(--r-md);
  background: linear-gradient(160deg, rgb(255 255 255 / 0.16), rgb(255 255 255 / 0.06)); box-shadow: var(--btn-edge), 0 6px 16px -8px rgb(0 0 0 / 0.5);
  transition: top var(--lead, 260ms) var(--ease), left var(--lead, 260ms) var(--ease), bottom var(--trail, 460ms) var(--ease), right var(--trail, 460ms) var(--ease), opacity var(--t) var(--ease);
}
:root[data-mode="light"] .nav-pill { background: rgb(255 255 255 / 0.75); }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: var(--r-md);
  color: var(--ink); text-decoration: none; font: 600 0.9375rem/1.25rem var(--font); transition: background-color var(--t-fast) var(--ease);
}
@media (hover: hover) { .nav-item:hover:not([aria-current]) { background: var(--fill-1); } .nav-item:hover .ni .icon { transform: scale(1.12) rotate(-4deg); } }
.ni { position: relative; display: grid; place-items: center; color: var(--c, var(--accent-text)); }
.ni .icon { transition: transform var(--t-slow) var(--spring); }
.ni .badge { position: absolute; top: -7px; inset-inline-start: 13px; }
:root[data-mode="light"] .ni { filter: saturate(1.2) brightness(0.72); }
.nav-item .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-foot { margin-top: auto; display: grid; gap: 4px; }
.nav-tools { display: flex; justify-content: space-between; padding: 0 2px; }
.nav-item.me { padding-inline: 8px; }
.narrow-only { display: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; max-width: 1320px; margin: 0 auto; padding: 26px 28px 6px; }
.topbar h1 { font: 720 1.75rem/2.25rem var(--font); letter-spacing: -0.015em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar #top-avatar { display: none; }
#page { width: 100%; max-width: 1320px; margin: 0 auto; padding: 12px 28px 48px; }
/* These pages name themselves in their content. */
@media (min-width: 840px) {
  :root:is([data-page="home"], [data-page="game"], [data-page="analysis"], [data-page="profile"], [data-page="tournament"]) .topbar { display: none; }
  :root:is([data-page="home"], [data-page="game"], [data-page="analysis"], [data-page="profile"], [data-page="tournament"]) #page { padding-top: 20px; }
  :root:is([data-page="game"], [data-page="analysis"]) #page { max-width: 1600px; padding-bottom: 20px; }
}
@media (min-width: 840px) and (max-width: 1159px) {
  .shell { grid-template-columns: 76px minmax(0, 1fr); }
  .nav { padding-inline: 10px; }
  .brand { margin-inline: 7px; } .brand > span:last-child, .nav-item .lbl { display: none; }
  .nav-item, .nav-item.me { justify-content: center; padding: 0; }
  .nav-tools { flex-direction: column; align-items: center; }
  #page, .topbar { padding-inline: 20px; }
}
@media (max-width: 839px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: fixed; inset: auto 10px calc(10px + env(safe-area-inset-bottom)); height: 66px; flex-direction: row; padding: 6px; border-radius: 28px;
    background: var(--glass-sheen), color-mix(in srgb, var(--md-sys-color-surface) 62%, transparent);
    backdrop-filter: blur(22px) saturate(1.7); -webkit-backdrop-filter: blur(22px) saturate(1.7);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.22), inset 0 0 0 1px rgb(255 255 255 / 0.07), 0 18px 40px -10px rgb(0 0 0 / 0.7);
  }
  .brand, .nav-foot, .wide-only { display: none !important; }
  .narrow-only { display: flex; }
  .nav-list { flex: 1; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; }
  .nav-pill { border-radius: 22px; }
  .nav-item { flex-direction: column; justify-content: center; gap: 1px; min-height: 54px; padding: 0 2px; border-radius: 22px; font: 600 0.6875rem/1rem var(--font); }
  .nav-item .lbl { max-width: 100%; }
  .topbar {
    position: sticky; top: 0; z-index: 15; min-height: 56px; padding: max(6px, env(safe-area-inset-top)) 10px 6px 18px;
    background: color-mix(in srgb, var(--md-sys-color-surface) 48%, transparent); backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5);
    box-shadow: inset 0 -1px 0 rgb(255 255 255 / 0.06);
  }
  .topbar h1 { font: 700 1.1875rem/1.5rem var(--font); }
  .topbar #top-avatar { display: inline-grid; width: 46px; height: 46px; }
  #page { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); }
}

/* ---------- sign in ---------- */
.page-auth { display: grid; place-items: center; min-height: 100dvh; max-width: none !important; padding: 24px 16px !important; }
.page-auth .page-host { width: min(440px, 100%); }
.auth .brand-row { display: flex; align-items: center; gap: 16px; margin-bottom: 22px; }
.auth .mark { width: 64px; height: 64px; border-radius: 20px; animation: brand-in 700ms var(--spring); }
.auth .mark .icon { width: 40px; height: 40px; }
@keyframes brand-in { from { opacity: 0; transform: rotate(-40deg) scale(0.4); } }
.auth .card { padding: 24px; border-radius: 28px; }
.auth form { display: grid; gap: 8px; }
.auth .links { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.rules { list-style: none; padding: 4px 16px; margin: 0; display: grid; gap: 2px; }
.rules li { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; color: var(--ink-2); }
.rules li.ok { color: var(--accent-text); }
.rules .icon { width: 16px; height: 16px; }

/* ---------- home ---------- */
.home { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; max-width: 1260px; margin: 0 auto; }
.hello { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 14px; text-shadow: 0 1px 6px rgb(0 0 0 / 0.45); }
:root[data-mode="light"] .hello { text-shadow: none; }
.hello .who-name { color: inherit; text-decoration: none; font: 720 1.25rem/1.5rem var(--font); }
.hello .stats { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-inline-start: auto; }
.stat { display: flex; align-items: center; gap: 8px; font: 700 1.0625rem/1.25rem var(--font); }
.stat small { font: 500 0.8125rem/1rem var(--font); color: var(--ink-2); }
.stat .icon { color: var(--accent-text); width: 22px; height: 22px; }

.play-panel { display: grid; grid-template-columns: 236px repeat(3, minmax(0, 1fr)); gap: 14px; padding: 14px; }
.quick { display: flex; flex-direction: column; gap: 10px; padding: 4px 2px; }
.quick h2 { margin: 0 2px; }
.quick .chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.quick .chip { padding: 0 4px; }
.quick .spacer { flex: 1; }
.searching { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 8px 8px 16px; border-radius: var(--r-lg); background: var(--accent-soft); animation: breathe 2.2s ease-in-out infinite; }
.searching .grow { flex: 1; min-width: 0; font: 600 0.9375rem/1.25rem var(--font); }
@keyframes breathe { 50% { background: color-mix(in srgb, var(--accent) 38%, transparent); } }

.tile {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden; border-radius: var(--r-lg); background: var(--fill-1); box-shadow: var(--btn-edge); color: inherit; text-decoration: none;
  transition: transform var(--t-slow) var(--spring), background-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
@media (hover: hover) { a.tile:hover { transform: translateY(-5px); background: var(--fill-2); box-shadow: var(--btn-edge), 0 22px 34px -18px rgb(0 0 0 / 0.75); } a.tile:hover .btn.tonal { background: var(--fill-3); } }
a.tile:active { transform: scale(0.985); }
.tile-body { display: flex; flex-direction: column; gap: 12px; flex: 1; padding: 12px 14px 14px; }
.tile-head { position: relative; display: flex; align-items: center; gap: 10px; min-height: 40px; }
.tile-head > div { min-width: 0; flex: 1; }
.tile-head b, .tile-head small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-head b { font: 680 1rem/1.25rem var(--font); }
.tile-head small { color: var(--ink-2); font-size: 0.8125rem; line-height: 1.125rem; }
.tile .btn { margin-top: auto; width: 100%; }
.tile.soon .mini { filter: saturate(0.5) brightness(0.72); }
.mini-wrap { position: relative; aspect-ratio: 1; overflow: hidden; background: var(--fill-2); }
.mini { display: block; width: 100%; height: 100%; }
/* Light lying on a board. */
.mini-wrap::after, .board-area::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(155deg, rgb(255 255 255 / 0.16), rgb(255 255 255 / 0.03) 32%, transparent 55%, rgb(0 0 0 / 0.1));
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), inset 0 0 0 1px rgb(255 255 255 / 0.06);
}
.live { position: absolute; top: 0; inset-inline-end: 0; display: flex; align-items: center; gap: 6px; font: 700 0.8125rem/1.25rem var(--font); color: var(--ink-2); }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #6cc24a; animation: live 1.8s ease-out infinite; }
@keyframes live { from { box-shadow: 0 0 0 0 rgb(108 194 74 / 0.6); } to { box-shadow: 0 0 0 8px transparent; } }

.home-cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 18px; align-items: start; }
.home-cols > div { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.gtiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(290px, 100%), 1fr)); gap: 10px; }
.gtile { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 14px; align-items: center; padding: 8px; border-radius: var(--r-lg); background: var(--fill-1); box-shadow: var(--btn-edge); color: inherit; text-decoration: none; transition: transform var(--t-slow) var(--spring), background-color var(--t) var(--ease); }
@media (hover: hover) { .gtile:hover { transform: translateY(-3px); background: var(--fill-2); } }
.gtile .mini-wrap { border-radius: var(--r-sm); }
.gtile.myturn { box-shadow: inset 0 0 0 2px var(--accent); }
.gtile b, .gtile small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtile small { margin: 2px 0 8px; color: var(--ink-2); font-size: 0.8125rem; line-height: 1.125rem; }
.leaders { list-style: none; margin: 10px -8px 0; padding: 0; }
.leaders a { display: grid; grid-template-columns: 1.75rem 32px minmax(0, 1fr) auto; align-items: center; gap: 10px; min-height: 48px; padding: 4px 10px 4px 4px; border-radius: var(--r-md); color: inherit; text-decoration: none; }
.leaders .avatar { width: 32px; height: 32px; font-size: 0.8125rem; }
.leaders .pos { text-align: center; font: 700 0.9375rem/1 var(--font); color: var(--ink-2); }
.leaders li:nth-child(1) .pos { color: #ffcf4d; } .leaders li:nth-child(2) .pos { color: #cfd6dd; } .leaders li:nth-child(3) .pos { color: #e09a62; }
:root[data-mode="light"] .leaders .pos { color: var(--ink-2) !important; }
.leaders .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.leaders .val { font: 700 1rem/1 var(--font); font-variant-numeric: tabular-nums; }
.leaders .me a { background: var(--accent-soft); }

@media (max-width: 1159px) {
  .play-panel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .quick { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: center; }
  .quick h2, .quick .spacer { display: none; }
  .quick .chips { grid-column: 1 / 3; grid-template-columns: repeat(6, 1fr); }
  .home-cols { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 839px) { .hello > a { display: none; } .hello .stats { width: 100%; margin: 0; justify-content: space-between; gap: 6px; } }
@media (max-width: 959px) { .home-cols { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 699px) {
  .home { gap: 14px; }
  .stat { font-size: 1rem; gap: 6px; }
  .play-panel { display: block; padding: 12px; }
  .quick { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; padding: 0; }
  .quick .chips { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); }
  .quick .go-slot { grid-column: 1 / -1; }
  .quick > a.btn { min-height: 64px; flex-direction: column; gap: 3px; padding: 6px 4px; font-size: 0.75rem; line-height: 1rem; } .quick > a.btn .icon { margin: 0; }
  .tiles { display: flex; gap: 10px; margin: 0 -12px; padding: 2px 12px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-padding: 12px; scrollbar-width: none; }
  .tiles .tile { flex: 0 0 min(62vw, 240px); scroll-snap-align: start; }
}
@media (min-width: 700px) { .tiles { display: contents; } }

/* ---------- chess lobby ---------- */
.lobby { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.lobby-side { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.lobby-side .has-items { order: -1; }
@media (min-width: 720px) { .lobby { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); } }
@media (max-width: 719px) { .lobby-side { display: contents; } }
.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.tc {
  display: grid; justify-items: center; gap: 1px; padding: 11px 4px; border: none; border-radius: var(--r-md); background: var(--fill-2); box-shadow: var(--btn-edge); color: var(--ink); cursor: pointer;
  transition: transform var(--t) var(--spring), background-color var(--t) var(--ease), box-shadow var(--t) var(--ease);
}
.tc:active { transform: scale(0.95); }
@media (hover: hover) { .tc:hover { background: var(--fill-3); } }
.tc b { font: 680 1.1875rem/1.5rem var(--font); }
.tc span { font-size: 0.75rem; line-height: 1rem; color: var(--ink-2); }
.tc[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.suggest { position: relative; }
.suggest ul { position: absolute; z-index: 10; inset-inline: 0; top: 62px; margin: 0; padding: 6px; list-style: none; border-radius: var(--r-md); background: var(--md-sys-color-surface-container-high); box-shadow: var(--glass-shadow), inset 0 0 0 1px var(--hair); animation: fade var(--t-fast); }
.suggest li button { width: 100%; padding: 10px 12px; border: none; background: none; text-align: start; cursor: pointer; border-radius: var(--r-sm); font: inherit; color: inherit; }
.suggest li button:hover { background: var(--fill-2); }

/* ---------- play ---------- */
/* Board sizes use svh (the height with the browser's bars shown), not dvh: dvh
   changes when a phone's address bar slides away, which resized the board mid-game. */
.game { --panel: clamp(300px, 26vw, 400px); display: grid; grid-template-columns: minmax(280px, min(calc(100svh - 156px), 1040px)) var(--panel); gap: 22px; justify-content: center; align-items: stretch; }
.game.no-players { grid-template-columns: minmax(280px, min(calc(100svh - 22px), 1040px)) var(--panel); }
.board-col { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 8px; }
.board-row { display: flex; gap: 8px; }
.board-area { position: relative; flex: 1; aspect-ratio: 1; min-width: 0; touch-action: none; border-radius: 12px; box-shadow: 0 24px 50px -18px rgb(0 0 0 / 0.8), 0 0 0 1px rgb(0 0 0 / 0.3); transition: box-shadow var(--t-slow) var(--ease); }
.board-area.myturn { box-shadow: 0 24px 50px -18px rgb(0 0 0 / 0.8), 0 0 0 3px var(--accent), 0 0 34px -6px var(--accent); }
.board { display: block; width: 100%; height: 100%; border-radius: inherit; touch-action: none; user-select: none; -webkit-user-select: none; }
.board.can-move { cursor: grab; } .board.can-move:active { cursor: grabbing; }
.board .piece { transition: opacity var(--t-fast); }
.board .taken { transform-box: fill-box; transform-origin: center; animation: taken 260ms var(--ease) forwards; }
@keyframes taken { to { opacity: 0; transform: scale(0.35) rotate(14deg); } }
.board .dot { transform-box: fill-box; transform-origin: center; animation: pop 220ms var(--spring); }
.board .hl { animation: fade 220ms var(--ease); }
.board .hl-check { animation: check 1.1s ease-in-out infinite alternate; }
@keyframes check { from { opacity: 0.65; } }
.board .ghost { filter: drop-shadow(0 10px 9px rgb(0 0 0 / 0.5)); }
@media (pointer: fine) { .board .pieces { filter: drop-shadow(0 2px 2px rgb(0 0 0 / 0.35)); } }

.evalbar { position: relative; flex: none; width: 18px; border-radius: 9px; overflow: hidden; background: #2b2825; box-shadow: 0 0 0 1px rgb(255 255 255 / 0.12); }
.evalbar > i { position: absolute; inset-inline: 0; bottom: 0; height: 50%; background: linear-gradient(90deg, #fff, #e3ddd5); transition: height 700ms var(--ease); }
.evalbar.flipped > i { bottom: auto; top: 0; }
/* The score stands at the end of the leading side's part. */
.evalbar > b { position: absolute; left: 0; width: 18px; bottom: 6px; font: 700 0.625rem/18px var(--font); color: #3a3734; writing-mode: vertical-rl; transform: rotate(180deg); }
.evalbar:is(.black-ahead:not(.flipped), .flipped:not(.black-ahead)) > b { bottom: auto; top: 6px; }
.evalbar.black-ahead > b { color: #f2f0ec; }

.player { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; min-height: 46px; text-shadow: 0 1px 5px rgb(0 0 0 / 0.5); }
:root[data-mode="light"] .player { text-shadow: none; }
.player .name { min-width: 0; }
/* One line each, so the bar keeps its height whatever the name or material count. */
.player .name a, .player .name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .name a { color: inherit; text-decoration: none; font: 680 1rem/1.25rem var(--font); }
.player .name small { color: var(--ink-2); font-size: 0.8125rem; line-height: 1.125rem; }
.clock {
  margin-inline-start: auto; min-width: 6.4ch; padding: 9px 14px; text-align: end; text-shadow: none; border-radius: var(--r-md);
  font: 680 1.625rem/1 var(--font); font-variant-numeric: tabular-nums; background: var(--glass-sheen), var(--glass); color: var(--ink-2); box-shadow: var(--btn-edge);
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease), box-shadow var(--t) var(--ease), transform var(--t-slow) var(--spring);
}
.clock.running { background: #fbf6ef; color: #241a12; box-shadow: 0 6px 24px -6px rgb(255 240 220 / 0.55); transform: scale(1.03); }
.clock.low { color: var(--md-sys-color-error); }
.clock.low.running { background: #e5483d; color: #fff; animation: hurry 1s ease-in-out infinite; }
.clock.flagged { background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
@keyframes hurry { 50% { box-shadow: 0 0 0 5px rgb(229 72 61 / 0.35); } }

/* The panel is exactly as tall as the board column; only the move list scrolls. */
.panel { display: flex; flex-direction: column; height: 0; min-height: 100%; overflow: hidden; }
.tabs { display: flex; padding: 6px 12px 0; box-shadow: inset 0 -1px 0 var(--hair); }
.tabs button { flex: 1; min-height: 46px; border: none; background: none; color: var(--ink-2); cursor: pointer; font: 650 0.9375rem/1.25rem var(--font); position: relative; transition: color var(--t) var(--ease); }
.tabs button::after { content: ""; position: absolute; inset: auto 14% 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); transform: scaleX(0); transition: transform var(--t-slow) var(--spring); }
.tabs button[aria-selected="true"] { color: var(--ink); } .tabs button[aria-selected="true"]::after { transform: none; }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 14px 14px 8px; animation: fade var(--t) var(--ease); }
.panel-foot { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 12px 14px 14px; background: color-mix(in srgb, var(--md-sys-color-surface) 30%, transparent); box-shadow: inset 0 1px 0 var(--hair); }
.stake { text-align: center; font-size: 0.8125rem; line-height: 1.125rem; color: var(--ink-2); } .stake b { color: var(--ink); }
.navkeys { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; }
.navkeys button { display: grid; place-items: center; min-height: 44px; border: none; border-radius: var(--r-md); background: var(--fill-2); box-shadow: var(--btn-edge); color: var(--ink); cursor: pointer; transition: transform var(--t) var(--spring), background-color var(--t-fast), opacity var(--t); }
@media (hover: hover) { .navkeys button:hover:not(:disabled) { background: var(--fill-3); } }
.navkeys button:active:not(:disabled) { transform: scale(0.93); }
.navkeys button:disabled { opacity: 0.4; cursor: default; }
.acts { display: flex; flex-wrap: wrap; gap: 8px; } .acts:empty, #offer:empty { display: none; }
.acts .btn { flex: 1 1 auto; padding-inline: 10px; font-size: 0.875rem; }
.status { padding: 10px 14px; border-radius: var(--r-md); background: var(--fill-2); }
.status.result { background: var(--accent-soft); }
.status.alert { background: color-mix(in srgb, var(--accent) 34%, transparent); }
.engine-line { font: 400 0.8125rem/1.25rem var(--font-mono); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.moves { flex: 1; min-height: 60px; overflow-y: auto; margin: 0 -6px; padding: 0 6px; font-variant-numeric: tabular-nums; }
.mrow { display: grid; grid-template-columns: 2.4em minmax(0, 1fr) minmax(0, 1fr) 52px; align-items: center; min-height: 32px; border-radius: var(--r-sm); }
.mrow:nth-child(even) { background: var(--fill-1); }
.mrow .no { padding-inline-start: 8px; color: var(--ink-2); font-size: 0.8125rem; }
.mv { display: inline-flex; align-items: center; justify-self: start; gap: 2px; min-height: 28px; padding: 2px 8px; border: none; border-radius: 7px; background: none; color: inherit; text-align: start; cursor: pointer; font: 600 0.9375rem/1.25rem var(--font); }
@media (hover: hover) { button.mv:hover { background: var(--fill-2); } }
.mv.cur { background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 60%, transparent); }
.mv .fig { width: 19px; height: 19px; margin-inline-start: -3px; }
.mrow .tm { display: grid; gap: 1px; padding-inline-end: 8px; text-align: end; color: var(--ink-2); font-size: 0.6875rem; line-height: 0.8125rem; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 16px; margin: 0; font-size: 0.9375rem; } .facts dt { color: var(--ink-2); } .facts dd { margin: 0; text-align: end; }
.tools { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; } .tools .btn { justify-content: flex-start; padding-inline: 14px; font-size: 0.875rem; text-align: start; }
.panel-scroll { overflow-y: auto; display: grid; align-content: start; gap: 16px; }

/* Game over, on the board. */
.over { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 12px; border-radius: inherit; background: rgb(0 0 0 / 0.35); animation: fade var(--t) var(--ease); }
.over-card { position: relative; width: min(330px, 100%); padding: 26px 22px 20px; border-radius: 28px; text-align: center; background: var(--glass-sheen), var(--glass-strong); backdrop-filter: blur(22px) saturate(1.5); -webkit-backdrop-filter: blur(22px) saturate(1.5); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.25), inset 0 0 0 1px rgb(255 255 255 / 0.08), 0 30px 60px -16px rgb(0 0 0 / 0.8); animation: dlg-in 560ms var(--spring); }
.over-card .medal { display: grid; place-items: center; width: 68px; height: 68px; margin: 0 auto 10px; border-radius: 50%; background: var(--fill-3); color: var(--ink-2); animation: pop 700ms 120ms var(--spring) both; } .over-card .medal .icon { width: 36px; height: 36px; }
.over-card.won .medal { background: linear-gradient(160deg, #ffe08a, #e0951d); color: #4a2b00; box-shadow: 0 8px 30px -6px #ffb640; }
.over-card .gain { display: inline-block; margin-top: 10px; animation: pop 600ms 360ms var(--spring) both; }
.over-card .row { justify-content: center; margin-top: 18px; } .over-card .row .btn { flex: 1; padding-inline: 10px; }
.over-card .x { position: absolute; top: 10px; inset-inline-end: 10px; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; border-radius: inherit; }
.confetti i { position: absolute; top: -14px; left: var(--x); width: 8px; height: 13px; border-radius: 2px; background: var(--c); animation: fall var(--d) var(--w) cubic-bezier(0.3, 0.4, 0.7, 1) both; }
@keyframes fall { from { opacity: 1; } 80% { opacity: 1; } to { opacity: 0; transform: translate(var(--s), 110cqh) rotate(var(--r)); } }
.board-area { container-type: size; }

@media (max-width: 959px), (max-width: 1159px) and (orientation: portrait) {
  .game, .game.no-players { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .board-col { width: min(100%, max(320px, calc(100svh - 190px))); justify-self: center; }
  .panel { height: auto; min-height: 0; width: min(100%, max(320px, calc(100svh - 190px))); justify-self: center; overflow: visible; }
  .panel-foot { order: 0; background: none; box-shadow: none; } .tabs { order: 1; } .panel-body { order: 2; }
  .moves { max-height: 320px; }
}
@media (max-width: 599px) {
  /* Phones: the board and both clocks fit between the top bar and the bottom menu. */
  :root:is([data-page="game"], [data-page="analysis"]) #page { padding: 6px 8px calc(92px + env(safe-area-inset-bottom)); }
  .board-col, .panel { width: 100%; min-width: 0; }
  .board-col { gap: 6px; justify-items: center; }
  .board-col > * { width: 100%; }
  .board-col.with-players > * { width: min(100%, max(240px, calc(100svh - 262px - env(safe-area-inset-top) - env(safe-area-inset-bottom)))); }
  .board-area { border-radius: 8px; }
  .clock { font-size: 1.375rem; padding: 8px 12px; }
  .player .avatar { width: 36px; height: 36px; }
}

/* ---------- players ---------- */
/* Every row is a grid with fixed column widths, so numbers and buttons line up.
   Phones: the chosen number (rank under it); wider: all of them. */
.players-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; margin-bottom: 10px; }
.players-tools .search { flex: 1 1 220px; }
.players-tools .chip .n { opacity: 0.7; }
.players .seg { margin-bottom: 10px; max-width: none; }
.plist { list-style: none; margin: 0 0 12px; padding: 0; }
.prow { display: grid; grid-template-columns: 40px minmax(0, 1fr) 4rem 84px; align-items: center; gap: 8px; min-height: 64px; padding: 8px 4px; border-radius: var(--r-md); }
.prow + .prow { background: linear-gradient(var(--hair), var(--hair)) top / 100% 1px no-repeat; }
.prow.me, .prow.head + .prow.me { background: var(--accent-soft); }
.prow .rank { display: none; text-align: end; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.prow .who-col { min-width: 0; }
.prow .who-col > * { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prow .r { display: none; text-align: end; font-variant-numeric: tabular-nums; }
.prow .r.sel { display: block; }
.prow .r b { font: 650 1.0625rem/1.5rem var(--font); }
.prow .rank-sm { display: block; min-height: 1rem; color: var(--ink-2); font-size: 0.75rem; line-height: 1rem; }
.prow .acts2 { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.prow .slot2 { display: inline-grid; place-items: center; width: 40px; height: 40px; }
.prow.head { display: none; }
@media (min-width: 840px) {
  .prow { grid-template-columns: 2rem 40px minmax(0, 1fr) repeat(var(--cols, 4), 5rem) 84px; gap: 12px; padding-inline: 8px; }
  .prow .rank, .prow .r { display: block; }
  .prow .r.sel b { color: var(--accent-text); }
  .prow .rank-sm { display: none; }
  .prow.head { display: grid; min-height: 0; padding-block: 0 4px; font: 600 0.75rem/1rem var(--font); color: var(--ink-2); }
  .prow.head button.r { padding: 4px 0; border: none; background: none; font: inherit; color: inherit; cursor: pointer; }
  .prow.head button.r.sel { color: var(--accent-text); }
}

/* ---------- profile / tournaments ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; align-items: start; }
.ratings { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.rating { padding: 14px 16px; border-radius: var(--r-lg); background: var(--fill-1); box-shadow: var(--btn-edge); }
.rating b { display: block; margin: 2px 0; font: 680 1.75rem/2.125rem var(--font); font-variant-numeric: tabular-nums; }
.rating .body-s { color: var(--ink-2); }
.rating.total { background: var(--accent-soft); }
.result-w { color: var(--md-sys-color-tertiary); font-weight: 650; }
.result-l { color: var(--md-sys-color-error); font-weight: 650; }
.page-head { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 12px; margin: 0 0 14px; }
@media (min-width: 840px) { :root[data-page="tournaments"] .page-head { margin-top: -62px; min-height: 48px; } }
/* Cards stacked directly on a page. (Inside a grid the gap spaces them.) */
.page-host > section.card + section.card { margin-top: 16px; }
/* A person's name (with avatar) as a link, coloured like the text around it. */
a.person { display: inline-flex; align-items: center; gap: 8px; min-width: 0; color: inherit; text-decoration: none; }
a.person:hover > span { text-decoration: underline; }
.who { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; }

/* ---------- settings ---------- */
.settings h2 .icon { color: var(--accent-text); margin-inline-end: 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 46px; height: 46px; padding: 0; border: none; border-radius: 50%; cursor: pointer; box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.35), 0 3px 8px rgb(0 0 0 / 0.3); transition: transform var(--t) var(--spring), border-radius var(--t) var(--ease), box-shadow var(--t) var(--ease); }
@media (hover: hover) { .swatch:hover { transform: scale(1.08); } }
.swatch[aria-pressed="true"] { border-radius: var(--r-md); box-shadow: 0 0 0 2px var(--glass-strong), 0 0 0 4px var(--accent); }
.swatch.sm { width: 36px; height: 36px; }
.board-swatch { display: grid; grid-template-columns: 1fr 1fr; width: 56px; height: 56px; border-radius: var(--r-md); overflow: hidden; }
.board-swatch i { display: block; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: var(--r-md); width: max-content; }
.qr svg { width: 200px; height: 200px; }
.codes { display: grid; grid-template-columns: repeat(2, auto); gap: 4px 24px; font: 500 1rem/1.5rem var(--font-mono); }
/* Balanced columns instead of rows of very different heights. */
@media (min-width: 900px) {
  .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto auto auto 1fr; grid-template-areas: "avatar lang" "look notify" "look security" "look account"; }
  /* The two short cards on top share their height, so the cards below start evenly. */
  .settings > .s-avatar { grid-area: avatar; align-self: stretch; }
  .settings > .s-lang { grid-area: lang; align-self: stretch; }
  .settings > .s-look { grid-area: look; }
  .settings > .s-app { grid-area: notify; } /* install + notifications */
  .settings > .s-security { grid-area: security; }
  .settings > .s-account { grid-area: account; }
}
@media (max-width: 1199px) { .settings .seg > button .icon { display: none; } }
@media (min-width: 1500px) { .settings { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: auto auto 1fr; grid-template-areas: "avatar look lang" "notify look security" "account look security"; } }
.crop { position: relative; width: min(72vw, 280px); aspect-ratio: 1; overflow: hidden; touch-action: none; cursor: grab; background: var(--fill-3); }
.crop img { position: absolute; top: 0; left: 0; max-width: none; user-select: none; -webkit-user-select: none; pointer-events: none; }
.photo-colors { width: min(78vw, 420px); }
.photo-colors img { width: 100%; max-height: 240px; object-fit: contain; border-radius: var(--r-lg); cursor: crosshair; background: var(--fill-2); }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { display: grid; justify-items: center; gap: 4px; padding: 8px 4px; border: 2px solid transparent; border-radius: var(--r-lg); background: var(--fill-2); color: inherit; cursor: pointer; }
.slot i { display: block; width: 40px; height: 40px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.15); }
.slot.on { border-color: var(--accent); }
.shapes { display: flex; flex-wrap: wrap; gap: 8px; }
.shape-pick { display: grid; place-items: center; width: 48px; height: 48px; padding: 0; border: none; border-radius: var(--r-md); background: transparent; cursor: pointer; transition: background-color var(--t) var(--ease), transform var(--t) var(--spring); }
@media (hover: hover) { .shape-pick:hover { transform: scale(1.1); } }
.shape-pick .avatar.sm { width: 32px; height: 32px; background: color-mix(in srgb, var(--ink) 42%, transparent); }
.shape-pick[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.shape-pick[aria-pressed="true"] .avatar { background: var(--accent); }
.piece-sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.piece-set { display: grid; grid-template-columns: 1fr 1fr; justify-items: center; padding: 8px 8px 6px; border: none; border-radius: var(--r-lg); background: var(--fill-1); box-shadow: var(--btn-edge); color: inherit; cursor: pointer; transition: background-color var(--t) var(--ease), transform var(--t) var(--spring); }
@media (hover: hover) { .piece-set:hover { transform: translateY(-2px); background: var(--fill-2); } }
.piece-set .pp { display: grid; place-items: center; width: 100%; aspect-ratio: 1; } .piece-set .pp:first-child { border-radius: 8px 0 0 8px; } .piece-set .pp:nth-child(2) { border-radius: 0 8px 8px 0; }
.piece-set img { width: 92%; height: 92%; }
.piece-set .label-m { grid-column: 1 / -1; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.piece-set[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.camera { display: grid; justify-items: center; gap: 16px; width: min(80vw, 480px); }
.camera video { width: 100%; max-height: 60dvh; object-fit: cover; border-radius: var(--r-xl); background: #000; }
.camera video.mirror { transform: scaleX(-1); }
.camera-actions { justify-content: center; gap: 24px; }
