/* Unhush — interface styles.
   Layout: a dusk-pond play field fills the screen; menus float as dark lily-pad panels,
   anchored left on wide screens so the living pond stays visible beside them.
   One committed night look (the game world is always dusk), so no light theme. */

@font-face {
  font-family: "Unbounded";
  src: url("../assets/fonts/unbounded-latin-var.woff2") format("woff2");
  font-weight: 200 900;
  font-display: swap;
}
@font-face {
  font-family: "DM Mono";
  src: url("../assets/fonts/dmmono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "DM Mono";
  src: url("../assets/fonts/dmmono-latin-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  --night: #07060f;      /* deepest water */
  --dusk: #1d1446;       /* evening sky */
  --reed: #3a2c74;       /* panel edges, quiet lines */
  --ink: #f6efe2;        /* warm paper-white text */
  --ink-dim: #b9b0c9;    /* secondary text, still AA on panel */
  --firefly: #ffcf6b;    /* the player's light: the one accent */
  --ember: #ff9d5c;      /* embers, warnings */
  --panel: rgba(9, 7, 24, 0.84);
  --panel-solid: #0c0a1f;
  --font-display: "Unbounded", "Trebuchet MS", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --step--1: 0.8rem;
  --step-0: 0.95rem;
  --step-1: 1.15rem;
  --step-2: 1.6rem;
  --step-3: clamp(2.2rem, 7vw, 3.4rem);
  color-scheme: dark;
}

* { box-sizing: border-box; }
button, a, input, select, label { touch-action: manipulation; } /* no double-tap-zoom delay */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--night);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: var(--step-0);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
body.in-run #stage { cursor: none; }

#safe {
  position: fixed;
  visibility: hidden;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  /* The whole menu layer takes taps (the play field needs no input while a menu is open).
     A pointer-events:none layer with tappable scrolling panels inside is fragile in WebKit. */
  pointer-events: auto;
  padding-block: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  z-index: 5;
}
.screen-title { justify-content: flex-start; }
.screen-title .panel { margin-left: clamp(0px, 4vw, 64px); }
.screen-over { justify-content: flex-end; }
.screen-over .panel { margin-right: clamp(0px, 4vw, 64px); }
.screen-center { justify-content: center; background: rgba(4, 3, 10, 0.55); pointer-events: auto; }

.panel {
  pointer-events: auto;
  width: 100%;
  max-width: 410px;
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border: 1px solid var(--reed);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  scrollbar-width: thin;
  scrollbar-color: var(--reed) transparent;
}
.panel.narrow { max-width: 340px; }
.panel.wide { max-width: 560px; }

/* ---------- type ---------- */
.logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--step-3);
  letter-spacing: -0.02em;
  line-height: 1;
  margin: 0;
  text-wrap: balance;
}
.logo .un {
  color: transparent;
  -webkit-text-stroke: 2px var(--firefly);
  text-shadow: 0 0 18px rgba(255, 207, 107, 0.55);
  animation: breathe 3.2s ease-in-out infinite;
}
@keyframes breathe { 50% { text-shadow: 0 0 34px rgba(255, 207, 107, 0.9); } }
.tagline { margin: 10px 0 0; color: var(--ink-dim); max-width: 34ch; }
.h-display {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--step-2);
  margin: 0;
  text-wrap: balance;
}
.label {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: var(--step--1);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin: 0;
}
.label .fine { letter-spacing: 0.02em; text-transform: none; margin-left: 6px; }
.fine { font-size: var(--step--1); color: var(--ink-dim); margin: 0; }
.privacy { opacity: 0.8; }
.maker { letter-spacing: 0.06em; margin-top: -10px; }
kbd {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 1px 6px;
  border: 1px solid currentColor;
  border-radius: 4px;
  opacity: 0.6;
  margin-left: 8px;
}

/* ---------- controls ---------- */
.modes { display: grid; gap: 10px; }
.btn {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: var(--step-0);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--reed);
  border-radius: 12px;
  padding: 13px 18px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.btn small { font-family: var(--font-mono); font-size: var(--step--1); color: var(--ink-dim); font-weight: 400; }
.btn:hover:not(:disabled) { border-color: var(--firefly); background: rgba(255, 207, 107, 0.06); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--firefly); color: #1a1206; border-color: var(--firefly); font-weight: 800; }
.btn.primary:hover { background: #ffd98a; }
.btn.primary small, .btn.primary kbd { color: #1a1206; }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: var(--step--1); }
.btn.armed { border-color: var(--ember); color: var(--ember); }
:focus-visible { outline: 2px solid var(--firefly); outline-offset: 3px; }

.link {
  font: inherit;
  font-size: var(--step--1);
  color: var(--ink);
  background: none;
  border: none;
  padding: 10px 0;
  min-height: 44px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--reed);
  text-underline-offset: 4px;
}
.link:hover { text-decoration-color: var(--firefly); }
.links { display: flex; flex-wrap: wrap; gap: 4px 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--reed);
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
}
.chip[aria-checked="true"] { border-color: var(--firefly); color: var(--firefly); background: rgba(255, 207, 107, 0.08); }
.chip:disabled { opacity: 0.45; cursor: not-allowed; }
.chip .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

.block { display: flex; flex-direction: column; gap: 10px; }

