:root,
html[data-theme="light"] {
  --page: #d8dde6;
  --bg: #eef0f4;
  --hero-from: #e4eaf3;
  --hero-to: #eef0f4;
  --hero-glow: rgba(90, 140, 220, 0.18);
  --surface: #ffffff;
  --surface-2: #f4f6fa;
  --text: #2c3a4f;
  --muted: #8b95a5;
  --label: #9aa3b2;
  --icon: #5b6b86;
  --accent: #3b6fe8;
  --accent-soft: #d7e5ff;
  --user: #2f62d6;
  --given: #1c1c1c;
  --error: #e4453a;
  --error-bg: #fdecee;
  --select: #b7d8f6;
  --peer: #e7eef6;
  --same: #cfe4f6;
  --grid: #2b3848;
  --grid-thin: #d3d8e0;
  --board: #ffffff;
  --tap: #eef1f6;
  --overlay: rgba(248, 250, 252, 0.88);
  --ghost-ring: #dbe3ef;
  --shadow: 0 8px 28px rgba(40, 55, 80, 0.08);
  --daily-from: #3a8dff;
  --daily-to: #1f63e6;
  --win: #2f9e5d;
  --warn: #ff7a1a;
  --hint: #1aa36a;
  --separator: rgba(60, 60, 67, 0.12);
  --destructive: #e6453a;
  color-scheme: light;
}

html[data-theme="dark"] {
  --page: #101218;
  --bg: #161922;
  --hero-from: #1b2030;
  --hero-to: #161922;
  --hero-glow: rgba(90, 130, 220, 0.16);
  --surface: #232833;
  --surface-2: #2b3140;
  --text: #e4e8f2;
  --muted: #8d95a8;
  --label: #7e8798;
  --icon: #b3bccb;
  --accent: #7aa2ff;
  --accent-soft: #2a3b63;
  --user: #8bb4ff;
  --given: #eef1f6;
  --error: #ff7a7a;
  --error-bg: #3a2428;
  --select: #2c4c7c;
  --peer: #222836;
  --same: #314e74;
  --grid: #c9d1de;
  --grid-thin: #3a4254;
  --board: #1c212c;
  --tap: #2c3342;
  --overlay: rgba(16, 18, 24, 0.86);
  --ghost-ring: #3a4356;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --daily-from: #4b86f0;
  --daily-to: #2c5ed4;
  --win: #5dcc8a;
  --warn: #ffb060;
  --hint: #5dcc8a;
  --separator: rgba(84, 84, 88, 0.55);
  --destructive: #ff6961;
  color-scheme: dark;
}

html[data-theme="paper"] {
  --page: #d9d6c4;
  --bg: #ece9d6;
  --hero-from: #e7e3cc;
  --hero-to: #ece9d6;
  --hero-glow: rgba(150, 160, 90, 0.18);
  --surface: #f6f2e3;
  --surface-2: #efe9d4;
  --text: #3b382c;
  --muted: #8a8470;
  --label: #9a947e;
  --icon: #6a6554;
  --accent: #5c7a45;
  --accent-soft: #d5e2c4;
  --user: #4d6b38;
  --given: #2f2c22;
  --error: #c45b4a;
  --error-bg: #f3e0d6;
  --select: #d5e4bf;
  --peer: #eee8d4;
  --same: #e0eac8;
  --grid: #5a5646;
  --grid-thin: #d4cdb4;
  --board: #f8f4e6;
  --tap: #ebe4cf;
  --overlay: rgba(236, 233, 214, 0.9);
  --ghost-ring: #d4cdb4;
  --shadow: 0 8px 28px rgba(80, 70, 40, 0.1);
  --daily-from: #7a9a58;
  --daily-to: #5a7a3e;
  --win: #4f7a3a;
  --warn: #c47a32;
  --hint: #4f7a3a;
  --separator: rgba(90, 86, 70, 0.18);
  --destructive: #c45b4a;
  color-scheme: light;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background: var(--page);
  color: var(--text);
  transition: background-color 0.25s ease, color 0.25s ease;
}

html.fs,
html.immersive,
html.fs body,
html.immersive body {
  height: 100%;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

body {
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  background: var(--surface);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 20px 60px rgba(30, 40, 60, 0.12);
}

@media (max-width: 480px) {
  body {
    background: var(--bg);
  }
  #app {
    max-width: none;
    box-shadow: none;
  }
}

html.fs body,
html.immersive body {
  background: var(--bg);
}

html.fs #app,
html.immersive #app,
#app:fullscreen,
#app:-webkit-full-screen {
  max-width: none;
  width: 100%;
  height: 100%;
  min-height: 100%;
  max-height: 100%;
  box-shadow: none;
  overflow: hidden;
}

