/* Letter Peel — styles */
@font-face {
  font-family: 'Anton';
  src: url('../fonts/Anton-Regular.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Outfit';
  src: url('../fonts/outfit-latin-wght-normal.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f6f2ec;
  --bg-2: #efe9e1;
  --card: #ffffff;
  --ink: #1f1b17;
  --ink-2: #5d564e;
  --ink-3: #8e867d;
  --line: rgba(31, 27, 23, 0.1);
  --line-strong: rgba(31, 27, 23, 0.2);
  --accent: #f47c1f;
  --accent-ink: #1d1206;
  --accent-soft: #fde7d3;
  --accent-deep: #b75d17;
  --good: #1e9e57;
  --bad: #e5484d;
  --gold: #e7a817;
  --shadow-lg: 0 24px 60px -24px rgba(20, 14, 8, 0.45), 0 2px 8px rgba(20, 14, 8, 0.08);
  --font: 'Outfit', ui-rounded, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --board-w: 100%;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #151311; --bg-2: #1d1a17; --card: #23201c; --ink: #f4efe9; --ink-2: #bdb4aa; --ink-3: #8b8279;
    --line: rgba(255, 255, 255, 0.1); --line-strong: rgba(255, 255, 255, 0.2);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.8), 0 2px 8px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #151311; --bg-2: #1d1a17; --card: #23201c; --ink: #f4efe9; --ink-2: #bdb4aa; --ink-3: #8b8279;
  --line: rgba(255, 255, 255, 0.1); --line-strong: rgba(255, 255, 255, 0.2);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, 0.8), 0 2px 8px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 520px at 50% -180px, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  transition: background-color 0.4s;
}
body.modal-open { overscroll-behavior: contain; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 5px; margin: 0 1px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 6px;
  font: 600 12px/1.4 var(--font); text-align: center; background: var(--bg-2);
}

/* ---------------- layout ---------------- */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 1180px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(16px, env(safe-area-inset-left));
}
.topbar {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 12px; padding: 12px 0 10px;
  width: min(100%, max(var(--board-w), 680px)); margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; min-width: 0; }
.logo { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.18)); }
.logo-skin { fill: var(--accent); transition: fill 0.4s; }
.logo-flap { fill: var(--accent-soft); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.05; }
.brand-meta { font-size: 13px; color: var(--ink-2); display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.meta-short { display: none; }
.meta-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.top-actions { display: flex; gap: 4px; flex: none; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink); transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--line); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible, .btn:focus-visible, .tile:focus-visible, .gcard:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; stroke: none; }

.banner {
  flex: 1 0 100%; max-width: min(100%, var(--board-w)); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 8px 12px; border-radius: 12px; font-size: 14px;
  background: color-mix(in srgb, var(--accent) 14%, var(--card)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.link-btn { border: 0; background: none; padding: 2px 4px; font-weight: 650; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }

.stage { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 2px 0 6px; }
.board-wrap {
  position: relative; width: 100%; aspect-ratio: 4 / 3; border-radius: 16px; overflow: hidden;
  background: var(--accent);
  box-shadow: 0 30px 50px -28px rgba(20, 12, 4, 0.55), 0 3px 10px rgba(20, 12, 4, 0.14), inset 0 0 0 1px rgba(255, 255, 255, 0.15);
  transition: background-color 0.4s;
}
#board { display: block; width: 100%; height: 100%; touch-action: manipulation; outline: none; user-select: none; -webkit-user-select: none; }
#board:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }

.board-loading {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.06) 0 18px, transparent 18px 36px), var(--accent);
  color: var(--accent-ink); text-align: center; padding: 24px; font-weight: 600; font-size: 16px;
}
.board-loading p { margin: 0; max-width: 32ch; }
.board-loading.error { background: var(--card); color: var(--ink); }
.board-loading.error .loader { display: none; }
.loader { display: flex; gap: 8px; }
.loader span { width: 12px; height: 12px; border-radius: 4px; background: currentColor; opacity: 0.85; animation: bob 1s ease-in-out infinite; }
.loader span:nth-child(2) { animation-delay: 0.15s; }
.loader span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-9px) rotate(45deg); } }

