/* TERRARIUM — styles.css
   The Lab's retro-arcade dark look (tokens shared with sandfall), with a
   greenhouse accent: leaf green for titles, a sky glow behind the jar
   that follows the jar's own day and night. */

/* ---------- fonts (self-hosted, shared with the lab root) ---------- */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

/* ---------- tokens ---------- */

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;
  --leaf: #4fdc6c;
  --soil: #8a5c36;
  --water: #2f8fd8;
  --vapor: #9fc3d6;
  --outside: #07070e;

  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(79, 220, 108, 0.06), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(79, 220, 108, 0.3); }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--text);
}

/* ---------- header ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(20px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(79, 220, 108, 0.55), 3px 3px 0 var(--magenta);
  overflow-wrap: anywhere;
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--leaf); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
  padding: 16px var(--space-gutter) 72px;
}

.how-line {
  margin: 12px 0 16px;
  font-size: 13px;
  color: var(--dim);
}

.sim-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}

/* ---------- stage ---------- */

.stage-wrap { min-width: 0; display: flex; flex-direction: column; gap: 8px; }

/* "this tab is not saving" notice above the jar */
.jar-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 0 18px rgba(255, 200, 87, 0.08);
}
.jar-notice p { margin: 0; flex: 1 1 240px; font-size: 13px; line-height: 1.5; color: var(--text); }
.jar-notice-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.jar-notice .btn { font-size: 11.5px; padding: 8px 12px; }

.clock-hud {
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  line-height: 1.6;
  color: var(--gold);
  text-align: center;
}

.stage {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 12px 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--outside);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

/* sky glow behind the glass: warm by day, cool by night (opacity only) */
.stage::before,
.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  transition: opacity 1.2s ease;
}
.stage::before { background: radial-gradient(60% 55% at 50% 30%, rgba(255, 200, 87, 0.16), transparent 70%); }
.stage::after { background: radial-gradient(60% 55% at 50% 30%, rgba(80, 110, 255, 0.14), transparent 70%); opacity: 0; }
.stage[data-sky="night"]::before { opacity: 0; }
.stage[data-sky="night"]::after { opacity: 1; }

#jarCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}

.brush-ring {
  position: absolute;
  top: 0; left: 0;
  border: 1px solid var(--cyan);
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(69, 240, 255, 0.35), inset 0 0 6px rgba(69, 240, 255, 0.2);
  pointer-events: none;
  will-change: transform;
}

.play-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 20px;
  background: rgba(5, 5, 12, 0.78);
  pointer-events: none;
}
.play-hint .btn { pointer-events: auto; }
.play-hint p {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--dim);
  max-width: 380px;
}

/* ---------- panels ---------- */

.controls { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.panel-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 1px;
  line-height: 1.6;
  color: var(--leaf);
  text-shadow: 0 0 8px rgba(79, 220, 108, 0.4);
}

.note { margin: 0; font-size: 12px; color: var(--dim); line-height: 1.5; }

/* ---------- toolbar ---------- */

.tools-panel { margin-bottom: 12px; gap: 14px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  max-width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11.5px;
  letter-spacing: 0.5px;
  line-height: 1.2;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s, transform 0.12s var(--ease-out);
}
.tool-btn:hover {
  border-color: var(--swatch, var(--cyan));
  color: var(--text);
  box-shadow: 0 0 12px color-mix(in srgb, var(--swatch, var(--cyan)) 28%, transparent);
}
.tool-btn[aria-pressed="true"] {
  border-color: var(--cyan);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--swatch, var(--cyan)), 0 0 0 2px rgba(69, 240, 255, 0.2), 0 0 16px rgba(69, 240, 255, 0.28);
}
.tool-btn:active { transform: translateY(1px); }
.tool-btn kbd { color: var(--dim); }

.tool-swatch {
  flex: 0 0 auto;
  width: 14px; height: 14px;
  background: var(--swatch, var(--cyan));
  border: 1px solid rgba(255, 255, 255, 0.25);
}
.tool-btn[data-tool="erase"] .tool-swatch {
  background:
    linear-gradient(45deg, transparent 42%, var(--red) 42%, var(--red) 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, var(--red) 42%, var(--red) 58%, transparent 58%),
    var(--bg);
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}
.btn:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--leaf); border-color: var(--leaf); color: #05050d; }
.btn-primary:hover { border-color: var(--leaf); box-shadow: 0 0 18px rgba(79, 220, 108, 0.5); }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 11px; padding: 14px 20px; }
.btn.is-on { border-color: var(--gold); color: var(--gold); box-shadow: inset 0 0 10px rgba(255, 200, 87, 0.12); }

