/* Chess Snacks, web version. The colours come from js/theme.js as CSS variables. */

:root {
  --bg: #2a1d14;
  --card: #38281c;
  --ink: #f0e2cb;
  --ink-soft: #cdb393;
  --ink-muted: #9c8262;
  --accent: #c2702f;
  --accent-ink: #ffffff;
  --border: #46341f;
  --board-frame: #1d130b;
  --gold: #f3cf63;
  --light-sq: #e8d2b0;
  --dark-sq: #8a5a3c;
  --hl: #e8a77f;
  --bad: #cf5b3b;
  /* The board is as wide as the column, and never taller than the room on the screen. */
  --board-w: min(100%, max(220px, calc(100dvh - 350px)));
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* The background picture of a theme, behind the page. */
#texture {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  pointer-events: none;
}

#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

h1, h2, h3, p { margin: 0; }

button, input { font: inherit; color: inherit; }
button { margin: 0; padding: 0; border: 0; background: none; cursor: pointer; text-align: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.boot { padding: 48px 24px; color: var(--ink-soft); text-align: center; }

.screen { flex: 1; display: flex; flex-direction: column; padding: 12px 24px 0; min-width: 0; }

/* ---- shared parts ---- */

.btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.secondary { background: var(--card); color: var(--ink); border: 1px solid var(--border); }
.btn.big { padding: 18px; }
.btn.inline { width: auto; padding: 11px 26px; font-size: 15px; border-radius: 9px; }
.btn:active { opacity: 0.85; }

.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.back { display: flex; align-items: center; width: 72px; font-size: 16px; color: var(--accent); }
.back-spacer { width: 72px; }
.chevron { font-size: 26px; line-height: 1; color: var(--accent); margin: -4px 2px 0 0; }
.chevron.muted { color: var(--ink-muted); font-size: 22px; margin-left: 8px; }
.header-title { font-size: 18px; font-weight: 700; }

.title { font-size: 34px; font-weight: 800; text-align: center; }
.subtitle { font-size: 15px; color: var(--ink-soft); text-align: center; }

.link { color: var(--accent); font-weight: 700; }

.segment { display: flex; background: var(--border); border-radius: 9px; padding: 3px; }
.segment.block { width: 100%; margin-bottom: 4px; }
.seg-btn { width: 64px; padding: 7px 2px; border-radius: 7px; font-size: 14px; font-weight: 600; color: var(--ink-soft); text-align: center; white-space: nowrap; }
.segment.block .seg-btn { flex: 1; width: auto; padding: 9px 2px; }
.seg-btn.active { background: var(--card); color: var(--ink); }

.input {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 16px;
}
.input::placeholder { color: var(--ink-muted); }

.modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(0, 0, 0, 0.55); }
.modal-card { width: 100%; max-width: 340px; padding: 20px; border-radius: 14px; background: var(--card); border: 1px solid var(--border); }
.modal-card h3 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.modal-card p { font-size: 14px; color: var(--ink-soft); line-height: 1.45; margin-bottom: 16px; }

/* ---- the board ---- */

.board-frame { width: 100%; padding: 5px; border-radius: 8px; background: var(--board-frame); }
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  border-radius: 3px;
  overflow: hidden;
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1; min-width: 0; touch-action: manipulation; }
.sq.light { background: var(--light-sq); --mark: var(--dark-sq); --label: var(--dark-sq); }
.sq.dark { background: var(--dark-sq); --mark: var(--hl); --label: var(--light-sq); }
button.sq:focus-visible { outline: 3px solid var(--mark); outline-offset: -3px; z-index: 1; }
.tint { position: absolute; inset: 0; }
.tint.last { background: var(--mark); opacity: 0.32; }
.tint.check { background: #d7263d; opacity: 0.5; }
.tint.sel { background: var(--mark); opacity: 0.5; }
.pc { position: relative; display: block; width: 92%; height: 92%; }
.pc svg, .promo-btn svg { display: block; width: 100%; height: 100%; }
.spot { position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--mark); opacity: 0.7; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: max(2px, 1cqw) solid var(--mark); opacity: 0.7; }
.coord { position: absolute; font-size: max(6px, 2.5cqw); font-weight: 700; line-height: 1.1; color: var(--label); }
.coord.rank { top: 1px; }
.coord.file { bottom: 0; }
.coord.at-left { left: 2px; }
.coord.at-right { right: 2px; }
.slider { position: absolute; display: flex; align-items: center; justify-content: center; width: 12.5%; height: 12.5%; pointer-events: none; z-index: 2; }

/* ---- first run ---- */

