  :root {
    --bg: #f4efe6;
    --board: #fffdf8;
    --line: #e6dccb;
    --ink: #3b3226;
    --accent: #d9534f;
    --empty: #f3ede2;
    --empty-hover: #e9dfcd;
    --btn: #fff;
    --btn-hover: #f8f2e8;
    --btn-border: #c9bba3;
    --overlay: rgba(255,253,248,.88);
    --bad: #f5c6c4;
    --good: #2e7d32;
    --stone: #6d6a66;
    --stone-2: #7a7772;
    color-scheme: light;
  }
  :root[data-theme="dark"] {
    --bg: #1c1a17;
    --board: #262320;
    --line: #3a352e;
    --ink: #ece4d6;
    --accent: #ff7b72;
    --empty: #302c27;
    --empty-hover: #3d3831;
    --btn: #2e2a25;
    --btn-hover: #3a352e;
    --btn-border: #4a443b;
    --overlay: rgba(28,26,23,.9);
    --bad: #6b2f2c;
    --good: #7fd88a;
    --stone: #4a4743;
    --stone-2: #55524d;
    color-scheme: dark;
  }
  :root[data-theme="dark"] .cell.tile { filter: brightness(.85) saturate(.9); }
  * { box-sizing: border-box; }
  body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--ink);
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
  }
  .timebar {
    width: var(--panel-w); height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; margin-bottom: 10px;
  }
  .timebar > div { height: 100%; background: #6cba5f; transition: width .25s linear, background .3s; }
  button, select {
    font: inherit; font-size: 14px; padding: 6px 12px; border-radius: 6px;
    border: 1px solid var(--btn-border); background: var(--btn); color: var(--ink); cursor: pointer;
  }
  button:hover { background: var(--btn-hover); }
  .wrap { position: relative; }
  #board {
    display: grid;
    gap: 2px;
    padding: 6px;
    background: var(--board);
    border: 2px solid var(--line);
    border-radius: 10px;
    touch-action: manipulation;
  }
  .cell {
    width: var(--cs); height: var(--cs);
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: calc(var(--cs) * .52);
    cursor: pointer;
    position: relative;
  }
  .cell.empty { background: var(--empty); }
  .cell.empty:hover { background: var(--empty-hover); }
  .cell.tile { color: #fff; cursor: default; text-shadow: 0 1px 1px rgba(0,0,0,.25); box-shadow: inset 0 -3px 0 rgba(0,0,0,.15); }
  .cell.hit { animation: pop .45s ease-out forwards; }
  .cell.near { outline: 3px solid rgba(0,0,0,.35); outline-offset: -3px; }
  .cell.hint { animation: pulse 1s ease-in-out 3; }
  .cell.bad { animation: shake .3s; background: var(--bad) !important; }
  @keyframes pop {
    0% { transform: scale(1); opacity: 1; }
    40% { transform: scale(1.25); opacity: 1; }
    100% { transform: scale(0) rotate(25deg); opacity: 0; }
  }
  .cell.stone {
    cursor: not-allowed;
    background: repeating-linear-gradient(45deg, var(--stone), var(--stone) 4px, var(--stone-2) 4px, var(--stone-2) 8px);
    box-shadow: inset 0 -3px 0 rgba(0,0,0,.3), inset 0 2px 0 rgba(255,255,255,.12);
  }
  .cell.stone.cracked::after {
    content: ''; position: absolute; inset: 0;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M3 2 L8 8 L6 12 L11 15 L10 19 M8 8 L14 6 L18 9 M11 15 L16 14' fill='none' stroke='%23fff' stroke-width='1.3' stroke-opacity='.8'/%3E%3C/svg%3E") center / 100% no-repeat;
  }
  .cell.stone.hit { animation: shatter .45s ease-out forwards; }
  @keyframes shatter {
    0% { transform: scale(1); opacity: 1; }
    30% { transform: scale(1.15) rotate(-6deg); filter: brightness(1.8); }
    100% { transform: scale(.2) rotate(40deg); opacity: 0; }
  }
  #board.hot { border-color: #ff9800; box-shadow: 0 0 14px rgba(255,152,0,.55); transition: box-shadow .3s, border-color .3s; }
  .heatbar {
    display: none; position: relative;
    width: var(--panel-w); height: 16px; background: var(--line); border-radius: 8px; overflow: hidden; margin: -4px 0 10px;
  }
  body.blockers .heatbar { display: block; }
  .heatbar > div { height: 100%; width: 0; transition: width .1s linear; background: linear-gradient(90deg, #ffd54a, #ff9800); }
  .heatbar.hot > div { background: linear-gradient(90deg, #ff9800, #ff3d00); animation: flicker .5s ease-in-out infinite alternate; }
  .heatbar span {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; letter-spacing: .5px; color: var(--ink);
  }
  .heatbar.hot span { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
  @keyframes flicker { to { filter: brightness(1.25); } }
  @keyframes pulse { 50% { background: #ffd54a; } }
  @keyframes shake {
    25% { transform: translateX(-3px); } 75% { transform: translateX(3px); }
  }
  svg#rays { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
  .float {
    position: absolute; pointer-events: none; font-weight: 800; font-size: 20px;
    animation: rise .9s ease-out forwards;
  }
  @keyframes rise { to { transform: translateY(-36px); opacity: 0; } }
  .overlay {
    position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
    background: var(--overlay); border-radius: 10px; flex-direction: column; gap: 10px; font-size: 20px;
  }
  .overlay.show { display: flex; }
  .overlay .big { font-size: 40px; font-weight: 800; }
  label.opt { font-size: 14px; display: flex; gap: 6px; align-items: center; }
  .lb {
    width: var(--panel-w); margin: 16px 0 32px; padding: 12px 16px;
    background: var(--board); border: 2px solid var(--line); border-radius: 10px;
  }
  .lb-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
  .lb-head h2 { margin: 0; font-size: 18px; }
  .lb-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
  .lb-tabs button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .lb table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
  .lb th, .lb td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--line); }
  .lb th:last-child, .lb td:last-child { text-align: right; }
  .lb tr.me td { font-weight: 700; background: var(--empty); }
  .lb .alias { opacity: .6; font-size: 12px; }
  .lb .status { font-size: 13px; opacity: .75; margin-top: 8px; }
  .lb input { font: inherit; font-size: 14px; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--btn-border); background: var(--btn); color: var(--ink); width: 150px; }
  #board.idle .cell { visibility: hidden; }
  #board.idle { min-height: 360px; min-width: min(92vw, 640px); }
  #ovLeave { display: none; }
  body.in-match #ovLeave { display: inline-block; }
  body.in-match #againBtn { display: none; }
  #lobby { gap: 12px; font-size: 18px; text-align: center; padding: 16px; }
  #lobbyTitle { font-size: 24px; font-weight: 800; }
  .lobby-mode, .lobby-msg { font-size: 14px; opacity: .8; }
  .lobby-link { display: flex; gap: 6px; }
  .lobby-link input { font: inherit; font-size: 13px; width: min(70vw, 380px); padding: 6px 8px; border-radius: 6px; border: 1px solid var(--btn-border); background: var(--btn); color: var(--ink); }
  .lobby-players { list-style: none; margin: 0; padding: 0; font-size: 16px; }
  .lobby-players li { margin: 4px 0; }
  .lobby-actions { display: flex; gap: 8px; }
  #readyBtn { font-weight: 700; }
  #readyBtn:disabled, button:disabled { opacity: .5; cursor: default; }
  #ovMatch { font-size: 22px; font-weight: 800; }
  .ov-seed { font-size: 12px; opacity: .6; user-select: text; -webkit-user-select: text; }
  #zenBtn[hidden] { display: none; }

  /* ---- Header, controls and stats ---- */
  :root { --panel-w: min(94vw, 1000px); --radius: 12px; --primary: #4a7cf0; --primary-ink: #fff; }
  :root[data-theme="dark"] { --primary: #6d9bff; --primary-ink: #0d1424; }
  .topbar {
    width: var(--panel-w); display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin: 14px 0 10px;
  }
  .topbar h1 { margin: 0; font-size: 28px; letter-spacing: .5px; }
  .topbar-right { display: flex; align-items: center; gap: 10px; position: relative; }
  .theme { display: flex; align-items: center; gap: 6px; font-size: 16px; }
  .howto summary {
    list-style: none; cursor: pointer; font-size: 14px; padding: 6px 12px; border-radius: 999px;
    border: 1px solid var(--btn-border); background: var(--btn);
  }
  .howto summary::-webkit-details-marker { display: none; }
  .howto[open] summary { background: var(--btn-hover); }
  .howto-body {
    position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; width: min(90vw, 460px);
    padding: 14px 16px; font-size: 14px; line-height: 1.5; text-align: left;
    background: var(--board); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: 0 10px 30px rgba(0,0,0,.18);
  }
  .howto-body p, .howto-body ul { margin: 0 0 8px; }
  .howto-body ul { padding-left: 18px; }
  .opt-hint { display: none; }
  body.blockers .opt-hint { display: block; }

  .panel {
    width: var(--panel-w); background: var(--board); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 10px 12px;
  }
  .controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
  .group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
  .group.secondary button { font-size: 13px; padding: 5px 10px; background: transparent; }
  .group.secondary button:hover:not(:disabled) { background: var(--btn-hover); }
  .field { display: flex; align-items: center; gap: 8px; font-size: 13px; opacity: .9; }
  button.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); font-weight: 700; }
  button.primary:hover:not(:disabled) { background: var(--primary); filter: brightness(1.08); }

  /* Toggle switch for Blockers */
  .switch { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
  .switch input { position: absolute; opacity: 0; pointer-events: none; }
  .switch .track {
    width: 36px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .2s;
  }
  .switch .track::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
    background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s;
  }
  .switch input:checked + .track { background: #ff9800; }
  .switch input:checked + .track::after { transform: translateX(16px); }
  .switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
  .switch input:disabled + .track { opacity: .5; }

  .stats { width: var(--panel-w); display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; margin-bottom: 10px; }
  .stat {
    display: flex; flex-direction: column; justify-content: center; min-width: 92px; padding: 6px 12px;
    background: var(--board); border: 1px solid var(--line); border-radius: 10px;
  }
  .stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; opacity: .6; }
  .stat .value { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.2; }
  .stat .value small { font-size: 13px; opacity: .6; margin-left: 2px; }
  #streakBox { display: none; }
  body.blockers #streakBox { display: contents; }
  .opponent-stat { display: none; }
  body.in-match .opponent-stat { display: flex; }
  #opponent { font-size: 16px; font-weight: 700; }
  .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
  .hint { font-size: 15px; padding: 8px 14px; }
  .hint small { opacity: .6; }
  @media (max-width: 640px) {
    .topbar h1 { font-size: 22px; }
    .controls { justify-content: center; }
    .stat { min-width: 0; flex: 1 1 28%; }
    .actions { margin-left: 0; flex: 1 1 100%; }
    .actions .hint { flex: 1; }
    .howto-body { position: fixed; top: 64px; left: 3vw; right: 3vw; width: auto; }
    #board { gap: 1px; padding: 4px; }
    .cell { border-radius: 3px; }
  }
  #undoBtn[hidden], #ovUndo[hidden], #solutionBtn[hidden], .replay-bar[hidden] { display: none; }
  .replay-bar {
    position: absolute; left: 50%; top: -18px; transform: translateX(-50%); z-index: 15;
    display: flex; align-items: center; gap: 8px; padding: 6px 10px; white-space: nowrap;
    background: var(--board); border: 1px solid var(--line); border-radius: 999px;
    box-shadow: 0 6px 18px rgba(0,0,0,.2); font-size: 14px; font-variant-numeric: tabular-nums;
  }
  .replay-bar button { font-size: 13px; padding: 3px 10px; }
  .cell.replay-click { background: #ffd54a !important; box-shadow: 0 0 0 3px #ff9800 inset; }
  .icon-btn { font-size: 16px; padding: 5px 9px; border-radius: 999px; line-height: 1; }
  .lb-filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
  .lb-filters .sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
  .lb-filters button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
  .lb-filters button.chip.active { background: #7c4dff; border-color: #7c4dff; color: #fff; }
  .lb-filters button.chip[data-flag="blockers"].active { background: #ff9800; border-color: #ff9800; }
  /* Tutorial */
  .tutorial-card { margin-bottom: 12px; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(74,124,240,.15); }
  .tutorial-card[hidden] { display: none; }
  .tut-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
  .tut-step { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; opacity: .6; }
  .tut-head button { font-size: 12px; padding: 3px 10px; background: transparent; }
  .tut-text { margin: 8px 0 4px; font-size: 17px; line-height: 1.5; }
  #tutPlay { margin-top: 8px; font-size: 16px; padding: 8px 18px; }
  #tutPlay[hidden], #tutSkip[hidden] { display: none; }
  body.tutorial .stats, body.tutorial .heatbar { display: none; }
  body.tutorial .timebar { visibility: hidden; }
  .cell.tut-target { animation: tutPulse 1.1s ease-in-out infinite; box-shadow: 0 0 0 3px var(--primary) inset; }
  .cell.tut-target::after { content: '👆'; position: absolute; bottom: -38%; right: -22%; font-size: calc(var(--cs) * .55); animation: tutTap 1.1s ease-in-out infinite; }
  .cell.tut-nudge { animation: shake .3s, tutPulse 1.1s ease-in-out infinite; }
  @keyframes tutPulse { 50% { background: #ffd54a; } }
  @keyframes tutTap { 50% { transform: translate(-3px, -4px); } }

  .player-bar { width: var(--panel-w); display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; margin: 0 0 14px; }
  .account-label { opacity: .65; font-size: 12px; margin-left: 5px; }
  #identityMessage { width: 100%; margin: 0; font-size: 13px; }
  #identityMessage:empty { display: none; }
  .google-button { min-height: 0; }
  .google-button[hidden], [hidden] { display: none !important; }
  body.in-match #googleAccountButton, body.in-match #signOutBtn { display: none; }
  #identityDialog { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 28px; border: 1px solid var(--btn-border); border-radius: 18px; background: var(--board); color: var(--ink); box-shadow: 0 20px 80px #0005; }
  #identityDialog::backdrop { background: #0009; backdrop-filter: blur(5px); }
  #identityForm { display: flex; flex-direction: column; gap: 12px; }
  #identityForm h2 { margin: 0; font-size: 26px; }
  #identityForm p { margin: 0; line-height: 1.5; }
  #identityForm label { font-weight: 600; margin-top: 8px; }
  #firstNickname { width: 100%; font: inherit; padding: 12px; color: var(--ink); background: var(--empty); border: 1px solid var(--btn-border); border-radius: 8px; user-select: text; }
  #identityForm button { padding: 11px; }
  .welcome-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .13em; color: var(--accent); }
  .welcome-divider { margin-top: 6px; text-align: center; font-size: 12px; opacity: .7; }
  .welcome-note { font-size: 12px; opacity: .65; }
  #nicknameMessage { color: var(--accent); font-size: 13px; }
  #nicknameMessage:empty { display: none; }
  #googleWelcomeButton { align-self: center; }
  #identityForm input:focus-visible, #identityForm button:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }

  .privacy-footer { margin: 20px 0; font-size: 12px; }
  .privacy-footer a { color: var(--ink); opacity: .65; }

  /* Viewport-first play surface. Secondary tools live in popovers/dialogs. */
  html { height: 100%; }
  body { height: 100dvh; min-height: 0; overflow: hidden; display: block; }
  .app-shell { height: 100%; max-width: 1240px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 28px max(8px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
  .topbar { width: 100%; flex: none; margin: 0; gap: 16px; min-height: 44px; }
  .brand { display: flex; align-items: baseline; gap: 16px; }
  .topbar h1 { font-size: 25px; letter-spacing: -.8px; white-space: nowrap; }
  .brand-dot { color: var(--primary); }
  .brand-note { font-size: 9px; letter-spacing: .17em; opacity: .4; }
  .topbar-right { gap: 8px; }
  .quiet-button, .topbar .icon-btn, .howto summary { background: transparent; border-color: transparent; }
  .quiet-button { font-size: 12px; padding: 7px 10px; }
  .quiet-button:hover, .topbar .icon-btn:hover, .howto summary:hover { background: var(--btn-hover); }
  .howto summary { width: 30px; height: 30px; text-align: center; padding: 4px; font-weight: 700; }
  .topbar .icon-btn { font-size: 15px; width: 32px; height: 32px; }
  .howto-body { top: 42px; max-height: calc(100dvh - 100px); overflow-y: auto; }
  .popover { position: relative; }
  .popover > summary { display: flex; align-items: center; justify-content: center; gap: 9px; cursor: pointer; list-style: none; border: 1px solid var(--btn-border); border-radius: 9px; min-height: 34px; padding: 6px 10px; font-size: 12px; background: var(--btn); }
  .popover > summary::-webkit-details-marker { display: none; }
  .popover > summary:hover, .popover[open] > summary { background: var(--btn-hover); }
  .popover > summary:focus-visible, .howto > summary:focus-visible { outline: 2px solid var(--primary); outline-offset: 3px; }
  .profile-menu > summary { border-color: var(--line); background: transparent; }
  #playerLabel { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .profile-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
  .chevron { opacity: .5; }
  .popover-body { position: absolute; right: 0; top: calc(100% + 10px); width: min(304px, calc(100vw - 32px)); z-index: 30; padding: 18px; border: 1px solid var(--btn-border); border-radius: 14px; background: var(--board); box-shadow: 0 16px 48px #0003; max-height: calc(100dvh - 96px); overflow-y: auto; }
  .popover-heading { font-size: 12px; font-weight: 700; margin: 0 0 6px; }
  .player-bar { display: flex; align-items: stretch; flex-direction: column; gap: 14px; margin: 0; }
  .account-label { font-weight: 400; font-size: 11px; }
  .profile-field { display: flex; flex-direction: column; gap: 7px; font-size: 12px; }
  .profile-field input { width: 100%; font: inherit; font-size: 14px; padding: 10px; border: 1px solid var(--btn-border); border-radius: 8px; background: var(--empty); color: var(--ink); user-select: text; }
  .google-button { color-scheme: light; background: transparent; width: 260px; max-width: 100%; }
  .google-button iframe { color-scheme: light; }
  #identityMessage { font-size: 12px; line-height: 1.5; }
  #googleUnavailable { margin: 0; line-height: 1.5; }
  .play-area { flex: 1; min-height: 0; display: flex; justify-content: center; }
  .game-stage { --chrome-width: 1000px; width: 100%; height: 100%; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; }
  .game-toolbar, .stats, .timebar, .heatbar, .tutorial-card { width: min(100%, var(--chrome-width)); flex: none; margin: 0; }
  .game-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 36px; }
  .mode-caption { display: flex; align-items: center; gap: 8px; font-size: 12px; opacity: .7; min-width: 0; }
  .mode-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--primary); flex: none; }
  #modeLabel { white-space: nowrap; }
  .toolbar-actions { display: flex; align-items: center; gap: 7px; }
  .toolbar-actions > button { font-size: 12px; min-height: 34px; padding: 7px 13px; }
  #challengeBtn { background: transparent; }
  .settings-menu > summary { letter-spacing: 2px; padding: 6px 10px; border-color: transparent; background: transparent; }
  .settings-body { display: flex; flex-direction: column; gap: 16px; }
  .settings-body .field { display: flex; justify-content: space-between; width: 100%; opacity: 1; }
  .settings-body .field select { max-width: 195px; font-size: 12px; }
  .settings-body .switch { justify-content: space-between; font-size: 13px; }
  .settings-body .switch input { position: absolute; }
  .settings-body > button { text-align: left; border: none; background: transparent; padding: 3px 0; font-size: 13px; }
  .settings-body > button:hover { color: var(--primary); }
  .menu-divider { height: 1px; background: var(--line); margin: 0 -2px; }
  .timebar { height: 4px; border-radius: 4px; }
  .heatbar { height: 12px; }
  .heatbar span { font-size: 9px; }
  .board-space { flex: 1; min-height: 0; width: 100%; display: grid; place-items: center; }
  .wrap { flex: none; max-width: 100%; }
  #board.idle { min-height: 0; min-width: 0; }
  .stats { display: flex; flex-wrap: nowrap; justify-content: flex-start; align-items: center; gap: 0; min-height: 46px; padding: 4px 0; }
  .stat { flex: none; min-width: 82px; padding: 0 18px; border: 0; border-right: 1px solid var(--line); border-radius: 0; background: transparent; }
  .stat:first-child { padding-left: 0; }
  .stat .label { font-size: 9px; letter-spacing: .9px; line-height: 1.5; white-space: nowrap; }
  .stat .value { font-size: 23px; letter-spacing: -.5px; }
  .stat .value small { font-size: 12px; }
  .actions { flex: none; margin-left: auto; }
  .hint { padding: 7px 11px; font-size: 12px; background: transparent; }
  .app-footer { flex: none; display: flex; align-items: center; justify-content: space-between; font-size: 10px; opacity: .4; line-height: 16px; }
  .app-footer a { color: inherit; text-decoration: none; }
  #leaderboardDialog { width: min(600px, calc(100vw - 28px)); max-height: calc(100dvh - 40px); padding: 22px; background: var(--board); color: var(--ink); border: 1px solid var(--btn-border); border-radius: 16px; box-shadow: 0 20px 80px #0005; }
  #leaderboardDialog::backdrop { background: #0008; backdrop-filter: blur(5px); }
  #leaderboardDialog .lb { width: 100%; margin: 0; padding: 0; background: transparent; border: 0; }
  .dialog-close { order: 3; border: 0; padding: 2px 8px; font-size: 24px; background: transparent; margin-left: auto; }
  .overlay { overflow-y: auto; padding: 14px; }
  .overlay .big { line-height: 1; }
  .tutorial-card { padding: 12px 16px; }
  .tut-text { font-size: 15px; }
  body.tutorial .timebar { display: none; }
  @media (max-width: 760px) {
    .app-shell { padding-left: 16px; padding-right: 16px; gap: 10px; }
    .brand-note { display: none; }
    .stat { padding: 0 12px; }
  }
  @media (max-width: 640px) {
    .app-shell { padding-left: 12px; padding-right: 12px; gap: 8px; }
    .topbar { min-height: 36px; gap: 8px; }
    .topbar h1 { font-size: 22px; }
    .topbar-right { gap: 2px; }
    .nav-label { display: none; }
    #leaderboardBtn { font-size: 18px; padding: 4px 7px; }
    #playerLabel { max-width: 78px; font-size: 11px; }
    .profile-menu > summary { gap: 6px; min-height: 30px; padding: 5px 8px; }
    .profile-dot { width: 5px; height: 5px; }
    .game-stage { gap: 8px; }
    .game-toolbar { gap: 6px; min-height: 32px; }
    .toolbar-actions { gap: 4px; }
    .toolbar-actions > button { padding: 6px 9px; min-height: 32px; font-size: 11px; }
    .mode-caption { font-size: 10px; gap: 5px; }
    #modeLabel { max-width: 105px; overflow: hidden; text-overflow: ellipsis; }
    .stats { min-height: 42px; }
    .stat { flex: 1 1 0; min-width: 0; padding: 0 7px; }
    .stat .label { font-size: 8px; letter-spacing: .3px; }
    .stat .value { font-size: 20px; }
    .stat .value small { font-size: 10px; }
    .actions { flex: none; gap: 4px; margin-left: 10px; }
    .actions .hint { flex: none; font-size: 11px; padding: 6px; }
    #opponent { font-size: 11px; overflow: hidden; text-overflow: ellipsis; max-width: 64px; }
    .howto-body { left: 12px; right: 12px; width: auto; top: 58px; }
    .settings-body { width: min(304px, calc(100vw - 32px)); }
    .app-footer { font-size: 9px; }
  }
  @media (max-height: 500px) {
    .app-shell { padding-top: 6px; padding-bottom: 4px; gap: 4px; }
    .topbar { min-height: 30px; }
    .topbar h1 { font-size: 21px; }
    .game-stage { gap: 5px; }
    .game-toolbar { min-height: 30px; }
    .toolbar-actions > button { min-height: 28px; padding-top: 4px; padding-bottom: 4px; }
    .stats { min-height: 34px; padding: 0; }
    .stat .value { font-size: 18px; }
    .app-footer { display: none; }
    .tutorial-card { padding: 6px 12px; }
    .tut-text { font-size: 12px; margin: 4px 0; }
  }

  /* Wide screens keep live scores and standings alongside the board. */
  .sidebar-title { display: none; }
  .lb-table-scroll { min-height: 0; overflow-y: auto; }
  .game-sidebar { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 16px; }
  .game-sidebar .stats, .game-sidebar .lb { width: 100%; margin: 0; padding: 20px; background: var(--board); border: 1px solid var(--line); border-radius: 16px; }
  .game-sidebar .stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 12px; min-height: 0; }
  .game-sidebar .sidebar-title { display: block; grid-column: 1 / -1; margin: 0; font-size: 10px; text-transform: uppercase; letter-spacing: .14em; font-weight: 600; opacity: .5; }
  .game-sidebar .stat { min-width: 0; padding: 0; border: 0; }
  .game-sidebar .stat:first-of-type { grid-column: 1 / -1; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
  .game-sidebar .stat:first-of-type .value { font-size: 48px; letter-spacing: -1.5px; }
  .game-sidebar .stat:first-of-type .value small { font-size: 15px; letter-spacing: 0; }
  .game-sidebar .stat .value { font-size: 27px; }
  .game-sidebar .stat .label { font-size: 9px; }
  .game-sidebar .opponent-stat { grid-column: 1 / -1; }
  .game-sidebar #opponent { max-width: 100%; font-size: 16px; }
  .game-sidebar .actions { grid-column: 1 / -1; display: flex; gap: 8px; width: 100%; margin: 0; }
  .game-sidebar .actions button { flex: 1; }
  .game-sidebar .lb { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 14px; }
  .game-sidebar .lb-head { flex: none; margin: 0; display: flex; flex-direction: column; align-items: stretch; gap: 16px; }
  .game-sidebar .lb-head h2 { font-size: 16px; }
  .game-sidebar .dialog-close { display: none; }
  .game-sidebar .lb-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .game-sidebar .lb-filters button { font-size: 11px; padding: 7px 5px; }
  .game-sidebar .lb-filters .sep { display: none; }
  .game-sidebar .lb-filters .chip { grid-column: 1 / -1; }
  .game-sidebar .lb table { table-layout: fixed; font-size: 12px; }
  .game-sidebar .lb th, .game-sidebar .lb td { padding: 8px 4px; }
  .game-sidebar .lb th:first-child { width: 26px; }
  .game-sidebar .lb th:last-child { width: 48px; }
  .game-sidebar .lb td:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .game-sidebar .lb .status { flex: none; margin: auto 0 0; padding-top: 12px; border-top: 1px solid var(--line); font-size: 11px; line-height: 1.5; }
  @media (min-width: 960px) {
    .app-shell { max-width: 1640px; }
    .play-area { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 28px; }
    .game-stage { min-width: 0; align-items: flex-end; }
    .board-space { justify-items: end; }
  }
  @media (min-width: 960px) and (max-width: 1199px) {
    .play-area { grid-template-columns: minmax(0, 1fr) 244px; gap: 20px; }
    .game-sidebar { gap: 12px; }
    .game-sidebar .stats, .game-sidebar .lb { padding: 16px; }
  }
  @media (min-width: 960px) and (max-height: 640px) {
    .game-sidebar { gap: 10px; }
    .game-sidebar .stats, .game-sidebar .lb { padding: 12px 16px; }
    .game-sidebar .stats { gap: 10px 12px; }
    .game-sidebar .stat:first-of-type { padding-bottom: 8px; }
    .game-sidebar .stat:first-of-type .value { font-size: 32px; }
    .game-sidebar .stat .value { font-size: 20px; }
    .game-sidebar .lb { gap: 8px; }
    .game-sidebar .lb-head { gap: 8px; }
    .game-sidebar .lb-filters button { padding: 5px; }
  }
