:root {
  color-scheme: dark;
  --bg: #17130e;
  --panel: rgba(31, 24, 17, .96);
  --panel-line: rgba(231, 173, 99, .28);
  --ink: #f5e8ca;
  --dim: rgba(245, 232, 202, .62);
  --accent: #e7ad63;
  --control-bg: rgba(20, 15, 10, .44);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
body[data-theme="ambient"] {
  --bg: #040912; --panel: rgba(4, 9, 18, .96); --panel-line: rgba(92, 217, 255, .3);
  --ink: #d9f5ff; --dim: rgba(217, 245, 255, .58); --accent: #5cd9ff; --control-bg: rgba(4, 9, 18, .45);
}
body[data-theme="paper"] {
  color-scheme: light;
  --bg: #eee4cc; --panel: rgba(245, 236, 216, .97); --panel-line: rgba(91, 51, 36, .28);
  --ink: #34231b; --dim: rgba(52, 35, 27, .62); --accent: #8a3b2d; --control-bg: rgba(238, 228, 204, .64);
}

.stage, #farm { position: fixed; inset: 0; width: 100%; height: 100%; }
#farm { display: block; touch-action: none; }
body.commanding #farm { cursor: crosshair; }

.chrome {
  position: fixed;
  z-index: 10;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  opacity: 1;
  transition: opacity .45s ease, transform .45s ease;
}
.idle .chrome { opacity: .16; transform: translateY(-3px); }
.preview .chrome, .preview .specimen-label { display: none; }

.icon-button, .dialog-close {
  appearance: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: var(--control-bg);
  color: var(--dim);
  font: 700 16px/1 "JetBrains Mono", monospace;
  cursor: pointer;
  backdrop-filter: blur(7px);
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.icon-button svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; }
.dice-button svg circle { fill: currentColor; stroke: none; }
.dice-button.active { color: var(--accent); border-color: var(--panel-line); }
.icon-button:hover, .dialog-close:hover { color: var(--accent); border-color: var(--panel-line); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.specimen-label {
  position: fixed;
  z-index: 6;
  left: max(16px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-left: 1px solid var(--accent);
  color: var(--dim);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  font-size: clamp(10px, 1vw, 13px);
  letter-spacing: .14em;
  font-variant-numeric: tabular-nums;
}
.specimen-label[hidden] { display: none; }
#demoLabel { color: var(--accent); font-size: .72em; letter-spacing: .18em; }

dialog {
  width: min(92vw, 580px);
  max-height: min(88dvh, 760px);
  padding: 0;
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, .58);
}
dialog::backdrop { background: rgba(2, 4, 6, .68); backdrop-filter: blur(5px); }
.dialog-card { position: relative; padding: clamp(22px, 5vw, 38px); }
.dialog-close { position: absolute; top: 12px; right: 12px; background: transparent; font-size: 23px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 10px; letter-spacing: .24em; }
.dialog-card .dialog-title { margin: 0 44px 25px 0; font-size: clamp(24px, 5vw, 34px); line-height: 1.05; letter-spacing: -.04em; }
.dialog-card .section-title { margin: 25px 0 7px; color: var(--accent); font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.dialog-card p:not(.eyebrow) { margin: 0 0 12px; color: var(--dim); font-family: "Source Serif 4", Georgia, serif; font-size: 16px; line-height: 1.62; }
.dialog-card strong { color: var(--ink); font-weight: 500; }

.settings-grid { display: grid; grid-template-columns: minmax(120px, .75fr) minmax(180px, 1.25fr); gap: 14px 18px; align-items: center; }
.settings-grid > label:not(.check-row) { color: var(--dim); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
select {
  width: 100%; min-height: 44px; padding: 8px 34px 8px 11px;
  border: 1px solid var(--panel-line); border-radius: 4px;
  color: var(--ink); background: var(--bg); font: 500 13px/1.2 "JetBrains Mono", monospace;
}
select:disabled { opacity: .48; cursor: not-allowed; }
.check-row { grid-column: 1 / -1; display: flex; align-items: center; gap: 11px; min-height: 44px; color: var(--dim); font-size: 12px; cursor: pointer; }
.check-row input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 25px; padding-top: 18px; border-top: 1px solid var(--panel-line); }
.text-button {
  min-height: 44px; padding: 9px 14px; border: 1px solid var(--panel-line); border-radius: 4px;
  color: var(--dim); background: transparent; font: 600 11px/1.2 "JetBrains Mono", monospace; cursor: pointer;
}
.text-button.primary { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.about-links { display: flex; gap: 22px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--panel-line); }
.about-links a { color: var(--accent); font-size: 11px; letter-spacing: .08em; text-decoration: none; text-transform: uppercase; }

.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; }

@media (max-width: 560px) {
  .icon-button { width: 48px; height: 48px; }
  .settings-grid { grid-template-columns: 1fr; gap: 7px; }
  .settings-grid select { margin-bottom: 8px; }
  .dialog-actions { flex-direction: column-reverse; }
  .text-button { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: .01ms !important; }
}
@media (prefers-contrast: more) {
  .icon-button, select, .text-button, dialog { border-width: 2px; }
  .chrome { opacity: 1 !important; transform: none !important; }
}
@media (forced-colors: active) {
  .icon-button, .dialog-close, select, .text-button, dialog { border: 1px solid ButtonText; forced-color-adjust: auto; }
  button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid Highlight; }
}
@media (min-width: 1900px), (min-height: 1900px) {
  .chrome { top: max(20px, env(safe-area-inset-top)); right: max(20px, env(safe-area-inset-right)); gap: 10px; }
  .icon-button { width: 60px; height: 60px; font-size: 24px; }
  .icon-button svg { width: 28px; height: 28px; }
  .specimen-label { font-size: 19px; padding: 11px 15px; }
}
