/* ================= theme =================
   --bg and --accent are set per-game from the generated concept;
   everything else derives from them via color-mix. */
:root {
  --bg: #14121f;
  --accent: #8f7bff;
  --text: #f2f1fa;
  --panel: color-mix(in oklab, var(--bg) 86%, white);
  --panel-2: color-mix(in oklab, var(--bg) 93%, white);
  --line: color-mix(in oklab, var(--panel) 80%, var(--accent));
  --muted: color-mix(in oklab, var(--text) 55%, var(--bg));
  --accent-soft: color-mix(in oklab, var(--accent) 22%, var(--bg));
  --good: #3ecf8e;
  --danger: #ff5d6c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 800px at 70% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "SF Pro Rounded", ui-rounded, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  min-height: 100vh;
  transition: background 600ms ease;
}

h1, h2, h3 { margin: 0; }
p { margin: 0.35rem 0; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; font-weight: 500; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.hidden { display: none !important; }
.row { display: flex; gap: 0.6rem; align-items: center; }
.row.center { justify-content: center; }

/* ================= shared bits ================= */
.screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
  position: relative;
  z-index: 1;
}

.card {
  background: color-mix(in oklab, var(--panel) 92%, transparent);
  border: 1px solid color-mix(in oklab, var(--line) 55%, transparent);
  border-radius: 18px;
  padding: 1.25rem;
  backdrop-filter: blur(8px);
}

.btn {
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: transparent;
  transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease, filter 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--accent);
  color: color-mix(in oklab, var(--accent) 12%, black);
  box-shadow: 0 4px 24px color-mix(in oklab, var(--accent) 40%, transparent);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { background: var(--panel-2); }
.btn.big { width: 100%; padding: 0.85rem; font-size: 1.05rem; margin-top: 0.75rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.arm { background: var(--danger); border-color: var(--danger); color: #fff; }

.btn:focus-visible, #big-btn:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem;
  font: inherit;
  color: var(--text);
  resize: vertical;
  margin-top: 0.5rem;
}
textarea::placeholder { color: var(--muted); }

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.35rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
}

/* ================= start screen ================= */
.hero { text-align: center; margin: 2.5rem 0 2rem; }
.hero h1 { font-size: 3rem; letter-spacing: -0.02em; }
.tag { font-size: 1.05rem; color: var(--muted); margin: 0.6rem auto 0; max-width: 46ch; text-wrap: balance; }

.forge-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.forge-cards h2 { font-size: 1.15rem; }

.saves {
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1rem;
}
.continue {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  border-color: color-mix(in oklab, var(--accent) 60%, transparent);
  box-shadow: 0 6px 30px var(--accent-soft);
}
.continue h3 { font-size: 1.1rem; }


.difficulty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin: -0.75rem 0 1.25rem;
}
.seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.4rem 0.8rem;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: var(--accent);
  color: color-mix(in oklab, var(--accent) 12%, black);
}

.model-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 2.5rem;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
}
.dot { width: 10px; height: 10px; border-radius: 50%; background: #8a8a99; flex: none; }
.dot.ok { background: var(--good); }
.dot.err { background: var(--danger); }
.dot.busy { background: #f5b942; animation: pulse 0.9s infinite alternate; }

.progress {
  flex: 1 1 140px;
  min-width: 120px;
  height: 8px;
  background: var(--panel-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress .fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s ease; }

.footnote { text-align: center; font-size: 0.8rem; margin-top: 0.75rem; }

/* ================= generation overlay ================= */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  z-index: 50;
}
.gen-box {
  text-align: center;
  max-width: 540px;
  width: calc(100% - 2rem);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
}
.spinner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 4px solid var(--panel-2);
  border-top-color: var(--accent);
  animation: spin 900ms linear infinite;
}
#gen-stage { font-weight: 800; font-size: 1.15rem; }
#gen-quip { min-height: 1.3em; font-style: italic; }
#gen-stream {
  max-width: 100%;
  min-height: 1.2em;
  overflow: hidden;
  white-space: nowrap;
  opacity: 0.5;
  font-size: 0.78rem;
}
#gen-error-msg { color: var(--danger); font-weight: 600; }

/* ================= game screen ================= */
.game-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.game-head h1 { font-size: 1.9rem; letter-spacing: -0.02em; }
.byline { font-size: 0.78rem; color: var(--accent); margin-top: 0.15rem; }

.game-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1.05fr 0.95fr;
  /* 1fr on the last row makes the store's extra height land there,
     so it can't inflate the click row and push the chronicle down */
  grid-template-rows: auto auto 1fr;
  grid-template-areas: "growth balance" "click store" "chron store";
  align-items: start;
}

.growth { grid-area: growth; }
.balance { grid-area: balance; }
.growth, .balance { padding: 0.9rem 1.1rem 0.75rem; }
.graph-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.4rem;
}
.graph-head h2 { font-size: 1rem; }
#growth-canvas, #balance-canvas {
  display: block;
  width: 100%;
  height: 120px;
}