.marks { position: absolute; inset: 0; pointer-events: none; }

/* before Play: the covered board with a Play button in the middle */
.play-cover {
  position: absolute; inset: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(8px, calc(var(--board-h) * 0.03), 16px);
}
.play-btn {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 0.45em;
  height: 2.8em; padding: 0 1.35em 0 1.1em; border: 0; border-radius: 999px;
  font: 750 clamp(18px, calc(var(--board-w) * 0.032), 30px)/1 var(--font); letter-spacing: -0.01em;
  background: #fff; color: #1f1b17;
  box-shadow: 0 18px 40px -14px rgba(0, 0, 0, 0.55), 0 3px 10px rgba(0, 0, 0, 0.18), inset 0 -3px 0 rgba(0, 0, 0, 0.08);
  transition: transform 0.15s, box-shadow 0.2s;
  animation: playIn 0.35s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.play-btn svg { width: 1.15em; height: 1.15em; fill: var(--accent-deep); }
.play-btn:hover { transform: scale(1.04); }
.play-btn:active { transform: scale(0.97); }
.play-btn:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.play-note {
  margin: 0; padding: 4px 12px; border-radius: 999px; font-size: clamp(12px, calc(var(--board-w) * 0.014), 15px); font-weight: 600;
  color: #fff; background: rgba(18, 16, 14, 0.38); backdrop-filter: blur(4px);
}
@keyframes playIn { from { transform: scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }
.mark {
  position: absolute; width: 22px; height: 22px; transform: translate(-50%, -50%);
  display: grid; place-items: center; border-radius: 50%;
  background: #ff3b30; color: #fff; border: 2px solid #fff; font-size: 11px; font-weight: 800; line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); animation: pop 0.28s cubic-bezier(0.3, 1.6, 0.5, 1);
}
@keyframes pop { from { transform: translate(-50%, -50%) scale(0.2); } to { transform: translate(-50%, -50%) scale(1); } }

.layer-chip {
  position: absolute;
  display: flex; align-items: center; gap: 5px; padding: 6px 10px 6px 11px; border-radius: 999px;
  background: rgba(18, 16, 14, 0.86); color: #fff; font-size: 12px; font-weight: 650; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); pointer-events: none; backdrop-filter: blur(6px);
  animation: chipIn 0.18s ease-out;
}
@keyframes chipIn { from { opacity: 0; } to { opacity: 1; } }
.layer-chip .cd { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, 0.3); position: relative; }
.layer-chip .cd.on { background: #fff; box-shadow: 0 0 0 2px var(--accent); }
.layer-chip .cd.x { background: transparent; }
.layer-chip .cd.x::before, .layer-chip .cd.x::after {
  content: ''; position: absolute; left: -1px; top: 3px; width: 10px; height: 2px; background: #ff6b63; border-radius: 1px; transform: rotate(45deg);
}
.layer-chip .cd.x::after { transform: rotate(-45deg); }
.layer-chip .cd.x.on { box-shadow: 0 0 0 2px #ff6b63; }
.layer-chip .cl { margin-left: 4px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.layer-chip.out { opacity: 0; transition: opacity 0.25s; }

/* ---------------- dock ---------------- */
.dock {
  width: min(100%, var(--board-w)); margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 8px 0 4px;
}
.dock-info { flex: 1 1 auto; min-width: 0; }
.progress-label { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; font-size: 15px; color: var(--ink-2); }
.progress-label > span:first-child { white-space: nowrap; }
.progress-label strong { color: var(--ink); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.progress { height: 7px; border-radius: 99px; background: var(--line); margin: 6px 0 5px; overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1); }
.dock-meta { font-size: 13px; color: var(--ink-3); display: flex; gap: 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.dock-actions { display: flex; gap: 10px; flex: none; align-items: center; }
.dock-solved { gap: 14px; min-width: 0; flex-shrink: 1; }
.solved-text { display: flex; flex-direction: column; text-align: right; font-size: 13px; color: var(--ink-3); min-width: 0; }
.solved-text span { white-space: nowrap; }
.solved-text strong { font-size: 16px; color: var(--ink); }

.btn {
  height: 48px; padding: 0 20px; border-radius: 999px; border: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 650; font-size: 16px; letter-spacing: 0.005em; white-space: nowrap;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 85%, black), inset 0 -3px 0 rgba(0, 0, 0, 0.14), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-primary.ready { animation: ready 2.4s ease-in-out infinite; }
@keyframes ready { 0%, 100% { box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 85%, black), 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent), inset 0 -3px 0 rgba(0, 0, 0, 0.14); }
  50% { box-shadow: 0 10px 22px -10px color-mix(in srgb, var(--accent) 85%, black), 0 0 0 7px color-mix(in srgb, var(--accent) 0%, transparent), inset 0 -3px 0 rgba(0, 0, 0, 0.14); } }
.btn-ghost { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong), 0 2px 6px rgba(0, 0, 0, 0.05); }
.btn-ghost:hover { background: var(--bg-2); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-small { height: 36px; padding: 0 14px; font-size: 14px; }
.btn-wide { width: 100%; margin-top: 18px; }
.btn .count {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; display: inline-grid; place-items: center;
  background: rgba(0, 0, 0, 0.2); color: inherit; font-size: 12.5px; font-weight: 750; font-variant-numeric: tabular-nums;
}
.tag {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; background: color-mix(in srgb, var(--accent) 16%, var(--card)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.status { flex: 1 0 100%; text-align: center; margin: 0 0 8px; min-height: 1.35em; font-size: 14px; color: var(--ink-2); }

.diff { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 700; line-height: 18px; letter-spacing: 0.02em; }
.diff-easy { background: #d9f3e3; color: #13663a; }
.diff-medium { background: #fdeccb; color: #7a4d00; }
.diff-hard { background: #fbdada; color: #8e1d1d; }
:root[data-theme='dark'] .diff-easy { background: #16402a; color: #9fe3bb; }
:root[data-theme='dark'] .diff-medium { background: #4a3810; color: #f6d68f; }
:root[data-theme='dark'] .diff-hard { background: #4f1c1c; color: #f5b1b1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .diff-easy { background: #16402a; color: #9fe3bb; }
  :root:not([data-theme='light']) .diff-medium { background: #4a3810; color: #f6d68f; }
  :root:not([data-theme='light']) .diff-hard { background: #4f1c1c; color: #f5b1b1; }
}

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 70px); z-index: 80;
  transform: translate(-50%, -12px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 440px); padding: 10px 18px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-size: 14.5px; font-weight: 550; text-align: center;
  box-shadow: 0 12px 30px -10px rgba(0, 0, 0, 0.45); transition: opacity 0.2s, transform 0.25s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-good { background: #177f47; color: #fff; }
.toast-bad { background: #b8322f; color: #fff; }

/* ---------------- modals ---------------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(14, 10, 7, 0.52); backdrop-filter: blur(3px); opacity: 0; transition: opacity 0.22s; }
.modal-card {
  position: relative; width: min(470px, 100%); max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 24px; padding: 26px 24px 22px; box-shadow: var(--shadow-lg);
  transform: translateY(14px) scale(0.98); opacity: 0; transition: transform 0.26s cubic-bezier(0.2, 1, 0.3, 1), opacity 0.2s; outline: none;
}
.modal-card.wide { width: min(780px, 100%); }
.modal.open .modal-backdrop { opacity: 1; }
.modal.open .modal-card { transform: none; opacity: 1; }
.modal-x { position: absolute; top: 12px; right: 12px; z-index: 2; }
.modal-x.on-image { background: rgba(255, 255, 255, 0.85); color: #1f1b17; }
.modal-x.on-image:hover { background: #fff; }
.modal h2 { margin: 0 44px 10px 0; font-size: 26px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; }
.modal h3 { margin: 22px 0 10px; font-size: 15px; font-weight: 700; color: var(--ink-2); }
.lede { margin: 0 0 18px; color: var(--ink-2); font-size: 16px; line-height: 1.45; }
.fine { font-size: 12.5px; color: var(--ink-3); line-height: 1.45; margin: 16px 0 0; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.steps li { display: grid; grid-template-columns: 46px 1fr; gap: 14px; align-items: start; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.steps strong { color: var(--ink); }
.step-ico { width: 46px; height: 46px; border-radius: 14px; background: var(--bg-2); display: grid; place-items: center; }
.step-ico svg { width: 36px; height: 36px; }
.i-skin { fill: var(--accent); } .i-flap { fill: var(--accent-soft); }
.i-good { fill: #27b467; } .i-tick { fill: none; stroke: #fff; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.i-reveal { fill: var(--accent); } .i-eye { fill: #fff; }
.tips { margin-top: 18px; padding: 14px 16px; border-radius: 16px; background: var(--bg-2); font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.tips p { margin: 0 0 8px; }
.tips p:last-child { margin: 0; }
.kbd-tips { font-size: 13px; }

/* result */
.result-card { padding: 0; width: min(520px, 100%); }
.result-hero { aspect-ratio: 4 / 3; background: var(--bg-2); overflow: hidden; }
.result-hero img { width: 100%; height: 100%; object-fit: cover; display: block; animation: heroIn 0.9s ease-out; }
@keyframes heroIn { from { transform: scale(1.06); filter: saturate(0); } to { transform: none; filter: none; } }
.result-body { padding: 18px 22px 20px; }
.eyebrow { margin: 0 0 6px; font-size: 12.5px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-3); }
.result-body h2 { margin-right: 0; }
.result-sub { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; font-size: 14px; color: var(--ink-2); flex-wrap: wrap; }
.rating { display: flex; align-items: center; gap: 12px; margin: 6px 0 14px; }
.rating p { margin: 0; font-weight: 650; font-size: 17px; }
.stars { display: flex; gap: 2px; }
.star { font-size: 26px; line-height: 1; color: var(--line-strong); }
.star.on { color: var(--gold); text-shadow: 0 2px 8px color-mix(in srgb, var(--gold) 50%, transparent); }
.result-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0 0 16px; }
.result-stats div { background: var(--bg-2); border-radius: 14px; padding: 10px 8px; text-align: center; }
.result-stats dt { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.result-stats dd { margin: 2px 0 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 10px; }
.result-actions .btn-primary { flex: 1; }
.next { margin: 14px 0 0; text-align: center; font-size: 14px; color: var(--ink-2); }
.next strong { font-variant-numeric: tabular-nums; color: var(--ink); }
.credit { margin: 10px 0 0; text-align: center; font-size: 12px; color: var(--ink-3); line-height: 1.5; }
.credit a { color: inherit; }

/* stats */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 6px; }
.stat-grid.two { grid-template-columns: repeat(2, 1fr); margin-top: 8px; }
.stat-grid div { background: var(--bg-2); border-radius: 14px; padding: 12px 6px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.stat-grid strong { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.dist { display: grid; gap: 6px; }
.dist-row { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.dist-k { color: var(--ink-3); font-weight: 650; text-align: right; }
.dist-bar { height: 24px; border-radius: 7px; background: color-mix(in srgb, var(--ink) 16%, transparent); display: flex; align-items: center; justify-content: flex-end; padding: 0 8px; font-weight: 700; color: var(--ink); min-width: 28px; transition: width 0.5s; }
.dist-bar.cur { background: var(--accent); color: var(--accent-ink); }

/* archive & gallery */
.tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--bg-2); margin: 4px 0 16px; }
.tabs button { border: 0; background: none; height: 36px; padding: 0 16px; border-radius: 999px; font-weight: 650; font-size: 14.5px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.count-pill { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--line); font-size: 12px; display: inline-grid; place-items: center; }
.archive-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.tile {
  position: relative; aspect-ratio: 4 / 3; border: 0; border-radius: 14px; overflow: hidden; padding: 0;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.22), rgba(0, 0, 0, 0.14)), var(--tile);
  color: #fff; text-align: left; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 4px 10px -6px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s;
}
.tile:hover { transform: translateY(-2px); }
.tile.current { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }
.tile-thumb { position: absolute; inset: 0; }
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-label { position: absolute; left: 9px; bottom: 7px; display: flex; flex-direction: column; line-height: 1.15; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55); font-size: 12px; }
.tile-label strong { font-size: 17px; font-weight: 750; }
.tile .diff { position: absolute; right: 7px; bottom: 8px; font-size: 10.5px; line-height: 16px; padding: 0 6px; }
.tile-badge { position: absolute; top: 7px; right: 7px; padding: 2px 7px; border-radius: 999px; background: rgba(0, 0, 0, 0.38); font-size: 11px; font-weight: 700; color: #fff; backdrop-filter: blur(4px); }
.tile.st-solved .tile-badge { background: rgba(0, 0, 0, 0.5); color: #ffd35c; letter-spacing: 1px; }
.tile.st-progress .tile-badge { background: #fff; color: #1f1b17; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.gcard { border: 0; padding: 0; background: var(--bg-2); border-radius: 16px; overflow: hidden; text-align: left; display: flex; flex-direction: column; transition: transform 0.15s; }
.gcard:hover { transform: translateY(-2px); }
.gcard img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: var(--line); }
.gcap { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--ink-3); }
.gcap strong { font-size: 15px; color: var(--ink); line-height: 1.25; }
.empty { color: var(--ink-3); text-align: center; padding: 30px 0; margin: 0; }

/* settings */
.settings { display: grid; gap: 2px; margin-top: 4px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.setting span { display: flex; flex-direction: column; gap: 2px; }
.setting small, .danger-row small { color: var(--ink-3); font-size: 13px; }
.setting select { height: 36px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg-2); padding: 0 10px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; width: 46px; height: 28px; border-radius: 14px; margin: 0;
  background: var(--line-strong); position: relative; cursor: pointer; transition: background 0.2s;
}
.switch::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.switch:checked { background: var(--accent); }
.switch:checked::before { transform: translateX(18px); }
.switch:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.danger { margin-top: 18px; display: grid; gap: 10px; }
.danger-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.danger-row span { display: flex; flex-direction: column; gap: 2px; }
.confirm { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--bad) 12%, var(--card)); font-size: 14px; }
.confirm span { flex: 1 1 180px; }

/* ---------------- responsive ---------------- */
@media (max-width: 560px) {
  .app { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar { padding: 8px 0 8px; }
  .logo { width: 34px; height: 34px; }
  .brand-name { font-size: 20px; }
  .brand-meta { font-size: 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .top-actions { gap: 0; }
  .board-wrap { border-radius: 12px; }
  .dock { gap: 10px; }
  .btn { height: 46px; padding: 0 16px; font-size: 15.5px; }
  .modal { place-items: end center; padding: 0; }
  .modal-card { width: 100%; max-height: 92dvh; border-radius: 24px 24px 0 0; padding: 24px 20px calc(20px + env(safe-area-inset-bottom)); transform: translateY(40px); }
  .modal-card.wide, .result-card { width: 100%; }
  .result-card { padding: 0 0 env(safe-area-inset-bottom); }
  .stat-grid strong { font-size: 22px; }
  .result-stats dd { font-size: 18px; }
  .mark { width: 18px; height: 18px; font-size: 9px; border-width: 1.5px; }
}
@media (max-width: 460px) {
  .solved-text { display: none; }
}
@media (max-width: 400px) {
  .meta-long { display: none; }
  .meta-short { display: inline; }
  #btnHint svg { display: none; }
  .btn { padding: 0 14px; }
  .dock-meta #peelsLabel, .dock-meta .sep:nth-of-type(4) { display: none; }
}
@media (max-width: 360px) {
  .brand { gap: 8px; }
  .logo { width: 30px; height: 30px; }
  .brand-name { font-size: 18px; }
  .brand-meta { font-size: 11.5px; gap: 4px; }
  .meta-long { display: none; }
  .meta-short { display: inline; }
  .icon-btn { width: 34px; height: 34px; }
  .icon-btn svg { width: 20px; height: 20px; }
  .dock { gap: 8px; }
  .dock-actions { gap: 6px; }
  #btnHint svg { display: block; }
  #btnHintLabel { display: none; }
  .btn { padding: 0 12px; font-size: 15px; }
  .progress-label { font-size: 14px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .app:not(.side) .topbar { padding: 4px 0; }
  .app:not(.side) .dock { padding: 4px 0; }
  /* keep the live region for screen readers, just don't show it */
  .app:not(.side) .status {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------- text board, collection ---------------- */
.i-paper { fill: #efe9df; }
.i-ink { fill: #1c1a17; }
.i-letters { font: 400 17px 'Anton', Impact, 'Arial Narrow', sans-serif; fill: var(--ink); letter-spacing: 0.5px; }
.result-body h2 { font-size: 24px; letter-spacing: 0.01em; text-transform: uppercase; }
.result-by { margin: -4px 0 8px; font-size: 14.5px; font-weight: 650; color: var(--ink-2); }
.result-note { margin: 0 0 12px; font-size: 15px; line-height: 1.45; color: var(--ink-2); }
.tile-word {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 18px 8px 26px;
  font: 400 22px/1 'Anton', Impact, 'Arial Narrow', sans-serif; letter-spacing: 0.02em; color: #1c1a17;
  background: #efe9df; text-align: center; overflow: hidden;
}
.tile.st-solved .tile-label, .tile.st-revealed .tile-label { color: #1c1a17; text-shadow: none; }
.gcard.text-card { background: var(--bg-2); }
.gphrase {
  display: grid; place-items: center; min-height: 150px; padding: 18px; text-align: center;
  background: #efe9df; color: color-mix(in srgb, var(--tile) 70%, black);
  font: 400 24px/1.1 'Anton', Impact, 'Arial Narrow', sans-serif; letter-spacing: 0.02em; border-bottom: 5px solid var(--tile);
}
/* three dock buttons (Hint, Reveal piece, Check): icon-only Hint / Reveal piece up to 480px */
@media (max-width: 480px) {
  .dock { gap: 8px; }
  .dock-actions { gap: 6px; }
  #btnHint, #btnPiece { padding: 0 13px; }
  #btnHint svg, #btnPiece svg { display: block; }
  #btnHintLabel, #btnPieceLabel { display: none; }
}

/* ---------------- side layout ----------------
   On touch devices held in landscape fitBoard() adds .side: the header becomes
   a column on the left and the dock (progress, status, Hint / Reveal piece / Check) a
   column on the right. Desktops always use the stacked layout. */
.app.side {
  --side-w: clamp(128px, 11vw, 184px);
  --side-gap: 16px;
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr) var(--side-w);
  grid-template-rows: minmax(0, 1fr);
  column-gap: var(--side-gap);
  align-items: center;
  max-width: calc(1200px + 2 * var(--side-w) + 2 * var(--side-gap) + 40px);
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}
.app.side .topbar {
  grid-column: 1; grid-row: 1; height: var(--board-h); width: auto; margin: 0; padding: 0;
  flex-direction: column; flex-wrap: nowrap; align-items: center; justify-content: flex-start; gap: 14px;
}
.app.side .brand { flex-direction: column; gap: 8px; text-align: center; }
.app.side .brand-text { align-items: center; }
.app.side .brand-meta { flex-wrap: wrap; justify-content: center; white-space: normal; row-gap: 3px; }
.app.side .meta-long { display: none; }
.app.side .meta-short { display: inline; }
.app.side .meta-sep2 { flex-basis: 100%; height: 0; overflow: hidden; visibility: hidden; }
.app.side .top-actions { flex-direction: column; gap: 2px; }
.app.side .banner {
  flex: none; width: 100%; max-width: none; margin: auto 0 0;
  flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 10px; font-size: 13px;
}
.app.side .stage { grid-column: 2; grid-row: 1; align-self: stretch; padding: 0; }
.app.side .dock {
  grid-column: 3; grid-row: 1; height: var(--board-h); width: auto; margin: 0; padding: 0;
  flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 12px;
}
.app.side .dock-info { order: 0; flex: none; }
.app.side .dock { container-type: inline-size; }
.app.side .dock-meta { flex-wrap: wrap; white-space: normal; }
@container (max-width: 175px) {
  .dock-meta #peelsLabel, .dock-meta .sep:nth-of-type(4) { display: none; }
}
@container (max-width: 150px) {
  .dock-actions .btn { padding: 0 8px; gap: 5px; font-size: 14.5px; }
  .dock-actions .btn svg { width: 18px; height: 18px; }
}
.app.side .status { order: 1; flex: 1 1 auto; min-height: 0; overflow: hidden; margin: 0; text-align: left; font-size: 13.5px; line-height: 1.4; }
/* a message that doesn't fit the column is only announced, not shown cut off (see fitStatus) */
.app.side .status.clipped {
  flex: none; position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.app.side .dock-actions { order: 2; flex-direction: column; align-items: stretch; gap: 8px; }
.app.side .dock-actions .btn { width: 100%; }
.app.side .dock-solved { gap: 10px; }
.app.side .solved-text { display: flex; text-align: center; }
.app.side ~ .toast { top: calc(env(safe-area-inset-top) + 16px); }
@media (max-height: 500px) {
  .app.side { --side-gap: 12px; padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .app.side .topbar { gap: 10px; }
  .app.side .brand { gap: 6px; }
  .app.side .logo { width: 30px; height: 30px; }
  .app.side .brand-name { font-size: 18px; }
  .app.side .brand-meta { font-size: 12px; }
  .app.side .top-actions { display: grid; grid-template-columns: repeat(2, auto); gap: 2px 6px; }
  .app.side .icon-btn { width: 36px; height: 36px; }
  .app.side .icon-btn svg { width: 21px; height: 21px; }
  .app.side .dock { gap: 8px; }
  .app.side .progress-label { font-size: 14px; }
  .app.side .progress-label strong { font-size: 16px; }
  .app.side .status { font-size: 12.5px; line-height: 1.35; }
  .app.side .btn { height: 42px; padding: 0 12px; font-size: 15px; }
  .app.side .dock-actions { gap: 6px; }
}

/* short landscape screens (phones): the result picture sits beside the text */
@media (max-height: 560px) and (orientation: landscape) {
  .result-card {
    width: min(820px, 100%); height: min(calc(100dvh - 24px), 520px); overflow: hidden;
    display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  }
  .result-hero { aspect-ratio: auto; display: grid; place-items: center; background: #efe9df; }
  .result-hero img { height: auto; object-fit: contain; }
  .result-body { overflow: auto; overscroll-behavior: contain; }
  .result-body h2 { margin-right: 40px; }
}

/* ---------------- portrait phones and tablets: ask for landscape ---------------- */
.rotate {
  display: none; position: fixed; inset: 0; z-index: 90; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 480px at 50% -160px, color-mix(in srgb, var(--accent) 18%, transparent), transparent 70%),
    var(--bg);
  text-align: center;
}
@media (orientation: portrait) and (pointer: coarse) {
  html:not(.portrait-ok) .rotate { display: grid; }
}
.rotate-card { max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.rotate-ico { width: 104px; height: 104px; overflow: visible; }
.rotate-phone { fill: var(--accent); stroke: var(--ink); stroke-width: 2.5; transform-origin: 32px 30px; animation: turn 2.8s ease-in-out infinite; }
.rotate-arrow { fill: none; stroke: var(--ink-2); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.rotate h2 { margin: 8px 0 0; font-size: 24px; font-weight: 750; letter-spacing: -0.02em; line-height: 1.15; }
.rotate p { margin: 0; color: var(--ink-2); font-size: 16px; line-height: 1.45; }
.rotate .link-btn { margin-top: 12px; font-size: 15px; color: var(--ink-2); }
@keyframes turn { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(90deg); } 100% { transform: rotate(0); } }
