/* Hashi — islands and bridges on a sea chart, washi paper or a night harbour.
   Every colour arrives as a custom property from themes.js; the defaults
   below are the sea chart. */

:root {
  --bg-a: #efe6d3;
  --bg-b: #d8c9ab;
  --blob-1: rgba(255, 250, 238, 0.95);
  --blob-2: rgba(42, 98, 108, 0.16);
  --blob-3: rgba(196, 140, 62, 0.16);
  --ink: #33271b;
  --ink-soft: #77664f;
  --paper: #fbf5e8;
  --paper-2: #f1e7d2;
  --line: rgba(80, 55, 25, 0.13);
  --accent: #245a63;
  --accent-2: #3c7a83;
  --accent-ink: #f5fbfa;
  --glow: #e3b45c;
  --warn: #b4492f;
  --good: #4b7d4b;
  --card: rgba(255, 251, 240, 0.46);
  --card-border: rgba(255, 255, 255, 0.6);
  --btn-bg: rgba(255, 251, 240, 0.62);
  --btn-hover: rgba(255, 251, 240, 0.92);
  --btn-border: rgba(80, 55, 25, 0.15);
  --hover: rgba(80, 55, 25, 0.08);
  --track: #d3c4a6;
  --shadow: 70, 45, 15;
  --backdrop: rgba(50, 35, 15, 0.4);
  --toast-bg: rgba(51, 39, 27, 0.94);
  --toast-ink: #fbf5e8;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.3, 1.35, 0.5, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b));
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  transition: background 0.8s, color 0.8s;
}