.click-panel {
  grid-area: click;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6rem;
  padding: 2rem 1.25rem 2.4rem;
  overflow: hidden;
}
.hud { text-align: center; }
#currency-count {
  font-size: 3rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
#currency-label { font-size: 1rem; margin-top: 0.35rem; }
.rates { margin-top: 0.5rem; font-size: 0.9rem; color: var(--muted); font-variant-numeric: tabular-nums; }

#big-btn {
  width: 190px;
  height: 190px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: radial-gradient(
    circle at 30% 25%,
    color-mix(in oklab, var(--accent) 55%, white 12%),
    var(--accent) 58%,
    color-mix(in oklab, var(--accent) 60%, black) 100%
  );
  box-shadow:
    0 10px 40px color-mix(in oklab, var(--accent) 45%, transparent),
    inset 0 -6px 18px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  transition: transform 0.07s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#big-btn:hover { transform: scale(1.03); }
#big-btn:active { transform: scale(0.93); }
#click-emoji { font-size: 4.2rem; line-height: 1.15; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3)); }
#click-verb { font-weight: 800; font-size: 1.05rem; color: color-mix(in oklab, var(--accent) 12%, black); }

#particles { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.particle {
  position: absolute;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--text);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: floatUp 0.95s ease-out forwards;
}

.store {
  grid-area: store;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.store h2 { font-size: 1rem; margin: 0.4rem 0 0.1rem; }
.store h2 .small { font-weight: 500; }

#upgrades { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.up-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.6rem 0.4rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: center;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.u-emoji { font-size: 1.5rem; line-height: 1.2; }
.u-name { font-size: 0.75rem; font-weight: 700; line-height: 1.15; }
.u-cost { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.up-tile.afford { border-color: var(--accent); box-shadow: 0 0 12px color-mix(in oklab, var(--accent) 30%, transparent); }
.up-tile:disabled { cursor: default; opacity: 0.55; }
.up-tile.owned {
  opacity: 0.95;
  border-color: color-mix(in oklab, var(--good) 60%, transparent);
  background: color-mix(in oklab, var(--good) 12%, var(--panel-2));
}
.up-tile.owned .u-cost { color: var(--good); }

#generators { display: flex; flex-direction: column; gap: 0.5rem; }
.gen-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.7rem;
  align-items: center;
  padding: 0.6rem 0.7rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.g-emoji { font-size: 1.7rem; width: 2.1rem; text-align: center; }
.g-name { font-weight: 800; font-size: 0.92rem; }
.g-owned { color: var(--accent); font-weight: 800; margin-left: 0.35rem; font-size: 0.85rem; }
.g-desc { font-size: 0.76rem; color: var(--muted); line-height: 1.25; margin-top: 0.1rem; }
.g-nums { text-align: right; font-variant-numeric: tabular-nums; }
.g-cost { font-weight: 800; font-size: 0.9rem; }
.g-rate { font-size: 0.74rem; color: var(--muted); }
.gen-row.afford { border-color: var(--accent); box-shadow: 0 0 12px color-mix(in oklab, var(--accent) 25%, transparent); }
.gen-row:disabled { cursor: default; opacity: 0.55; }
.gen-row.mystery { opacity: 0.7; }

/* Inner spans must never be the click target: their text nodes get replaced
   on store updates, and a vanished mousedown target swallows the click. */
#big-btn *, .gen-row *, .up-tile * { pointer-events: none; }

.chronicle { grid-area: chron; }
.chronicle h2 { font-size: 1rem; }
#chronicle-list {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  font-size: 0.86rem;
}
#chronicle-list li { line-height: 1.35; }
#chronicle-list li strong { color: var(--accent); margin-right: 0.3rem; }
#chronicle-list li.placeholder { color: var(--muted); font-style: italic; }

/* ================= toasts & ambience ================= */
#toasts {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 60;
  max-width: 340px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  font-size: 0.88rem;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  animation: slideIn 0.25s ease;
}
.toast.bye { opacity: 0; transform: translateX(12px); transition: all 0.3s ease; }

#bg-emojis { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
#bg-emojis span {
  position: absolute;
  opacity: 0.07;
  filter: saturate(0.7);
  animation: drift linear infinite alternate;
}

/* ================= keyframes ================= */
@keyframes spin { to { transform: rotate(1turn); } }
@keyframes pulse { to { opacity: 0.35; } }
@keyframes floatUp { to { transform: translateY(-90px); opacity: 0; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes drift {
  from { transform: translate(0, 0) rotate(-6deg); }
  to { transform: translate(30px, -40px) rotate(8deg); }
}

/* ================= responsive & motion ================= */
@media (max-width: 880px) {
  .hero h1 { font-size: 2.2rem; }
  .game-grid { grid-template-columns: 1fr; grid-template-areas: "growth" "balance" "click" "store" "chron"; }
  .continue { flex-direction: column; align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  #bg-emojis span { animation: none; }
  .particle { animation-duration: 0.4s; }
}