/* goals: a ring fills as you get closer */
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.goals li {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: var(--step--1);
  min-width: 0;
}
.goals .ring { width: 26px; height: 26px; }
.goals .ring circle { fill: none; stroke-width: 3; }
.goals .ring .track { stroke: var(--reed); }
.goals .ring .fill { stroke: var(--firefly); stroke-linecap: round; transform: rotate(-90deg); transform-origin: 50% 50%; }
.goals .reward { color: var(--firefly); white-space: nowrap; }
.goals .prog { color: var(--ink-dim); display: block; font-size: 0.72rem; }
.goals li.done { color: var(--firefly); }
.goals li.done .ring .fill { stroke: var(--firefly); }

.rank-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bar { height: 6px; border-radius: 3px; background: rgba(246, 239, 226, 0.1); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--ember), var(--firefly)); border-radius: 3px; transition: width 1.2s cubic-bezier(0.2, 0.8, 0.2, 1); }

/* ---------- game over ---------- */
.final-score {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.6rem, 9vw, 4rem);
  line-height: 1;
  margin: -6px 0 0;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.best-line { margin: -8px 0 0; color: var(--firefly); }
.stat-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0; }
.stat-row div { min-width: 0; }
.stat-row dt { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); }
.stat-row dd { margin: 2px 0 0; font-family: var(--font-display); font-weight: 500; font-size: var(--step-1); font-variant-numeric: tabular-nums; }
.records { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.records li { color: var(--firefly); font-size: var(--step--1); }
.records li::before { content: "\2726  "; }
.tip { margin: 0; font-size: var(--step--1); color: var(--ink-dim); border-left: 2px solid var(--reed); padding-left: 12px; }
.session { margin: 0; font-size: var(--step--1); color: var(--ink); background: rgba(255, 157, 92, 0.1); border: 1px solid rgba(255, 157, 92, 0.35); border-radius: 12px; padding: 10px 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 auto; justify-content: center; }
.actions .btn.primary { flex-basis: 100%; }
.share-text { width: 100%; font-family: var(--font-mono); font-size: var(--step--1); color: var(--ink); background: var(--panel-solid); border: 1px solid var(--reed); border-radius: 10px; padding: 10px; resize: none; user-select: text; }

/* ---------- how / records / settings ---------- */
.how-steps { margin: 0; padding-left: 1.3em; display: grid; gap: 8px; max-width: 62ch; }
.how-steps b { font-family: var(--font-display); font-weight: 500; color: var(--firefly); }
.bestiary { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 16px; }
.bestiary li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; font-size: var(--step--1); min-width: 0; }
.bestiary svg { width: 34px; height: 34px; }
.bestiary b { display: block; font-family: var(--font-display); font-weight: 500; font-size: var(--step-0); }
.bestiary .locked { color: var(--ink-dim); }

.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; margin: 0; }
.rec-grid div { min-width: 0; }
.rec-grid dt { font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); }
.rec-grid dd { margin: 2px 0 0; font-family: var(--font-display); font-weight: 500; font-size: var(--step-1); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.settings { display: grid; gap: 6px; }
.settings .row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid rgba(58, 44, 116, 0.5); flex-wrap: wrap; }
.settings .row > span { min-width: 0; }
.settings small { display: block; color: var(--ink-dim); font-size: 0.72rem; }
.settings input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--firefly); }
.settings input[type="range"] { width: min(200px, 50vw); accent-color: var(--firefly); }
.settings select { font: inherit; font-size: var(--step--1); color: var(--ink); background: var(--panel-solid); border: 1px solid var(--reed); border-radius: 8px; padding: 6px 8px; min-height: 36px; }
.settings .danger .btn { border-color: rgba(255, 157, 92, 0.5); }

/* ---------- in-run ---------- */
.icon-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: calc(env(safe-area-inset-left, 0px) + 12px);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--reed);
  background: rgba(9, 7, 24, 0.6);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  z-index: 4;
}
.toasts {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 92px); /* below the score, clear of tutorial hints */
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 9;
  pointer-events: none;
  width: min(420px, calc(100% - 32px));
}
.toast {
  background: var(--panel-solid);
  border: 1px solid var(--firefly);
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: var(--step--1);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  animation: toast-in 0.3s ease-out;
}
.toast b { color: var(--firefly); font-weight: 500; white-space: nowrap; }
.toast.out { opacity: 0; transition: opacity 0.4s; }
@keyframes toast-in { from { transform: translateY(-12px); opacity: 0; } }

/* ---------- notices: problems and the move from the old address ---------- */
.problem, .moving {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px));
  background: var(--panel-solid);
  border: 1px solid var(--ember);
  border-radius: 16px;
  padding: 20px;
  display: grid;
  gap: 10px;
  z-index: 20;
  color: var(--ink);
}
.moving { border-color: var(--firefly); text-align: center; }
.problem p, .moving p { margin: 0; font-size: var(--step--1); color: var(--ink-dim); overflow-wrap: anywhere; }
.moving a { color: var(--firefly); }

/* ---------- small screens ---------- */
@media (max-width: 700px) {
  .screen-title, .screen-over { justify-content: center; align-items: flex-end; }
  .screen-title .panel, .screen-over .panel { margin: 0; max-height: 86%; }
  .panel { padding: 18px; gap: 14px; }
  .screen-over .actions { order: -1; }
  .screen-over .panel > .label, .screen-over .final-score, .screen-over .best-line, .screen-over .stat-row { order: -2; }
  .stat-row dd { font-size: var(--step-0); }
}
@media (max-height: 560px) and (min-width: 701px) {
  .panel { padding: 16px; gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  .logo .un { animation: none; }
  .bar i { transition: none; }
  .toast { animation: none; }
}

/* Share / Add to Home Screen */
.install-help { margin: 0; padding: 10px 12px; border: 1px solid var(--firefly); border-radius: 10px; color: var(--ink); }