/* ---------------------------------------------------------- background */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg .blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.6;
  will-change: transform;
  transition: background 0.8s;
}
.bg .b1 { width: 60vmax; height: 60vmax; left: -20vmax; top: -25vmax; background: var(--blob-1); animation: drift 52s ease-in-out infinite alternate; }
.bg .b2 { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -20vmax; background: var(--blob-2); animation: drift 66s ease-in-out infinite alternate-reverse; }
.bg .b3 { width: 40vmax; height: 40vmax; left: 30vw; bottom: -25vmax; background: var(--blob-3); animation: drift 78s ease-in-out infinite alternate; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(8vmax, 6vmax) scale(1.12); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 980px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 10px; filter: drop-shadow(0 2px 3px rgba(var(--shadow), 0.3)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 23px; letter-spacing: 0.03em; }
.brand small { font-size: 11.5px; color: var(--ink-soft); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu { display: flex; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.stats {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 4px 16px 6px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.06);
  border-radius: 12px;
  padding: 6px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
  min-width: 0;
  transition: background 0.8s, border-color 0.8s;
}
.stat span { font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.stat b { font-family: var(--serif); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat.islands b { transition: color 0.4s; }
.stat.islands.done b { color: var(--good); }

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  margin: 4px 8px;
}
.board {
  position: absolute;
  inset: 0;
  display: block;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}
.busy {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  box-shadow: 0 6px 20px rgba(var(--shadow), 0.22);
  font-size: 14px;
  white-space: nowrap;
  animation: fade 0.3s;
}
.busy i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in oklab, var(--accent) 30%, transparent);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.actions {
  display: flex;
  gap: 8px;
  padding: 6px 16px 14px;
}
.btn {
  appearance: none;
  flex: 1;
  min-width: 0;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  min-height: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(var(--shadow), 0.08);
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }
.btn span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn.square { flex: 0 0 52px; padding: 0; }
.btn.square svg { width: 22px; height: 22px; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: var(--accent-ink);
  border-color: transparent;
  box-shadow: 0 4px 12px -4px rgba(var(--shadow), 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
.btn.primary:hover { filter: brightness(1.06); background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.btn.primary.thinking { animation: breathe 0.8s ease-in-out infinite; }
.btn.primary.next { animation: nudge 2.4s var(--ease) infinite; }
@keyframes breathe { 50% { opacity: 0.6; } }
@keyframes nudge { 0%, 70%, 100% { transform: none; } 80% { transform: translateX(3px); } 90% { transform: translateX(-1px); } }
.btn.subtle { flex: 0 0 auto; background: transparent; box-shadow: none; color: var(--ink-soft); font-size: 13.5px; margin: 18px auto 0; display: flex; border-color: transparent; min-height: 40px; }
.btn.subtle svg { width: 17px; height: 17px; }

/* Per-look touches on the chrome */
[data-theme="chart"] .stat { box-shadow: inset 0 0 0 2px rgba(255, 251, 240, 0.35), 0 1px 2px rgba(var(--shadow), 0.06); border-color: rgba(80, 55, 25, 0.16); }
[data-theme="chart"] .brand b { font-variant: small-caps; letter-spacing: 0.06em; }
[data-theme="sumi"] .btn.primary { background: var(--accent); box-shadow: 0 3px 10px -4px rgba(150, 30, 15, 0.7); border-radius: 12px 16px 13px 15px; }
[data-theme="sumi"] .stat { border-radius: 10px; background: rgba(255, 255, 252, 0.55); }
[data-theme="harbour"] .btn.primary { box-shadow: 0 0 18px -4px rgba(255, 190, 100, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.3); }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(var(--shadow), 0.25);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 22px;
  flex: 0 0 auto;
}
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 5px 0; }
.figure { display: block; width: 100%; max-width: 360px; height: auto; margin: 6px auto 16px; color: var(--ink); }
.figure .sea { fill: var(--paper-2); stroke: var(--line); }
.figure .isle { fill: var(--paper); stroke: currentColor; stroke-width: 1.6; }
.figure .isle.done { fill: color-mix(in oklab, var(--glow) 55%, var(--paper)); }
.figure .bridge { stroke: currentColor; stroke-width: 1.8; }
.figure .no { stroke: var(--warn); stroke-width: 1.8; stroke-dasharray: 4 3; }
.figure .x { stroke: var(--warn); stroke-width: 2.2; stroke-linecap: round; }
.figure text { font-family: var(--serif); font-weight: 600; font-size: 15px; fill: currentColor; text-anchor: middle; }
.figure .cap { font-family: var(--sans); font-weight: 500; font-size: 10.5px; fill: var(--ink-soft); letter-spacing: 0.04em; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 24px;
    max-height: 84dvh;
    animation: pop 0.28s var(--ease);
  }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 26px 24px 22px;
  box-shadow: 0 20px 60px rgba(var(--shadow), 0.35);
  text-align: center;
  animation: popc 0.34s var(--spring);
  overflow: hidden;
}
@keyframes popc { from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); } }
#confirm.over-sheet { box-shadow: 0 20px 60px rgba(var(--shadow), 0.35), 0 0 0 200vmax var(--backdrop); }
.dialog p { margin: 8px 0 16px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; position: relative; }
.dialog .row { display: flex; gap: 10px; position: relative; }
.result .glow {
  position: absolute;
  inset: -40% -20% auto;
  height: 70%;
  background: radial-gradient(ellipse at 50% 40%, color-mix(in oklab, var(--glow) 45%, transparent), transparent 65%);
  pointer-events: none;
  opacity: 0.85;
}
.result h2 { position: relative; font-size: 30px; }
/* a tiny double bridge between two islands under the title */
.result h2::after {
  content: "";
  display: block;
  width: 86px;
  height: 12px;
  margin: 10px auto 0;
  background:
    radial-gradient(circle, var(--accent) 0 4.2px, transparent 4.8px) 0 50% / 12px 12px no-repeat,
    radial-gradient(circle, var(--accent) 0 4.2px, transparent 4.8px) 100% 50% / 12px 12px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 50% 3.5px / 64px 1.5px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 50% 7px / 64px 1.5px no-repeat;
  opacity: 0.6;
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 18px;
  position: relative;
}
.result-stats div, .summary div { display: flex; flex-direction: column; align-items: center; background: var(--paper-2); border-radius: 12px; padding: 8px 4px; line-height: 1.2; min-width: 0; }
.result-stats span, .summary span { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.result-stats b, .summary b { font-family: var(--serif); font-size: 19px; font-weight: 600; }
.total { display: flex; flex-direction: column; align-items: center; margin: 2px 0 14px; position: relative; }
.total span { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); }
.total b { font-family: var(--serif); font-size: 46px; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.total em {
  font-style: normal;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1.5px dashed color-mix(in oklab, var(--accent) 60%, transparent);
  border-radius: 999px;
  padding: 3px 10px;
  margin-top: 6px;
  animation: popc2 0.5s 0.25s var(--spring) both;
}
@keyframes popc2 { from { opacity: 0; transform: scale(0.8); } }

/* ------------------------------------------------------------ play sheet */
.daily-card {
  appearance: none;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 12%, var(--paper)), var(--paper-2));
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.2s;
}
.daily-card:active { transform: scale(0.985); }
.daily-card[aria-current="true"] { border-color: var(--accent); }
.daily-badge {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--accent-ink);
  background: radial-gradient(circle at 35% 30%, var(--accent-2), var(--accent));
  box-shadow: 0 3px 8px -3px rgba(var(--shadow), 0.6);
}
.daily-badge svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.daily-card.done .daily-badge { background: radial-gradient(circle at 35% 30%, color-mix(in oklab, var(--good) 70%, white), var(--good)); }
.daily-text { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.daily-text b { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.daily-text small { color: var(--ink-soft); font-size: 13px; }

.with-count { display: flex; align-items: baseline; justify-content: space-between; }
.with-count small { font-family: var(--sans); font-weight: 500; font-size: 12.5px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.levels { display: grid; grid-template-columns: repeat(6, 1fr); gap: 7px; }
.level-tile {
  appearance: none;
  position: relative;
  aspect-ratio: 1;
  min-height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  cursor: pointer;
  font: inherit;
  padding: 0;
  transition: transform 0.15s, border-color 0.2s, background 0.2s;
}
.level-tile:active { transform: scale(0.94); }
.level-tile b { font-family: var(--serif); font-size: 17px; font-weight: 600; line-height: 1; }
.level-tile small { font-size: 10px; color: var(--ink-soft); line-height: 1; font-variant-numeric: tabular-nums; }
.level-tile svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.8; opacity: 0.55; }
.level-tile.solved {
  background: radial-gradient(circle at 35% 30%, color-mix(in oklab, var(--glow) 22%, var(--paper)), color-mix(in oklab, var(--glow) 38%, var(--paper-2)));
  border-color: color-mix(in oklab, var(--glow) 60%, transparent);
}
.level-tile.solved::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  border: 1.2px solid color-mix(in oklab, var(--ink) 25%, transparent);
  pointer-events: none;
}
.level-tile.locked { opacity: 0.45; cursor: default; }
.level-tile[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }

.opt-row { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 10px; }
.opt-label { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.btn.start { width: 100%; margin-top: 8px; }

/* ------------------------------------------------------------- results */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.sheet-body table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.sheet-body th { text-align: left; vertical-align: bottom; font-weight: 500; color: var(--ink-soft); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.sheet-body td { padding: 7px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.sheet-body .num { text-align: right; }
td.rs-time { font-family: var(--serif); font-weight: 600; font-size: 15px; }
td.rs-puzzle { overflow: hidden; text-overflow: ellipsis; max-width: 10em; }
.bests th:first-child, .bests td:first-child { text-align: left; }
.bests th, .bests td { text-align: center; }
.bests td { font-family: var(--serif); font-weight: 600; font-size: 15px; }
.bests td:first-child { font-family: var(--sans); font-weight: 500; font-size: 13px; color: var(--ink-soft); }
.bests td.none { color: color-mix(in oklab, var(--ink-soft) 55%, transparent); font-weight: 400; }
.note { font-size: 12.5px; color: var(--ink-soft); margin: -2px 0 8px; }
@media (max-width: 420px) { .sheet-body td { padding: 7px 3px; } .sheet-body th { padding: 4px 3px; font-size: 10px; } }

/* ------------------------------------------------------------- settings */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  min-height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 22%, transparent); }
.opt small { color: var(--ink-soft); font-size: 12px; font-variant-numeric: tabular-nums; }
.opts.lang .opt, .opts.sizes .opt, .opts.diffs .opt { padding-left: 14px; min-width: 72px; justify-content: center; }
.swatch {
  display: inline-block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.sw-chart {
  background:
    radial-gradient(circle at 34% 40%, #f8eccd 0 4px, #35261a 4.2px 5.2px, rgba(52, 92, 104, 0.45) 5.4px 6.1px, transparent 6.4px),
    linear-gradient(90deg, transparent 55%, #35261a 55% 59%, transparent 59%) 0 0 / 100% 100%,
    radial-gradient(circle at 50% 50%, #f2e6cb, #ddc79a);
}
.sw-sumi {
  background:
    radial-gradient(circle at 36% 42%, #bf3a26 0 4.4px, #1b1a19 4.8px 6px, transparent 6.4px),
    linear-gradient(90deg, transparent 56%, #1b1a19 56% 61%, transparent 61%),
    #f8f4eb;
}
.sw-harbour {
  background:
    radial-gradient(circle at 36% 42%, #ffd78c 0 2.2px, #33465f 2.6px 5px, rgba(255, 190, 100, 0.4) 5.4px, transparent 9px),
    linear-gradient(90deg, transparent 56%, #e9cf97 56% 60%, transparent 60%),
    radial-gradient(circle at 50% 30%, #18304d, #07111f);
}
.sw-auto { background: linear-gradient(135deg, #f2e6cb 0 50%, #11253d 50%); }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 18px; cursor: pointer; font-size: 15px; line-height: 1.35; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: var(--track); position: relative; transition: background 0.25s; }
.toggle .track::after { 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.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 8px);
  transform: translateX(-50%) translateY(-8px);
  z-index: 15;
  background: var(--toast-bg);
  color: var(--toast-ink);
  padding: 10px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  width: min(calc(100vw - 24px), 460px);
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.long { padding: 12px 18px; text-align: left; justify-content: flex-start; }

/* ------------------------------------------------------- small screens */
@media (max-height: 640px) {
  .top { padding-top: 6px; }
  .brand small { display: none; }
  .brand b { font-size: 20px; }
  .brand img { width: 32px; height: 32px; }
  .stat b { font-size: 17px; }
  .stat { padding: 4px 6px; }
  .actions { padding-bottom: 10px; }
  .btn { padding: 9px 10px; min-height: 46px; }
}
@media (max-width: 520px) {
  .actions { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .actions .btn { flex-direction: column; gap: 3px; padding: 7px 4px 6px; font-size: 12.5px; }
  .actions .btn.square { flex-basis: 46px; }
  .actions .btn svg { width: 21px; height: 21px; }
}
@media (max-width: 380px) {
  .top { padding-left: 12px; padding-right: 8px; }
  .brand { gap: 8px; }
  .brand img { width: 36px; height: 36px; }
  .menu { gap: 0; }
  .stats { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .stat span { font-size: 9.5px; letter-spacing: 0.04em; }
  .stat b { font-size: 18px; }
  .actions .btn { font-size: 12px; }
  .actions .btn.square { flex-basis: 42px; }
  .levels { gap: 6px; }
  .level-tile b { font-size: 16px; }
}
@media (min-width: 600px) {
  .levels { grid-template-columns: repeat(10, 1fr); gap: 6px; }
  .level-tile b { font-size: 15px; }
  .level-tile small { font-size: 9px; }
}
@media (min-width: 900px) and (min-height: 700px) {
  .brand b { font-size: 27px; }
  .stage { margin: 10px 16px; }
}

/* Phones on their side: chrome in a column on the left, the sea fills the rest. */
@media (orientation: landscape) and (max-height: 520px) {
  .app {
    display: grid;
    grid-template-columns: minmax(240px, 32%) 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas: "top stage" "stats stage" "gap stage" "actions stage";
    max-width: none;
  }
  .top { grid-area: top; flex-wrap: wrap; gap: 2px 8px; padding: 8px 10px 2px 14px; }
  .brand b { font-size: 20px; }
  .menu { margin-left: -6px; }
  .stats { grid-area: stats; grid-template-columns: 1fr 1fr; padding: 4px 10px 4px 14px; gap: 6px; }
  .stat b { font-size: 17px; }
  .stage { grid-area: stage; margin: 6px 8px 6px 2px; }
  .actions {
    grid-area: actions;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-template-areas: "undo redo check check" "puzzles puzzles hint hint";
    padding: 4px 10px 10px 14px;
    gap: 6px;
  }
  #btn-undo { grid-area: undo; }
  #btn-redo { grid-area: redo; }
  #btn-check { grid-area: check; }
  #btn-puzzles { grid-area: puzzles; }
  #btn-hint { grid-area: hint; }
  .actions .btn { flex-direction: row; gap: 6px; padding: 6px 6px; font-size: 13px; min-height: 42px; }
  .actions .btn.square { min-width: 0; }
  .toast, .toast.long { top: auto; bottom: 112px; left: calc(max(240px, 32vw) / 2 + 4px); width: auto; max-width: calc(max(240px, 32vw) - 20px); font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .blob { animation: none; }
  .sheet, .dialog, .backdrop, .total em, .btn.primary.next, .busy { animation: none; transition-duration: 0.01s; }
}
[data-theme="harbour"] .result .glow { opacity: 0.4; background: radial-gradient(ellipse at 50% 40%, rgba(255, 196, 110, 0.5), transparent 65%); }