.ctrl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ctrl-wide { grid-column: 1 / -1; }

.field-row { display: flex; align-items: center; gap: 10px; }
.field-row > label { flex: 0 0 auto; font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--dim); }
input[type="range"] { flex: 1; min-width: 0; accent-color: var(--leaf); }
#brushVal { font-family: var(--mono); font-size: 13px; color: var(--gold); min-width: 24px; text-align: right; }

/* ---------- jar panel ---------- */

.seed-line {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
}
.seed-line strong { font-family: var(--pixel); font-size: 11px; font-weight: 400; color: var(--gold); letter-spacing: 2px; }

.share-out {
  width: 100%;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 10px;
}

/* ---------- water cycle ---------- */

.cycle-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cycle-list li {
  display: grid;
  grid-template-columns: minmax(0, 9.5em) minmax(0, 1fr) 3.5em;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}
.cycle-name { overflow-wrap: anywhere; }
.cycle-bar { position: relative; height: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.cycle-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 0.4s var(--ease-out);
}
.fill-pool { background: var(--water); }
.fill-soil { background: var(--soil); }
.fill-plants { background: var(--leaf); }
.fill-air { background: var(--vapor); }
.cycle-list output { text-align: right; color: var(--text); }
.cycle-life { color: var(--text); }

/* ---------- field notes ---------- */

.notes-panel { margin-top: 24px; }
.notes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.notes-list li {
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 3px solid var(--leaf);
  border-radius: 6px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.55;
}
.notes-list p { margin: 0; }
.notes-list .source { margin-top: 8px; font-size: 12px; color: var(--dim); overflow-wrap: anywhere; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- dialog ---------- */

.dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  max-width: min(440px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(5, 5, 12, 0.72); }
.dialog-title { margin: 0 0 12px; font-family: var(--pixel); font-size: 12px; line-height: 1.6; color: var(--leaf); }
.dialog p { margin: 0 0 14px; color: var(--dim); line-height: 1.55; }
.dialog-label { display: block; margin-bottom: 6px; font-family: var(--mono); font-size: 11px; letter-spacing: 1px; color: var(--dim); }
.seed-in {
  width: 100%;
  margin-bottom: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--gold);
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 10px 12px;
}
.dialog .dialog-error { color: var(--red); margin-top: -6px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer p { margin: 4px 0; }
.site-footer .privacy-note { font-size: 12.5px; }
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .sim-layout { grid-template-columns: 1fr; }
  .controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (pointer: coarse) {
  .tool-btn { min-height: 48px; }
  .btn { min-height: 44px; }
}

/* right-drag, Space, [ ] and Tab/Enter mean nothing on a touch screen */
@media (hover: none) and (pointer: coarse) {
  .hint-fine { display: none; }
}

/* Phones: the jar comes first, straight under the header, with the tools
   right below it; the rest follows. .sim-layout dissolves so its two
   children can be ordered among main's own. */
@media (max-width: 600px) {
  main { display: flex; flex-direction: column; gap: 14px; }
  .sim-layout { display: contents; }
  .stage-wrap { order: 1; }
  .tools-panel { order: 2; margin: 0; }
  .how-line { order: 3; margin: 0; }
  .controls { order: 4; grid-template-columns: 1fr; }
  .notes-panel { order: 5; margin-top: 10px; }
  .notes-list { grid-template-columns: 1fr; }
  .stage { padding: 8px 0; }
  .site-header { padding-top: 18px; gap: 14px; }
  .jar-notice { padding: 10px 12px; gap: 8px; }
  .jar-notice-actions { display: grid; grid-template-columns: 1fr 1fr; width: 100%; }
  .jar-notice .btn { padding: 8px; font-size: 11px; line-height: 1.3; }
}

@media (max-width: 380px) {
  .ctrl-grid { grid-template-columns: 1fr; }
  .tool-btn { padding: 8px; gap: 6px; }
  .wordmark { letter-spacing: 1px; }
  .cycle-list li { grid-template-columns: minmax(0, 7.5em) minmax(0, 1fr) 3.2em; gap: 8px; }
}

/* ---------- reduced motion: kill looping/auto animation ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
}