#app:fullscreen,
#app:-webkit-full-screen {
  background: var(--surface);
}

#app:has(#game.active) {
  height: 100svh;
  max-height: 100svh;
  min-height: 0;
  overflow: hidden;
}

html.fs #app:has(#game.active),
html.immersive #app:has(#game.active),
#app:fullscreen:has(#game.active),
#app:-webkit-full-screen:has(#game.active) {
  height: 100%;
  max-height: 100%;
}

html.fs #home.active,
html.immersive #home.active {
  width: 100%;
  max-width: 480px;
  margin-inline: auto;
  max-height: 100%;
  overflow: auto;
}

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

#home.active {
  min-height: 100%;
  flex: 1;
}

/* Home */
#home {
  background: var(--bg);
}

.home-bar {
  position: relative;
  z-index: 2;
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  margin: -4px -6px 8px 0;
}

.home-hero {
  position: relative;
  padding: calc(18px + var(--safe-top)) 18px 22px;
  background:
    radial-gradient(1200px 280px at 50% -40px, var(--hero-glow), transparent 60%),
    linear-gradient(180deg, var(--hero-from) 0%, var(--hero-to) 100%);
  overflow: hidden;
}

.hero-grid {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(80, 100, 140, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(80, 100, 140, 0.18) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, #000 30%, transparent 95%);
  pointer-events: none;
}

.hero-num {
  position: absolute;
  color: rgba(90, 110, 150, 0.18);
  font-weight: 700;
  font-size: 42px;
  pointer-events: none;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  padding: 6px;
  gap: 2px;
}

.brand-mark i {
  background: var(--accent);
  border-radius: 1px;
}

.brand-mark i:nth-child(1),
.brand-mark i:nth-child(5),
.brand-mark i:nth-child(9) {
  background: var(--text);
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.45px;
  color: var(--text);
}

.brand span {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.cards {
  position: relative;
  display: flex;
  gap: 12px;
}

.daily-card {
  flex: 1.15;
  min-height: 168px;
  border-radius: 18px;
  padding: 18px 16px 16px;
  color: #fff;
  text-align: center;
  background: linear-gradient(180deg, var(--daily-from) 0%, var(--daily-to) 100%);
  box-shadow: 0 10px 24px rgba(40, 80, 40, 0.22);
  position: relative;
}

.daily-card .cup {
  width: 54px;
  height: 54px;
  margin: 2px auto 8px;
}

.daily-card h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.daily-card .date {
  margin: 4px 0 12px;
  font-size: 13px;
  opacity: 0.92;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  color: #fff;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
  position: relative;
}

.pill .dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  background: #ff4d4f;
  color: #fff;
  border-radius: 50%;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #2b74ea;
}

.daily-card.done {
  background: linear-gradient(180deg, #6aa4f5 0%, #3d78d6 100%);
}

.side-card {
  flex: 0 0 34%;
  min-width: 0;
  min-height: 168px;
  border-radius: 18px;
  background: var(--surface-2);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 8px;
}

.side-card strong {
  font-size: 13px;
  color: var(--text);
  text-align: center;
  line-height: 1.25;
}

.side-card .soon {
  font-size: 12px;
  background: var(--tap);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
}

.home-body {
  padding: 8px 16px calc(24px + var(--safe-bot));
}

.week {
  text-align: center;
  padding: 10px 0 16px;
}

.week h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 650;
}

.week h3 b {
  color: var(--warn);
  font-weight: 700;
}

.week h3 b.ok {
  color: var(--win);
}

.week p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.diff-list {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
}

.resume-card {
  display: none;
  width: 100%;
  background: var(--surface);
  border-radius: 14px;
  min-height: 56px;
  padding: 10px 14px;
  margin-bottom: 10px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: var(--shadow);
}

.resume-card.show {
  display: flex;
}

.resume-card .go {
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 650;
}

.resume-card strong {
  display: block;
  font-size: 15px;
}

.resume-card small {
  color: var(--muted);
  font-size: 12px;
}

.home-stats {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: -6px 0 12px;
}

.diff-btn {
  background: transparent;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  color: var(--accent);
  font-weight: 600;
  position: relative;
  overflow: hidden;
  border-bottom: 1px solid var(--separator);
}

.diff-btn:last-child {
  border-bottom: 0;
}

.diff-btn:active {
  background: var(--tap);
}

/* Game */
#game {
  background: var(--surface);
}

#game.active {
  flex: 1;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.game-top {
  padding: calc(8px + var(--safe-top)) 10px 4px;
}

.nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 44px;
}

