:root {
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --radius: 13px;
}

/* ── themes ─────────────────────────────────────────────────── */
html[data-theme="dark"] {            /* Dark periwinkle — the cozy twin of the light theme */
  --bg: #161528; --surface: #1e1d36; --overlay: #2a2849;
  --text: #e3e2f6; --muted: #9d9bc8; --subtle: #6e6c9c;
  --line: #2f2d50;
  --accent: #aaa6f7; --ok: #87cfdd; --warn: #f0c98a; --rose: #e3b1d6; --love: #ef7da6; --pine: #7ba6ea;
  --kbd-bg: #2a2849;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
html[data-theme="light"] {           /* Periwinkle */
  --bg: #f2f3fc; --surface: #e9ebfa; --overlay: #e2e4f6;
  --text: #45456a; --muted: #6c6b93; --subtle: #8d8cb0;
  --line: #dde0f4;
  --accent: #6c63d8; --ok: #3f8fa6; --warn: #bd7b2c; --rose: #b5658f; --love: #d24f7a; --pine: #2f6f86;
  --kbd-bg: #e2e4f6;
  --shadow: 0 24px 60px rgba(70, 70, 120, 0.18);
}
html[data-theme="classic"] {         /* Rainbow-Apple era — flat platinum + the six */
  --bg: #e7e5dc; --surface: #d8d5c8; --overlay: #cdc9ba;
  --text: #1c1c19; --muted: #56544b; --subtle: #87857a;
  --line: #a9a698;
  --accent: #7a3d97; --ok: #3a9e3a; --warn: #e07b00; --rose: #b0359a; --love: #d6322c; --pine: #1f7fc2;
  --kbd-bg: #dedbce;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.18);   /* flat: a hairline, not a soft drop */
}
html[data-theme="mono"] {            /* Green phosphor — opt-in via `theme mono` */
  --bg: #001100; --surface: #002600; --overlay: #003a00;
  --text: #33ff66; --muted: #1f9a48; --subtle: #127a36;
  --line: #0a4a1f;
  --accent: #66ff99; --ok: #33ff66; --warn: #9dff5a; --rose: #5affc0; --love: #aaff33; --pine: #2fd07a;
  --kbd-bg: #002a10;
  --shadow: 0 0 0 1px rgba(51, 255, 102, 0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: clamp(8px, 3vw, 40px);
  -webkit-font-smoothing: antialiased;
  transition: background 0.35s ease, color 0.35s ease;
}
/* a calm warm wash behind the window — the cozy opposite of dread-rain */
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(58% 50% at 50% 30%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 72%);
}

/* ── the macOS window ───────────────────────────────────────── */
.window {
  position: relative; z-index: 1;
  width: min(960px, 92vw);
  height: min(82svh, 720px);
  display: flex; flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: width 0.4s ease, height 0.4s ease;
}
/* 🟢 zoom — bigger within the browser (not OS fullscreen) */
.window.zoomed { width: min(1400px, 96vw); height: 94svh; }
.titlebar {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.8rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.lights { display: flex; gap: 8px; align-items: center; }
.lt {
  width: 12px; height: 12px; border-radius: 50%;
  padding: 0; border: 0; appearance: none; -webkit-appearance: none;
  display: inline-block; cursor: pointer;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.lt.r { background: #ff5f57; } .lt.y { background: #febc2e; } .lt.g { background: #28c840; }
.lt:hover { filter: brightness(1.18); transform: scale(1.12); }
.lt:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.title {
  text-align: center; font-family: var(--font-ui); font-size: 12.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.themebtn {
  justify-self: end; cursor: pointer;
  border: 1px solid var(--line); background: var(--overlay); color: var(--accent);
  border-radius: 999px; width: 30px; height: 30px; line-height: 1; font-size: 15px;
  display: grid; place-items: center;
  transition: border-color 0.2s ease, transform 0.2s ease;
}
.themebtn:hover { border-color: color-mix(in srgb, var(--accent) 55%, transparent); transform: translateY(-1px); }
.themebtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── the scrolling console (output flows top-down; input pins at bottom) ── */
.console { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.term {
  font-size: clamp(13px, 1.1vw + 7px, 15px);
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap; word-break: break-word;
  padding: 14px 16px 0;
  cursor: text;
  -webkit-user-select: text; user-select: text;
}
.cmdline {
  display: flex; align-items: baseline; gap: 0.5ch;
  padding: 2px 16px 14px;
  font-size: clamp(13px, 1.1vw + 7px, 15px);
}
.cmdline .ps { color: var(--accent); white-space: nowrap; }
.cmdline input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  font: inherit; color: var(--text); caret-color: var(--accent);
}

/* ── inline output helpers ──────────────────────────────────── */
.welcome { color: var(--accent); font-weight: 700; }
.kbd {
  font-family: var(--font-mono); background: var(--kbd-bg); color: var(--accent);
  border: 1px solid var(--line); border-radius: 6px; padding: 0 0.4em; font-size: 0.92em;
}
.c-accent { color: var(--accent); } .c-ok { color: var(--ok); } .c-warn { color: var(--warn); }
.c-muted { color: var(--muted); } .c-rose { color: var(--rose); } .c-love { color: var(--love); }
.c-pine { color: var(--pine); } .c-text { color: var(--text); }
.bold { font-weight: 700; }

@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.spark { display: inline-block; animation: pop 0.5s ease; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 2rem; text-align: center; color: var(--accent); z-index: 5; }
.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; }

/* ── the arcade stage (a canvas game replaces the console) ───── */
.game-stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.game-hud {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 6px 14px; font-family: var(--font-ui); font-size: 12.5px;
  color: var(--muted); background: var(--surface); border-bottom: 1px solid var(--line);
}
.game-hud-hint { color: var(--subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-canvas { flex: 1 1 auto; width: 100%; min-height: 0; display: block; touch-action: none; background: var(--bg); }

/* ── 🟡 minimize → a calm, on-theme ambient scene ───────────── */
/* --amb-glow (0–1) and --amb-speed (0.5–2) are tuned live by the corner panel. */
.ambient {
  --amb-glow: 0.22; --amb-speed: 1;
  position: fixed; inset: 0; z-index: 0; overflow: hidden; cursor: pointer;
  /* a touch darker than the terminal — the scene settles down as it fades in */
  background: color-mix(in srgb, var(--bg) 86%, #000);
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity 1.7s ease, visibility 1.7s ease;
}
body.minimized .ambient { opacity: 1; visibility: visible; pointer-events: auto; }
body.minimized .console, body.minimized .game-stage { display: none; }
body.minimized .window { height: auto; }
/* perf: the (blurred, large) ambient animations only run while it's on screen */
.ambient .blob, .ambient .mote { animation-play-state: paused; }
body.minimized .ambient .blob, body.minimized .ambient .mote { animation-play-state: running; }

/* lava-lamp glow: huge, soft, slowly drifting periwinkle light. heavy blur keeps
   it band-free; opacity follows the glow slider. */
.ambient .blob {
  position: absolute; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--accent) 65%, transparent), transparent 72%);
  filter: blur(72px);
  opacity: calc(0.55 * var(--amb-glow));
  animation-name: lava; animation-timing-function: ease-in-out;
  animation-iteration-count: infinite; animation-direction: alternate;
  animation-duration: calc(var(--lava, 60s) / var(--amb-speed));
  will-change: transform;
}
.ambient .b0 { width: 54vmax; height: 54vmax; left: -10vmax; bottom: -16vmax; --lava: 56s; }
.ambient .b1 { width: 46vmax; height: 46vmax; right: -12vmax; top: -14vmax; --lava: 72s; animation-delay: -24s; }
.ambient .b2 { width: 40vmax; height: 40vmax; left: 38%; bottom: -20vmax; --lava: 64s; animation-delay: -44s; }
@keyframes lava {
  0%   { transform: translate(0, 0) scale(1); }
  50%  { transform: translate(6vmax, -7vmax) scale(1.14); }
  100% { transform: translate(-4vmax, 4vmax) scale(0.95); }
}

/* the gentle particles — the star of the scene; they ease in after the glow */
.ambient .motes { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 2.6s ease; }
body.minimized .ambient .motes { opacity: 1; }
.ambient .mote {
  position: absolute; bottom: -12px; width: 6px; height: 6px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 72%, var(--text));
  box-shadow: 0 0 calc(10px * var(--amb-glow)) color-mix(in srgb, var(--accent) 55%, transparent);
  filter: blur(0.4px); opacity: 0;
  animation: mote-rise calc(var(--d, 12s) / var(--amb-speed)) linear var(--delay, 0s) infinite;
  will-change: transform, opacity;
}
@keyframes mote-rise {
  0% { transform: translate(0, 0); opacity: 0; }
  14% { opacity: calc(var(--mo, 0.6) * (0.45 + var(--amb-glow))); }
  85% { opacity: calc(var(--mo, 0.6) * (0.45 + var(--amb-glow))); }
  100% { transform: translate(var(--dx, 0), -100svh); opacity: 0; }
}
/* the corner adjustments panel (only while minimized; it lives inside .ambient) */
.ambient-controls {
  position: absolute; right: clamp(12px, 3vw, 28px); bottom: clamp(12px, 3vw, 28px);
  z-index: 2; width: 190px; max-width: 60vw; overflow: hidden;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  cursor: default;
  font-family: var(--font-ui); font-size: 12px; color: var(--muted);
  transition: opacity 0.7s ease;
}
/* after the first interaction, the collapsed pill fades to barely-there when idle;
   any hover/focus brings it right back */
.ambient-controls.ghosted { opacity: 0.16; }
.ambient-controls.ghosted:hover, .ambient-controls.ghosted:focus-within { opacity: 1; }
.ambient-controls .ac-toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 10px 14px; cursor: pointer;
  background: transparent; border: 0; font: inherit;
  color: var(--accent); font-weight: 600; letter-spacing: 0.04em;
}
.ambient-controls .ac-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.ambient-controls .ac-chev { color: var(--muted); font-size: 10px; }
.ambient-controls .ac-body {
  display: flex; flex-direction: column; gap: 9px;
  max-height: 0; opacity: 0; padding: 0 14px;
  transition: max-height 0.32s ease, opacity 0.3s ease, padding 0.32s ease;
}
.ambient-controls.open .ac-body { max-height: 240px; opacity: 1; padding: 2px 14px 14px; }
.ambient-controls .ac-row { display: flex; flex-direction: column; gap: 3px; cursor: default; }
.ambient-controls .ac-row span { letter-spacing: 0.03em; }
.ambient-controls input[type="range"] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.ambient-hint {
  position: absolute; left: 0; right: 0; bottom: 8%; text-align: center;
  color: var(--muted); font-family: var(--font-ui); font-size: 13px; letter-spacing: 0.02em;
}

/* ── skin chrome: classic (rainbow-Apple) + mono (green phosphor) ──── */
/* the titlebar theme button shows the current skin: ☾ / ☀ glyphs, a rainbow chip
   for classic, a green chip for mono */
.themebtn.tb-classic {
  background-image: linear-gradient(135deg, #61bb46, #fdb827, #f5821f, #e03a3e, #963d97, #009ddc);
  border-color: rgba(0, 0, 0, 0.18);
}
.themebtn.tb-mono { background: #001100; color: #33ff66; border-color: #0a4a1f; }

/* classic: a crisp six-stripe rainbow under the titlebar (the logo, flattened) */
[data-theme="classic"] .titlebar { position: relative; }
[data-theme="classic"] .titlebar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: linear-gradient(90deg, #61bb46 0 16.667%, #fdb827 0 33.333%, #f5821f 0 50%, #e03a3e 0 66.667%, #963d97 0 83.333%, #009ddc 0);
}
/* classic: the minimized ambient glow goes full rainbow */
[data-theme="classic"] .ambient .b0 { background: radial-gradient(closest-side, rgba(97, 187, 70, 0.60), transparent 72%); }
[data-theme="classic"] .ambient .b1 { background: radial-gradient(closest-side, rgba(245, 130, 31, 0.55), transparent 72%); }
[data-theme="classic"] .ambient .b2 { background: radial-gradient(closest-side, rgba(0, 157, 220, 0.55), transparent 72%); }

/* mono: phosphor glow on text + faint static scanlines (no motion, CRT feel) */
[data-theme="mono"] .term,
[data-theme="mono"] .cmdline input { text-shadow: 0 0 4px rgba(51, 255, 102, 0.35); }
[data-theme="mono"] .window::after {
  content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none;
  background: repeating-linear-gradient(rgba(0, 0, 0, 0) 0 2px, rgba(0, 0, 0, 0.16) 2px 3px);
}

/* ── the /root → /cafe crossing (plays on every café load) ───────────
   A deterministic, API-free reveal: the window gently rises in from the page's
   own dark background. Paired with /root fading out to this same background on
   the way over, the crossing reads as one smooth fade — no hard cut, no flash,
   and identical on the first load and every load after. */
.window { animation: cafe-rise-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both; }
@keyframes cafe-rise-in {
  from { opacity: 0; transform: translateY(10px) scale(0.992); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 560px) {
  .window { width: 94vw; height: min(86svh, 720px); }
  .window.zoomed { width: 98vw; height: 96svh; }
  .title { font-size: 11.5px; }
  body { padding: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  .spark { animation: none; }
  .ambient .mote, .ambient .blob { animation: none; }
  .window { animation: none; }
  * { transition: none !important; }
}