.onboarding-content { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 48px 0 24px; }
.onboarding .subtitle { margin: 6px 0 36px; }
.points { display: flex; flex-direction: column; gap: 22px; }
.point { display: flex; align-items: flex-start; gap: 14px; }
.point-icon { width: 34px; font-size: 26px; line-height: 1.1; text-align: center; flex: none; }
.point-title { font-size: 16px; font-weight: 700; }
.point-body { font-size: 14px; color: var(--ink-soft); line-height: 20px; margin-top: 3px; }
.footer-cta { padding: 18px 0; }

/* ---- home ---- */

.home { padding-top: 8px; }
.home-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; justify-content: flex-end; align-items: center; height: 40px; }
.icon-btn { display: flex; padding: 6px; margin: -6px; color: var(--ink-soft); }
.home .title { margin-top: 12px; }
.home .subtitle { margin: 4px 0 28px; }
.notice-card { display: flex; align-items: center; gap: 10px; padding: 12px 14px; margin-bottom: 20px; border-radius: 12px; background: var(--card); border: 1px solid var(--accent); }
.notice-main { flex: 1; font-size: 14px; font-weight: 600; line-height: 19px; }
.notice-close { padding: 4px; font-size: 15px; font-weight: 700; color: var(--ink-muted); }
.plays-left { font-size: 12px; color: var(--ink-muted); text-align: center; margin-top: 10px; }
.stats { display: flex; gap: 8px; margin-top: 20px; }
.completions { display: flex; justify-content: center; gap: 8px; margin-top: 8px; }
.stat { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; padding: 16px 2px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.stat.comp { flex: none; min-width: 132px; padding: 12px 22px; }
.stat-value { font-size: 17px; font-weight: 800; white-space: nowrap; }
.stat-label { font-size: 12px; color: var(--ink-muted); margin-top: 3px; white-space: nowrap; }
.journey { margin-top: 24px; }
.bar-track { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.bar-fill { height: 6px; border-radius: 3px; background: var(--accent); }
.journey-label { font-size: 13px; line-height: 20px; color: var(--ink-muted); text-align: center; margin-top: 8px; }
.journey-label .link { font-size: 13px; }
.home-footer { display: flex; justify-content: center; margin-top: auto; padding: 18px 0; }
.foot-link { font-size: 13px; font-weight: 600; color: var(--ink-soft); padding: 4px 8px; }

/* ---- the game ---- */

.turn-row { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 24px; margin-bottom: 12px; }
.dot { width: 13px; height: 13px; border-radius: 50%; border: 1.5px solid var(--ink); flex: none; }
.turn-text { font-size: 16px; font-weight: 600; color: var(--ink-soft); }
.won { min-height: 24px; margin-bottom: 12px; font-size: 20px; font-weight: 800; line-height: 24px; color: var(--accent); text-align: center; }
.won.pop { animation: pop 450ms cubic-bezier(0.2, 1.7, 0.4, 1) both; }
@keyframes pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: scale(1); } }
.lost { min-height: 24px; margin-bottom: 12px; font-size: 18px; font-weight: 800; line-height: 24px; color: var(--bad); text-align: center; }
.board-wrap { display: flex; justify-content: center; margin: 0 -16px; }
.board-box { position: relative; width: var(--board-w); }
.banner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 0 22px; border-radius: 10px; background: rgba(18, 18, 24, 0.84); }
.banner-title { font-size: 18px; font-weight: 800; color: #ffffff; text-align: center; }
.banner-body { font-size: 14px; line-height: 20px; color: #d8d8e0; text-align: center; }
.banner .btn { margin-top: 4px; }
.promo-backdrop { position: absolute; inset: 0; z-index: 3; display: flex; align-items: center; justify-content: center; border-radius: 8px; background: rgba(0, 0, 0, 0.5); }
.promo-card { display: flex; gap: 6px; padding: 8px; border-radius: 14px; background: var(--card); border: 1px solid var(--border); }
.promo-btn { width: 60px; height: 60px; padding: 4px; border-radius: 10px; background: var(--bg); }
.attrib { margin-top: 14px; padding: 0 16px; text-align: center; }
.attrib-year { font-size: 13px; color: var(--ink-muted); margin-bottom: 2px; }
.attrib-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attrib-vs { font-size: 13px; font-weight: 400; color: var(--ink-muted); }
.solution { margin-top: 14px; font-size: 15px; text-align: center; }
.hints { display: flex; flex-direction: column; gap: 4px; font-size: 15px; text-align: center; }
.controls { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.note { font-size: 15px; color: var(--ink-soft); }
.indicator { margin-top: auto; padding: 14px 0; font-size: 12px; color: var(--ink-muted); text-align: center; }

/* ---- unlock ---- */

.lead { font-size: 15px; color: var(--ink-soft); text-align: center; margin-bottom: 18px; }
.tier { padding: 18px; margin-bottom: 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.tier.featured { border: 2px solid var(--accent); }
.badge { display: inline-block; padding: 3px 10px; margin-bottom: 10px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 700; }
.tier-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 20px; font-weight: 800; }
.blurb { font-size: 14px; color: var(--ink-soft); margin-top: 4px; }
.earn { font-size: 13px; line-height: 19px; color: var(--ink-muted); margin: 18px 0; }

/* ---- settings ---- */

.settings { padding-top: 10px; padding-bottom: 24px; }
.section { font-size: 16px; font-weight: 700; margin: 6px 0 8px; }
.section.first { margin-top: 0; }
.divider { height: 1px; margin: 22px 0 4px; border: 0; background: var(--ink); }
.help { font-size: 12px; line-height: 17px; color: var(--ink-muted); margin-top: 8px; }
.help.below { margin: 0 0 12px; }
.preview { width: 190px; margin: 0 auto; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preset { display: flex; flex-direction: column; align-items: center; width: calc((100% - 16px) / 3); padding: 6px 4px; border-radius: 10px; background: var(--card); border: 1px solid var(--border); }
.preset.active { border: 2px solid var(--accent); padding: 5px 3px; }
.swatches { display: flex; gap: 3px; margin-bottom: 5px; }
.sw { width: 13px; height: 13px; border-radius: 3px; border: 1px solid var(--border); }
.preset-name { font-size: 12px; font-weight: 600; white-space: nowrap; }
.row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.row-label { font-size: 15px; padding-right: 8px; }
.link-row { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 4px 0; }
.link-row .chevron { font-size: 22px; margin: -2px 0 0; }
.num-form { display: flex; gap: 8px; }
.num-form .input { flex: 1; }

/* ---- about ---- */

.about { padding-bottom: 32px; }
.body { font-size: 14px; line-height: 20px; color: var(--ink-soft); }
.h { font-size: 16px; font-weight: 700; margin: 20px 0 6px; }
.legal-row { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 600; color: var(--accent); }
.legal-chevron { font-size: 13px; color: var(--ink-muted); }
.legal-body { padding: 10px 0; }
.legal-body p { font-size: 13px; line-height: 19px; color: var(--ink-soft); }
.legal-body p + p { margin-top: 12px; }
.version { align-self: flex-start; margin-top: 28px; padding: 4px 0; font-size: 12px; color: var(--ink-muted); cursor: default; }
.redeem { margin: 12px 0 16px; padding: 14px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.redeem .input { background: var(--bg); border-radius: 8px; }
.redeem-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 8px; }
.redeem-success { padding: 4px 0; font-size: 15px; font-weight: 700; color: var(--accent); text-align: center; }
.redeem-error { margin-top: 10px; font-size: 13px; font-weight: 600; color: var(--bad); }

/* ---- solved games ---- */

.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 0 16px 48px; }
.empty-title { font-size: 18px; font-weight: 800; text-align: center; }
.empty-body { font-size: 14px; line-height: 20px; color: var(--ink-soft); text-align: center; }
.mode-title { font-size: 17px; font-weight: 800; text-align: center; margin-bottom: 2px; }
.count { font-size: 13px; color: var(--ink-muted); text-align: center; margin-bottom: 12px; }
.solved .segment { margin-bottom: 14px; }
.solved .seg-btn { font-size: 13px; padding: 7px 2px; }
.solved-list { padding-bottom: 24px; }
.solved-row { display: flex; align-items: center; width: 100%; padding: 12px 14px; margin-bottom: 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.row-num { min-width: 46px; font-size: 13px; font-weight: 800; color: var(--ink-muted); }
.row-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.row-names { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

/* ---- a mode is complete ---- */

.completion { align-items: center; justify-content: center; gap: 4px; text-align: center; }
.crown { font-size: 52px; line-height: 1.1; margin-bottom: -8px; }
.sparkles { font-size: 26px; white-space: pre; }
.trophy { line-height: 1.15; }
.completion-title { font-size: 26px; font-weight: 800; margin-top: 14px; }
.completion-title.gold { color: var(--gold); }
.completion-sub { font-size: 16px; color: var(--ink-soft); margin-top: 4px; }
.completion-actions { width: 80%; margin-top: 32px; }

/* ---- a piece that the mouse drags ---- */

.drag-ghost { position: fixed; left: 0; top: 0; z-index: 20; display: flex; align-items: center; justify-content: center; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.35)); }
.drag-ghost svg { display: block; width: 100%; height: 100%; }

@media (hover: hover) {
  .btn:hover { filter: brightness(1.08); }
  .nav-link:hover { background: var(--card); color: var(--ink); }
  .seg-btn:hover { color: var(--ink); }
  .solved-row:hover, .preset:hover, button.stat:hover { border-color: var(--accent); }
  .back:hover, .link:hover, .foot-link:hover, .legal-row:hover { text-decoration: underline; }
  button.sq { cursor: pointer; }
}

/* ---- the desktop layout (js/layout.js sets data-layout on <html>) ---- */

#topnav { display: none; }

[data-layout="desktop"] {
  /* the board is as tall as the window allows, with room for the panel beside it */
  --board-w: min(calc(100dvh - 124px), calc(100vw - 480px), 920px);
}

[data-layout="desktop"] #topnav {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  padding: 0 max(32px, calc((100vw - 1116px) / 2));
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--card) 55%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; }
.brand img { display: block; border-radius: 7px; }
#topnav nav { display: flex; gap: 4px; }
#topnav.bare nav { display: none; }
.nav-link { padding: 8px 14px; border-radius: 9px; font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.nav-link.active { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 1px var(--border); }

[data-layout="desktop"] #app { max-width: 1180px; min-height: calc(100dvh - 60px); padding: 0 32px; }
[data-layout="desktop"] .screen { width: 100%; max-width: 680px; margin: 0 auto; padding: 36px 0 48px; }

.page-head { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-bottom: 24px; }
.page-head .back, .play-panel .back { width: auto; font-size: 14px; }
.page-head .back .chevron, .play-panel .back .chevron { font-size: 20px; margin-top: -3px; }
.page-title { font-size: 28px; font-weight: 800; line-height: 1.15; }

/* home: the text on the left, the next game on the right */
[data-layout="desktop"] .screen.home { flex-direction: row; align-items: center; justify-content: center; gap: 72px; max-width: 1040px; padding: 24px 0 48px; }
[data-layout="desktop"] .home-main { flex: 0 1 420px; }
[data-layout="desktop"] .home .title { margin-top: 0; font-size: 54px; line-height: 1.05; text-align: left; }
[data-layout="desktop"] .home .subtitle { margin: 10px 0 32px; font-size: 18px; text-align: left; }
[data-layout="desktop"] .plays-left { font-size: 13px; text-align: left; }
[data-layout="desktop"] .journey-label { text-align: left; }
.home-preview { flex: none; width: min(460px, calc(100dvh - 200px)); }
.preview-board { display: block; width: 100%; border-radius: 8px; transition: transform 120ms ease; }
.preview-board:hover { transform: translateY(-3px); }
.preview-caption { margin-top: 12px; font-size: 13px; color: var(--ink-muted); text-align: center; }

/* the game: the board on the left, the panel on the right */
[data-layout="desktop"] .screen.player { max-width: none; padding: 32px 0; }
.play-area { display: flex; justify-content: center; align-items: flex-start; gap: 40px; }
[data-layout="desktop"] .board-wrap { flex: none; margin: 0; }
.play-panel { flex: none; display: flex; flex-direction: column; width: 320px; min-height: var(--board-w); }
.play-panel .back { align-self: flex-start; margin-bottom: 14px; }
.play-title { font-size: 30px; font-weight: 800; line-height: 1.1; }
.play-number { margin: 4px 0 22px; font-size: 14px; color: var(--ink-muted); }
.play-panel .turn-row { justify-content: flex-start; }
.play-panel .won, .play-panel .lost { min-height: 28px; font-size: 22px; line-height: 28px; text-align: left; transform-origin: left center; }
.play-panel .attrib { margin-top: 6px; padding: 0; text-align: left; }
.play-panel .hints, .play-panel .solution { text-align: left; }
.play-panel .controls { margin-top: 22px; }
.keys-help { margin-top: auto; padding-top: 20px; font-size: 12px; line-height: 18px; color: var(--ink-muted); }

/* settings: two columns */
[data-layout="desktop"] .screen.settings { max-width: 920px; }
[data-layout="desktop"] .screen.advanced { max-width: 680px; }
[data-layout="desktop"] .settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 56px; align-items: start; }
[data-layout="desktop"] .set-rest > .divider:first-child { display: none; }
[data-layout="desktop"] .set-rest > .divider:first-child + .section { margin-top: 0; }
[data-layout="desktop"] .preview { width: 300px; }
[data-layout="desktop"] .num-form { max-width: 420px; }

/* solved games: a grid of cards */
[data-layout="desktop"] .screen.solved { max-width: 1040px; }
[data-layout="desktop"] .mode-title, [data-layout="desktop"] .count { text-align: left; }
[data-layout="desktop"] .solved .segment { max-width: 420px; }
[data-layout="desktop"] .solved-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
[data-layout="desktop"] .solved-row { margin-bottom: 0; }

/* unlock: the two levels side by side */
[data-layout="desktop"] .lead { text-align: left; }
[data-layout="desktop"] .tiers { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: stretch; }

[data-layout="desktop"] .screen.onboarding { max-width: 560px; }
[data-layout="desktop"] .onboarding-content { padding-top: 24px; }

@media (prefers-reduced-motion: reduce) {
  .won.pop { animation: none; }
}