.nav-left,
.nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-right {
  justify-content: flex-end;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--icon);
}

.icon-btn:active {
  background: var(--tap);
  transform: scale(0.92);
}

.icon-btn.on {
  color: var(--accent);
}

.nav-title {
  font-size: 17px;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.2px;
}

.stats {
  display: grid;
  grid-template-columns: 1.1fr 0.75fr 0.85fr 1.2fr;
  gap: 2px;
  padding: 4px 4px 6px;
  text-align: center;
}

.stat .k {
  font-size: 11px;
  color: var(--label);
}

.stat .v {
  margin-top: 3px;
  font-size: 16px;
  font-weight: 650;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 22px;
}

.stat .v .star {
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.stat .v .star.on {
  color: #e6b325;
}

.pause-btn {
  width: 26px;
  height: 26px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}

.game-top,
.board-area,
.tools,
.pad {
  width: min(100%, var(--play-w, 100%));
  margin-inline: auto;
}

.board-area {
  padding: 2px 10px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
}

.board-fit {
  width: 100%;
  aspect-ratio: 1;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  grid-template-rows: 16px minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  --cell: 36px;
}

.col-labs {
  display: grid;
  grid-template-columns: 16px repeat(9, 1fr);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.board-mid {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: stretch;
  min-height: 0;
  min-width: 0;
}

.row-labs {
  display: grid;
  grid-template-rows: repeat(9, 1fr);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.row-labs span,
.col-labs span {
  display: grid;
  place-items: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--grid);
  background: var(--board);
  user-select: none;
}

.cell {
  position: relative;
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  display: grid;
  place-items: center;
  font-size: clamp(16px, calc(var(--cell) * 0.52), 42px);
  font-weight: 600;
  color: var(--given);
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 73) {
  border-bottom: 0;
}

.cell:nth-child(3n) {
  border-right: 2px solid var(--grid);
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--grid);
}

.cell.peer {
  background: var(--peer);
}

.cell.same {
  background: var(--same);
}

.cell.sel {
  background: var(--select);
}

.cell.user {
  color: var(--user);
  font-weight: 650;
}

.cell.wrong {
  color: var(--error);
  background: var(--error-bg);
}

.cell.flash {
  animation: flash 0.45s ease;
}

.cell.hinted {
  color: var(--hint);
}

.cell.pop {
  animation: pop 0.45s ease;
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.08);
    background: var(--accent-soft);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes flash {
  0%,
  100% {
    background: var(--select);
  }
  35% {
    background: #ffc9c9;
  }
}

.notes {
  position: absolute;
  inset: 2px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
  pointer-events: none;
}

.notes i {
  display: grid;
  place-items: center;
  font-size: clamp(7px, calc(var(--cell) * 0.22), 13px);
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
  line-height: 1;
}

.tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 4px 6px 2px;
  gap: 2px;
  flex: 0 0 auto;
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--icon);
  min-height: 44px;
  padding: 6px 0;
  position: relative;
}

.tool:active {
  transform: scale(0.94);
  opacity: 0.72;
}

.tool svg {
  width: 28px;
  height: 28px;
}

.tool span {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.tool.on {
  color: var(--accent);
}

.tool.on span {
  color: var(--accent);
}

.badge {
  position: absolute;
  top: 0;
  right: 18%;
  background: #8b95a5;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 6px;
}

.tool.on .badge {
  background: var(--accent);
}

.hint-badge {
  position: absolute;
  top: 0;
  right: 18%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.pad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
  padding: 6px 12px 8px;
  flex: 0 0 auto;
  min-height: 52px;
  align-content: center;
}

.ad-slot {
  width: 100%;
  flex: 1 1 auto;
  min-height: 88px;
  margin-top: 4px;
  padding: 0 10px calc(10px + var(--safe-bot));
  display: flex;
  align-items: flex-end;
  box-sizing: border-box;
}

.ad-card {
  width: min(100%, var(--play-w, 100%));
  margin-inline: auto;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 0 0 1px var(--ghost-ring) inset;
  height: 76px;
  min-height: 76px;
  overflow: hidden;
}

.ad-thumb {
  width: 72px;
  height: 72px;
  min-height: 72px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--hero-from), var(--accent-soft));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 3px;
  padding: 8px;
}

.ad-thumb i {
  display: block;
  border-radius: 2px;
  background: var(--accent-soft);
}

.ad-thumb i:nth-child(1),
.ad-thumb i:nth-child(5),
.ad-thumb i:nth-child(9) {
  background: var(--accent);
  opacity: 0.55;
}

.ad-copy {
  min-width: 0;
  padding-right: 4px;
}

.ad-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--label);
}

