:root,
[data-theme="darcula"] {
  color-scheme: dark;
  --bg: #080907;
  --fg: #d4cdb8;
  --muted: #7a7568;
  --accent: #cc7832;
  --line: #2c2e26;
  --panel: #0c0d0a;
  --hot: #ebe4d2;
}

[data-theme="day"] {
  color-scheme: light;
  --bg: #e6e1d4;
  --fg: #2c2924;
  --muted: #6f6a60;
  --accent: #a85c24;
  --line: #cfc6b4;
  --panel: #f3efe6;
  --hot: #1e1c18;
}

[data-theme="string"] {
  color-scheme: dark;
  --bg: #0c100e;
  --fg: #d5dece;
  --muted: #7e8b78;
  --accent: #6a8759;
  --line: #2a3328;
  --panel: #101512;
  --hot: #e7f0e0;
}

[data-theme="number"] {
  color-scheme: dark;
  --bg: #0c1016;
  --fg: #d5deea;
  --muted: #7d8ba0;
  --accent: #6897bb;
  --line: #2a3344;
  --panel: #10151c;
  --hot: #e7eef6;
}

[data-theme="function"] {
  color-scheme: dark;
  --bg: #100e0a;
  --fg: #e6dcc4;
  --muted: #8d8168;
  --accent: #ffc66d;
  --line: #332e22;
  --panel: #16130e;
  --hot: #fff6e0;
}

[data-theme="select"] {
  color-scheme: dark;
  --bg: #0b1220;
  --fg: #dce6f2;
  --muted: #8496b0;
  --accent: #ffc66d;
  --line: #24344c;
  --panel: #10192a;
  --hot: #f3f7fc;
}

button, [role="button"] { cursor: pointer; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.45;
  overflow: hidden;
}

::selection { background: var(--accent); color: var(--bg); }

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

a { color: inherit; text-decoration: none; }

button {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  padding: 0;
}

.desk {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--bg);
  color: var(--fg);
  isolation: isolate;
}

.top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 8px;
}

.top h1 {
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 22px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid var(--fg);
  font-size: 9px;
  letter-spacing: -0.04em;
}

.top a:hover { color: var(--accent); }

.top-nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.top-nav a {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
}

.stage {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(240px, 34vw) minmax(0, 1fr);
  min-height: 0;
  border-top: 1px solid var(--line);
}

.wheel {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  touch-action: none;
}

.wheel-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.wheel-svg path {
  fill: none;
  stroke: var(--fg);
  stroke-width: 0.35;
  opacity: 0.85;
}

.spark {
  position: absolute;
  width: 3px;
  height: 3px;
  margin: -1px 0 0 -1px;
  background: var(--hot);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--hot);
  animation: spark 2.8s ease-in-out infinite;
  pointer-events: none;
}

@keyframes spark {
  0%, 100% { opacity: 0.15; }
  45% { opacity: 1; }
}

.arc-date, .arc-hint {
  position: absolute;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  pointer-events: none;
}

.arc-date-a { top: 10px; left: 16px; }
.arc-date-b { bottom: 28px; left: 16px; }
.arc-hint { bottom: 10px; left: 16px; }

