/* ============================================================
   Peek — styles
   Palette, type and the signature "aperture ring" chrome.
   Mobile-first, single card.
   ============================================================ */

:root {
  --ink: #14161c;
  --panel: #1d212b;
  --panel-2: #242836;
  --hair: #333849;
  --chalk: #f2efe9;
  --mist: #8b93a7;
  --amber: #e8a33d;
  --amber-dim: #a9761f;
  --good: #6fcf97;
  --bad: #e8636b;

  --radius: 18px;
  --radius-sm: 12px;
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must win over component display rules like
   `display:flex/grid` (otherwise a hidden overlay stays painted). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ink);
  color: var(--chalk);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 700px at 50% -10%, #1b1f29 0%, var(--ink) 55%),
    var(--ink);
}

.mono { font-family: var(--font-mono); }

.app {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
}

/* ---------------- Header ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 12px;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-mark { width: 30px; height: 30px; }
.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.5px;
}
.streak-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--hair);
  color: var(--chalk);
  border-radius: 999px;
  padding: 6px 12px 6px 9px;
  font-size: 15px;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease;
}
.streak-chip:hover { border-color: var(--amber-dim); }
.streak-chip:active { transform: scale(.96); }
.flame { width: 18px; height: 18px; fill: var(--amber); }
.streak-chip.cold .flame { fill: var(--mist); }

/* ---------------- Card ---------------- */
.card {
  background: linear-gradient(180deg, var(--panel-2) 0%, var(--panel) 100%);
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  box-shadow: 0 12px 40px -18px rgba(0,0,0,.8);
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.day-no {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--mist);
  text-transform: uppercase;
}
.cat-tag {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--amber);
  border: 1px solid var(--amber-dim);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---------------- Image stage + aperture ring ---------------- */
.stage { display: flex; justify-content: center; }
.stage-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #0f1116;
  border: 1px solid var(--hair);
}
.puzzle-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.06); /* hide blurred edges */
  transition: filter .6s ease, opacity .45s ease, -webkit-mask-image .45s ease;
  opacity: 0;
}
/* Base layer: the whole image, blurred (blur amount set inline by JS). */
.puzzle-base { filter: blur(30px); }
.puzzle-base.loaded { opacity: 1; }
/* Sharp layer: the same image at full clarity, revealed only through the
   "peek" windows (a mask of radial circles, composed inline by JS). */
.puzzle-sharp {
  filter: none;
  opacity: 0;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}

/* Pixel mode: a 48x48 canvas scaled up with crisp, blocky pixels. */
.pixel-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: none;
}

/* Only the active mode's surface is shown. */
.stage-frame[data-mode="pixels"] .puzzle-img { display: none; }
.stage-frame[data-mode="pixels"] .pixel-canvas { display: block; }
.stage-frame[data-mode="blur"] .pixel-canvas { display: none; }

.stage-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--mist);
  background: repeating-linear-gradient(45deg, #14161c, #14161c 12px, #171a21 12px, #171a21 24px);
}
.stage-fallback svg { width: 54px; height: 54px; opacity: .8; }
.stage-fallback span { font-size: 13px; letter-spacing: .5px; }
.fallback-url {
  max-width: 92%;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: #aeb6c7;
  word-break: break-all;
  text-align: center;
}
.fallback-url a { color: var(--amber); }

.stage-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.spinner {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(139,147,167,.3);
  border-top-color: var(--amber);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* The aperture ring: a stroked circle that doubles as the guess counter.
   stroke-dashoffset shrinks the drawn arc as guesses are used. */
.aperture-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transform: rotate(-90deg); /* start the arc at 12 o'clock */
}
.ring-track {
  fill: none;
  stroke: rgba(20, 22, 28, .55);
  stroke-width: 6;
}
.ring-progress {
  fill: none;
  stroke: var(--amber);
  stroke-width: 6;
  stroke-linecap: round;
  /* dasharray/offset set from JS (circumference of r=94) */
  transition: stroke-dashoffset .55s cubic-bezier(.4, 0, .2, 1), stroke .3s ease;
  filter: drop-shadow(0 0 6px rgba(232,163,61,.45));
}
.ring-progress.win { stroke: var(--good); filter: drop-shadow(0 0 7px rgba(111,207,151,.5)); }
.ring-progress.lose { stroke: var(--bad); filter: drop-shadow(0 0 7px rgba(232,99,107,.45)); }

/* ---------------- Attempt dots ---------------- */
.dots {
  display: flex;
  justify-content: center;
  gap: 9px;
  margin: 16px 0 4px;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--hair);
  transition: background .2s ease, border-color .2s ease, transform .2s ease;
}
.dot.used { background: var(--bad); border-color: var(--bad); }
.dot.win { background: var(--good); border-color: var(--good); transform: scale(1.15); }
.dot.next { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(232,163,61,.14); }

