:root {
  color-scheme: dark;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, sans-serif;
  font-synthesis: none;
  --bg: #10121a;
  --surface: #191c28;
  --surface-2: #222638;
  --line: #30364d;
  --text: #f7f7fb;
  --muted: #a7aec4;
  --accent: #85f2c5;
  --accent-2: #a9a0ff;
  --danger: #ff7385;
  --warning: #ffb15f;
  --lead: #57efbd;
  --trail: #ff6f82;
  --even: #8290b3;
  --quiet: #858da5;
  --accent-ink: #09251c;
  --backdrop: #090a10cc;
  --game-zone-glow: #29304a;
  --rules-bg: #10121ad9;
  --countdown-bg: #10121ae8;
  --game-overlay-bg: #10121af2;
  --match-board-bg: #0d1019aa;
  --tug-track: #0b0d14;
  --tug-line: #3a4057;
  --focus-ring: #fff;
  --stacker-scene-glow: #2c3450;
  --stacker-scene-edge: #11141f;
  --stacker-chip-bg: #0c0f18bb;
  --stacker-chip-line: #ffffff24;
  --radius: 20px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f7f5;
    --surface: #fff;
    --surface-2: #e5eeea;
    --line: #aebfb7;
    --text: #14211b;
    --muted: #4d6259;
    --accent: #087657;
    --accent-2: #5c50b5;
    --danger: #b4233c;
    --warning: #9a4b00;
    --lead: #087657;
    --trail: #b4233c;
    --even: #59677b;
    --quiet: #596b63;
    --accent-ink: #fff;
    --backdrop: #17201dcc;
    --game-zone-glow: #dce9e4;
    --rules-bg: #fffffff2;
    --countdown-bg: #f3f7f5f2;
    --game-overlay-bg: #f3f7f5f2;
    --match-board-bg: #dfe9e5cc;
    --tug-track: #dbe5e1;
    --tug-line: #80938b;
    --focus-ring: #14211b;
    --stacker-scene-glow: #dce9e4;
    --stacker-scene-edge: #bfcfc8;
    --stacker-chip-bg: #ffffffd9;
    --stacker-chip-line: #14211b33;
  }
}

* { box-sizing: border-box; }

html, body { width: 100%; margin: 0; min-height: 100%; overflow-x: hidden; background: var(--bg); color: var(--text); }
body { min-width: 320px; min-height: 100dvh; }
button, input, textarea { font: inherit; }
button { color: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.qr-unavailable { display: grid; place-items: center; background: var(--surface-2) !important; color: var(--text); }
.qr-fallback { margin: 0; padding: 8px; font-size: 13px; font-weight: 700; line-height: 1.35; text-align: center; }

#app { min-height: 100dvh; }
.storage-warning { padding: 8px 14px; border-bottom: 1px solid var(--danger); background: color-mix(in srgb, var(--danger), transparent 86%); color: var(--text); text-align: center; font-size: 12px; }

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  width: 100%;
  max-width: 100vw;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid color-mix(in srgb, var(--line), transparent 22%);
  background: color-mix(in srgb, var(--bg), transparent 7%);
  backdrop-filter: blur(16px);
}

.brand-button, .header-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.header-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border-radius: 11px;
}

.brand-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 12px;
  color: var(--accent);
}

.brand-button:hover { background: var(--surface-2); }
.brand-mark { width: 27px; height: 27px; }

.nickname-button {
  max-width: min(30vw, 150px);
  overflow: hidden;
  padding: 7px 8px;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nickname-button span:last-child { overflow: hidden; text-overflow: ellipsis; }

.header-spacer { flex: 1; min-width: 0; }
.header-button { padding: 7px 5px; color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: .04em; }
.header-button:hover, .header-button:focus-visible { background: var(--surface-2); color: var(--text); }
.header-icon { display: inline-grid; flex: 0 0 17px; width: 17px; height: 17px; place-items: center; }
.header-icon svg { width: 100%; height: 100%; }
.version-label { display: inline-flex; align-items: center; gap: 4px; padding: 5px 2px; border: 0; background: transparent; color: var(--quiet); cursor: pointer; font-size: 11px; white-space: nowrap; }
.version-label:hover, .version-label:focus-visible { color: var(--text); }
.version-label[data-unread="true"] .header-icon { color: var(--danger); }
.version-label:disabled { cursor: wait; }
.version-label .header-icon { width: 14px; height: 14px; }

.language-picker { position: relative; display: inline-flex; }
.language-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 7px);
  right: 0;
  width: max-content;
  min-width: 150px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 16px 42px #0009;
}
.language-menu button {
  display: grid;
  width: 100%;
  min-height: 42px;
  grid-template-columns: 35px 1fr;
  align-items: center;
  padding: 7px 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.language-menu button:hover, .language-menu button:focus-visible { outline: none; background: var(--surface-2); }
.language-menu button[aria-selected="true"] { color: var(--accent); }
.language-menu strong { font-size: 12px; letter-spacing: .05em; }
.language-menu span { color: var(--text); font-size: 13px; }

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  align-items: safe center;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--backdrop);
}

.modal-card {
  width: min(100%, 410px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 80px #0008;
}

.modal-card h2 { margin: 0 0 16px; font-size: 20px; }
.version-dialog { position: relative; max-height: min(78dvh, 680px); overflow: auto; }
.version-close { position: sticky; z-index: 1; top: 0; float: right; display: grid; width: 34px; height: 34px; margin: -8px -8px 4px 10px; place-items: center; border: 1px solid var(--line); border-radius: 50%; background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 23px; line-height: 1; }
.version-json { clear: both; overflow-wrap: anywhere; }
.version-field { margin-top: 16px; }
.version-object.depth-0 > .version-field:first-child { margin-top: 0; }
.version-key { display: block; margin: 0 0 8px; color: var(--text); }
.version-object.depth-0 > .version-field > .version-key { color: var(--accent); font-size: 23px; }
.version-object.depth-1 > .version-field > .version-key { font-size: 15px; }
.version-array { display: grid; gap: 7px; margin: 0; padding-left: 21px; color: var(--muted); font-size: 13px; line-height: 1.45; }
.version-value { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.modal-card input[type="text"] { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); }
.disclaimer { margin: 13px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.confirm-row { display: flex; gap: 9px; align-items: flex-start; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.action-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 750;
}
.action-button.primary { border-color: transparent; background: var(--accent); color: var(--accent-ink); }
.action-button.danger { border-color: color-mix(in srgb, var(--danger), transparent 50%); color: var(--danger); }
.action-button:disabled { cursor: not-allowed; opacity: .45; }

.empty-state { padding: 28px 16px; color: var(--muted); text-align: center; }

@media (max-width: 370px) {
  .app-header { gap: 3px; padding-inline: 7px; }
  .nickname-button { max-width: 82px; padding-inline: 4px; }
  .header-button { padding-inline: 3px; font-size: 11px; }
  .version-label { font-size: 10px; }
  .version-label .header-icon { display: none; }
}

@media (max-width: 480px) {
  .version-label .header-icon { display: none; }
}