.card {
  position: absolute;
  width: 150px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.card em {
  font-style: normal;
  color: var(--muted);
  font-size: 10px;
  opacity: 0;
}
.card.is-hot em { opacity: 1; }

.card-face {
  width: 100%;
  min-height: 96px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  padding: 8px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 2px;
  color: var(--fg);
}

.card.is-hot .card-face {
  border-color: var(--fg);
  box-shadow: 8px 0 0 -7px var(--fg);
}

.link-face {
  justify-content: flex-end;
  font-size: 13px;
  min-height: 96px;
}

.link-face:hover { color: var(--accent); }

.theme-face {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 0;
  min-height: 112px;
}

.swatch {
  text-align: left;
  padding: 6px 8px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  min-height: 36px;
}

.swatch:nth-child(2n) { border-right: 0; }
.swatch:nth-last-child(-n + 2) { border-bottom: 0; }
.swatch[aria-pressed="true"] { color: var(--bg); background: var(--accent); }
.swatch-darcula[aria-pressed="false"]:hover { color: #cc7832; }
.swatch-day[aria-pressed="false"]:hover { color: #a85c24; }
.swatch-string[aria-pressed="false"]:hover { color: #6a8759; }
.swatch-number[aria-pressed="false"]:hover { color: #6897bb; }
.swatch-function[aria-pressed="false"]:hover { color: #ffc66d; }
.swatch-select[aria-pressed="false"]:hover { color: #ffc66d; }

.term {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 16px 22px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panels {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(180px, 0.7fr) minmax(140px, 0.48fr);
  gap: 12px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.panel {
  border: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  background: color-mix(in srgb, var(--panel) 70%, transparent);
}

.root-panel {
  display: flex;
  flex-direction: column;
}

.panel header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

.root-stage {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 0;
  flex: 1;
}

.root-copy {
  grid-column: 1;
  grid-row: 1;
  padding: 8px 10px 0;
}

.root-copy p,
.root-foot,
.echo-note,
.card-id {
  margin: 0;
}

.root-copy p { color: var(--muted); font-size: 11px; }

.root-svg {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  height: 100%;
  min-height: 180px;
  background-image:
    linear-gradient(to right, var(--line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line) 1px, transparent 1px);
  background-size: 22px 22px;
}

.root-svg line { stroke: var(--line); stroke-width: 0.4; }
.seg-line { fill: none; stroke: var(--fg); stroke-width: 0.65; transition: opacity 280ms ease; }
.seg-hit { fill: none; stroke: transparent; stroke-width: 4.5; }
.seg.eaten .seg-line { opacity: 0; }

.root-foot {
  grid-column: 1;
  grid-row: 3;
  padding: 4px 10px 8px;
  color: var(--muted);
  font-size: 11px;
}

.root-stats {
  grid-column: 2;
  grid-row: 1 / span 3;
  margin: 0;
  border-left: 1px solid var(--line);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.root-stats div { display: flex; justify-content: space-between; gap: 8px; }
.root-stats dt { color: var(--muted); }
.root-stats dd { margin: 0; }

.echo-svg { width: 100%; height: 54px; display: block; border-bottom: 1px solid var(--line); }
.echo-svg polyline { fill: none; stroke: var(--fg); stroke-width: 1.2; }

.echo-note, .card-id { padding: 8px 10px; color: var(--muted); }
.card-id { color: var(--fg); border-top: 1px solid var(--line); }

.eye-svg { width: 100%; height: auto; display: block; color: var(--fg); }
.eye-svg circle { fill: var(--muted); }
.eye-svg rect { fill: none; stroke: var(--fg); stroke-width: 0.8; }

@keyframes blink {
  50% { opacity: 0; }
}

.glyph { transition: opacity 90ms linear; }
.glyph.eaten { opacity: 0; }

.worm {
  position: fixed;
  left: 0;
  top: 0;
  width: 13px;
  height: 13px;
  margin: -7px 0 0 -7px;
  border: 1px solid var(--hot);
  pointer-events: none;
  z-index: 70;
  opacity: 0;
  transition: width 80ms linear, height 80ms linear, border-color 80ms linear, opacity 160ms linear;
}

.worm.live { opacity: 1; }
.worm.live.ghost { opacity: 0.35; }
.worm.feeding {
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-color: var(--accent);
}


.eye-panel {
  background: transparent;
}

.sauron {
  position: fixed;
  right: 26px;
  bottom: 22px;
  z-index: 0;
  pointer-events: none;
  user-select: none;
}

.sauron-art {
  margin: 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 10px;
  line-height: 1.02;
  color: color-mix(in srgb, var(--fg) 72%, var(--accent));
  text-shadow: 0 0 12px color-mix(in srgb, var(--accent) 50%, transparent);
  transform-origin: 50% 52%;
  animation: sauron-watch 3.2s ease-in-out infinite;
}

.sauron-art b {
  font-weight: 500;
  color: var(--hot);
  text-shadow:
    0 0 2px var(--hot),
    0 0 8px var(--accent),
    0 0 16px var(--accent);
}

@keyframes sauron-watch {
  0%, 100% { opacity: 0.82; }
  50% { opacity: 1; }
}

html.page-hidden .spark,
html.page-hidden .sauron-art {
  animation-play-state: paused;
}

@media (max-width: 860px) {
  body { overflow: auto; overflow-x: hidden; }
  .desk { height: auto; min-height: 100dvh; overflow: visible; max-width: 100%; }
  .stage { display: flex; flex-direction: column; width: 100%; min-width: 0; max-width: 100%; }
  .wheel {
    touch-action: pan-x;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 16px 18px;
    height: auto;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .wheel-svg, .spark, .arc-date, .arc-hint { display: none; }
  .card {
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    opacity: 1;
    visibility: visible;
    flex: 0 0 220px;
    width: 220px;
  }
  .swatch { min-height: 44px; font-size: 12px; }
  .panels { grid-template-columns: 1fr; }
  .eye-panel { display: none; }
  .root-stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto auto;
  }
  .root-svg { height: auto; min-height: 220px; max-height: 280px; }
  .root-stats {
    grid-column: 1;
    grid-row: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }
  .term { overflow: visible; }
  .top-nav a { min-height: 44px; }
  .sauron { right: 14px; bottom: 14px; }
  .sauron-art { font-size: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .spark, .glyph, .seg-line, .worm, .sauron-art { animation: none; transition: none; }
}