.ad-title {
  margin-top: 2px;
  font-size: 14px;
  font-weight: 650;
  color: var(--text);
  line-height: 1.25;
}

.ad-sub {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.3;
}

.num {
  background: var(--surface-2);
  border-radius: 10px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.num b {
  font-size: 22px;
  font-weight: 650;
  color: var(--accent);
}

.num small {
  font-size: 11px;
  color: var(--muted);
}

.num.gone {
  opacity: 0;
  pointer-events: none;
}

.num:active {
  transform: scale(0.96);
  background: var(--tap);
}

.num.picked {
  outline: 2px solid var(--accent);
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 160px;
  transform: translateX(-50%) translateY(8px);
  background: rgba(40, 48, 62, 0.92);
  color: #fff;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 10px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  white-space: nowrap;
  z-index: 5;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 6;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.overlay.show {
  display: flex;
}

.overlay-card {
  width: min(100%, 300px);
  background: var(--surface);
  border-radius: 14px;
  padding: 22px 16px 16px;
  box-shadow: var(--shadow);
}

.overlay h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.3px;
  color: var(--text);
}

.overlay p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.35;
  font-size: 13px;
}

.overlay .meta {
  width: 100%;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px 8px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  margin-bottom: 16px;
}

.overlay .meta div {
  font-size: 12px;
  color: var(--muted);
}

.overlay .meta b {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  color: var(--text);
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.btn {
  min-height: 44px;
  border-radius: 12px;
  font-weight: 650;
  font-size: 17px;
}

.btn:active {
  transform: scale(0.98);
  opacity: 0.86;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: var(--surface-2);
  color: var(--accent);
}

.btn.destructive {
  background: transparent;
  color: var(--destructive);
}

.loading {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: var(--overlay);
  z-index: 8;
}

.loading.show {
  display: grid;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #d7e3f7;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (min-height: 780px) {
  .num {
    min-height: 52px;
  }
}

@media (max-height: 560px) {
  .game-top {
    padding-top: 2px;
    padding-bottom: 0;
  }
  .nav {
    min-height: 32px;
  }
  .icon-btn {
    width: 36px;
    height: 36px;
  }
  .stats {
    padding: 0 4px 4px;
  }
  .stat .k {
    font-size: 10px;
  }
  .tool {
    min-height: 36px;
    padding: 2px 0;
  }
  .tool span {
    font-size: 9px;
  }
  .tool svg {
    width: 22px;
    height: 22px;
  }
  .pad {
    padding: 2px 10px calc(6px + var(--safe-bot));
  }
  .ad-slot {
    display: none;
  }
  .num {
    min-height: 36px;
  }
  .num b {
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@media (prefers-contrast: more) {
  .grid {
    border-width: 3px;
  }
  .cell {
    border-color: var(--text);
  }
  .diff-btn,
  .btn.ghost,
  .theme-opt {
    box-shadow: 0 0 0 1px var(--text) inset;
  }
  .nav-title,
  .brand h1,
  .cell {
    font-weight: 700;
  }
}

.sheet {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 9;
}

.sheet.show {
  display: block;
}

.sheet-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
}

.sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + var(--safe-bot));
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.12);
}

.sheet-handle {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--muted);
  opacity: 0.4;
  margin: 6px auto 12px;
}

.sheet-card h3 {
  margin: 0 0 14px;
  text-align: center;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.3px;
}

.theme-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.theme-opt {
  border-radius: 14px;
  padding: 12px 8px 10px;
  text-align: center;
  background: var(--surface-2);
  box-shadow: 0 0 0 1px var(--ghost-ring) inset;
}

.theme-opt.on {
  box-shadow: 0 0 0 2px var(--accent) inset;
}

.theme-opt .swatch {
  height: 36px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.theme-opt .swatch.system {
  background: linear-gradient(90deg, #f4f6fa 50%, #1c212c 50%);
}

.theme-opt .swatch.light {
  background: linear-gradient(180deg, #f4f6fa, #e8eef8);
}

.theme-opt .swatch.dark {
  background: linear-gradient(180deg, #2a3140, #171b24);
}

.theme-opt .swatch.paper {
  background: linear-gradient(180deg, #f4f0de, #dfe6c8);
}

.theme-opt span {
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--separator);
}

.setting-row:last-of-type {
  border-bottom: 0;
}

.setting-row .k {
  font-size: 15px;
  font-weight: 600;
}

.setting-row .d {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.toggle {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--ghost-ring);
  position: relative;
  flex-shrink: 0;
}

.toggle.on {
  background: var(--accent);
}

.toggle i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}

.toggle.on i {
  transform: translateX(18px);
}

.sheet-actions {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