/* ---------------- Guess form + autocomplete ---------------- */
.guess {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.combo { position: relative; flex: 1; }
.guess-input {
  width: 100%;
  background: var(--ink);
  border: 1.5px solid var(--hair);
  color: var(--chalk);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 16px; /* >=16px stops iOS zoom */
  font-family: var(--font-body);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.guess-input::placeholder { color: var(--mist); }
.guess-input:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(232,163,61,.14);
}

.suggest {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(100% + 6px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--panel-2);
  border: 1px solid var(--hair);
  border-radius: var(--radius-sm);
  box-shadow: 0 -12px 34px -14px rgba(0,0,0,.85);
  max-height: 232px;
  overflow-y: auto;
  z-index: 20;
}
.suggest li {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.suggest li .alias-of {
  color: var(--mist);
  font-size: 12px;
  font-family: var(--font-mono);
}
.suggest li[aria-selected="true"],
.suggest li:hover {
  background: rgba(232,163,61,.14);
}
.suggest mark { background: transparent; color: var(--amber); font-weight: 600; }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  transition: transform .1s ease, opacity .15s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--amber);
  color: #241a06;
  padding: 0 18px;
}
.btn-primary:hover:not(:disabled) { background: #f0af4d; }

.input-hint {
  min-height: 16px;
  margin: 8px 2px 0;
  font-size: 12.5px;
  color: var(--mist);
  font-family: var(--font-mono);
}
.input-hint.bad { color: var(--bad); }

/* ---------------- History chips ---------------- */
.history {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 12px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  border: 1px solid var(--hair);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  animation: chip-in .25s ease;
}
@keyframes chip-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.chip .mark {
  width: 20px; height: 20px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}
.chip.wrong .mark { background: rgba(232,99,107,.16); color: var(--bad); }
.chip.right .mark { background: rgba(111,207,151,.16); color: var(--good); }
.chip .txt { text-transform: capitalize; }
.chip.wrong .txt { color: var(--chalk); }
.chip.right .txt { color: var(--good); font-weight: 600; }

/* ---------------- Result / reveal ---------------- */
.result {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hair);
  text-align: center;
  animation: chip-in .3s ease;
}
.result-head {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
}
.result-head .word { text-transform: capitalize; }
.result.win .result-head { color: var(--good); }
.result.lose .result-head { color: var(--bad); }
.result-sub {
  color: var(--mist);
  font-size: 13px;
  margin: 6px 0 14px;
}
.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--good);
  color: #0c2016;
  padding: 12px 22px;
}
.btn-share svg { width: 18px; height: 18px; fill: currentColor; }
.btn-share:hover { background: #86dca9; }
.attribution {
  margin: 14px 0 0;
  font-size: 11px;
  color: var(--mist);
  font-family: var(--font-mono);
  letter-spacing: .3px;
}

/* ---------------- Footer ---------------- */
.foot {
  margin-top: auto;
  padding-top: 16px;
  text-align: center;
  color: var(--mist);
  font-size: 12px;
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

/* Blur ⟷ Pixels mode toggle */
.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--hair);
  border-radius: 999px;
  overflow: hidden;
}
.mode-toggle button {
  background: none;
  border: none;
  color: var(--mist);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.mode-toggle button.active {
  background: var(--amber);
  color: #241a06;
  font-weight: 600;
}
.foot-sep { opacity: .5; }
.link-btn {
  background: none;
  border: none;
  color: var(--mist);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.link-btn:hover { color: var(--amber); }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%) translateY(20px);
  background: var(--chalk);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 30px -10px rgba(0,0,0,.7);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Dialogs ---------------- */
.dlg {
  border: 1px solid var(--hair);
  background: var(--panel);
  color: var(--chalk);
  border-radius: var(--radius);
  padding: 0;
  width: min(92vw, 420px);
  box-shadow: 0 30px 80px -30px rgba(0,0,0,.9);
}
.dlg::backdrop { background: rgba(8,9,12,.66); backdrop-filter: blur(2px); }
.dlg-inner { padding: 20px; }
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.dlg-head h2 { font-family: var(--font-display); font-size: 20px; margin: 0; }
.dlg-close {
  background: none;
  border: none;
  color: var(--mist);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.dlg-close:hover { color: var(--chalk); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stat { text-align: center; }
.stat-num { font-size: 26px; font-weight: 600; display: block; }
.stat-lbl { font-size: 10.5px; color: var(--mist); letter-spacing: .3px; }

.dist-title { font-size: 13px; color: var(--mist); text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px; }
.dist { display: flex; flex-direction: column; gap: 6px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-family: var(--font-mono); font-size: 13px; }
.dist-row .idx { width: 12px; color: var(--mist); }
.dist-bar {
  background: var(--panel-2);
  border-radius: 4px;
  height: 22px;
  min-width: 26px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 8px;
  color: var(--chalk);
  transition: width .4s ease;
}
.dist-bar.filled { background: var(--amber); color: #241a06; font-weight: 600; }
.dist-bar.current { background: var(--good); color: #0c2016; }

.how-list { margin: 0; padding-left: 18px; line-height: 1.7; font-size: 14.5px; color: var(--chalk); }
.how-list strong { color: var(--amber); }

/* Archive */
.archive-hint { margin: 0 0 14px; font-size: 12.5px; color: var(--mist); line-height: 1.5; }
.archive-list { display: flex; flex-direction: column; gap: 6px; max-height: 56vh; overflow-y: auto; }
.arch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--ink);
  border: 1px solid var(--hair);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--chalk);
  cursor: pointer;
  font-size: 14px;
  transition: border-color .15s ease, background .15s ease;
}
.arch-row:hover { border-color: var(--amber-dim); }
.arch-row.current { border-color: var(--amber); background: rgba(232,163,61,.08); }
.arch-num { color: var(--mist); font-size: 13px; width: 42px; flex: none; }
.arch-date { flex: 1; }
.arch-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  flex: none;
}
.arch-badge.win { background: rgba(111,207,151,.16); color: var(--good); }
.arch-badge.lose { background: rgba(232,99,107,.16); color: var(--bad); }
.arch-badge.today { background: rgba(232,163,61,.16); color: var(--amber); }
.arch-badge.todo { background: var(--panel-2); color: var(--mist); }

.foot a { color: var(--mist); text-decoration: underline; text-underline-offset: 2px; }
.foot a:hover { color: var(--amber); }

/* ---------------- Responsive niceties ---------------- */
@media (min-width: 500px) {
  .app { padding-top: 24px; }
  .wordmark { font-size: 28px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
