/* VN system-menu theme. Replaces style.css (kept for rollback). */

:root {
  --ink: #09080d;
  --ink-2: #110f18;
  --glass: rgba(16, 14, 23, 0.8);
  --paper: #ece5d6;
  --muted: #958d7e;
  --faint: #5d574c;
  --gold: #c8b285;
  --gold-hi: #f2e3bf;
  --rule: rgba(200, 178, 133, 0.32);
  --rule-faint: rgba(200, 178, 133, 0.14);
  --blood: #d8456f;
  --serif: "Cormorant Garamond", "EB Garamond", Georgia, serif;
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html { background: var(--ink); }

body {
  color: var(--paper);
  font: 500 17px/1.45 var(--serif);
  min-height: 100vh;
  background: radial-gradient(120% 85% at 50% 0%, #19152a 0%, #0d0b13 55%, #070609 100%) no-repeat var(--ink);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Faint scanlines and paper grain over the whole page. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 3px),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 0 auto;
  padding: 22px 28px 36px;
}

.jp {
  font-family: var(--mincho);
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: none;
  color: var(--gold);
}

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

.top {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin-bottom: 18px;
}

.title {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 14px;
  font: 600 15px/1.2 var(--serif);
  letter-spacing: 0.42em;
  text-transform: uppercase;
}

.title .jp { font-size: 13px; opacity: 0.85; }

.tag { margin: 0; color: var(--muted); font-style: italic; font-weight: 400; font-size: 16px; }

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

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

.stage { min-width: 0; }

.frame-wrap { width: 100%; display: flex; justify-content: center; }

.frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #060509;
  border: 1px solid var(--rule);
  box-shadow: 0 0 0 4px rgba(9, 8, 13, 0.92), 0 0 0 5px var(--rule-faint), 0 30px 80px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  touch-action: none;
}

.frame.loaded { cursor: grab; aspect-ratio: auto; }
.frame.dragging { cursor: grabbing; }

.layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { pointer-events: none; }

/* Corner brackets shared by the preview frame and the panel window. */
.frame::after,
.window::before {
  content: "";
  position: absolute;
  inset: 8px;
  z-index: 2;
  pointer-events: none;
  background:
    linear-gradient(var(--gold), var(--gold)) left top / 14px 1px,
    linear-gradient(var(--gold), var(--gold)) left top / 1px 14px,
    linear-gradient(var(--gold), var(--gold)) right top / 14px 1px,
    linear-gradient(var(--gold), var(--gold)) right top / 1px 14px,
    linear-gradient(var(--gold), var(--gold)) left bottom / 14px 1px,
    linear-gradient(var(--gold), var(--gold)) left bottom / 1px 14px,
    linear-gradient(var(--gold), var(--gold)) right bottom / 14px 1px,
    linear-gradient(var(--gold), var(--gold)) right bottom / 1px 14px;
  background-repeat: no-repeat;
  opacity: 0.7;
}

.empty {
  position: absolute;
  inset: 22px;
  border: 1px solid var(--rule-faint);
  outline: 1px solid var(--rule-faint);
  outline-offset: -5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  padding: 16px;
}

.frame.loaded .empty { display: none; }
.empty-main { margin: 0; font-size: 26px; font-style: italic; font-weight: 400; letter-spacing: 0.04em; }
.empty-sub { margin: 0 0 12px; color: var(--muted); font-size: 16px; }
.empty .menu-item { width: auto; }

kbd {
  font: 500 14px var(--serif);
  padding: 0 6px;
  border: 1px solid var(--rule);
  color: var(--gold-hi);
}

.stage-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  min-height: 30px;
}

.hint { color: var(--muted); font-style: italic; font-size: 15px; }

/* ---------- panel window ---------- */

.panel {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border: 1px solid var(--rule);
  box-shadow: inset 0 0 0 3px rgba(9, 8, 13, 0.85), inset 0 0 0 4px var(--rule-faint), 0 24px 70px rgba(0, 0, 0, 0.55);
  /* A fixed-height window that scrolls inside, like a config screen. */
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
}

.panel-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 24px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(200, 178, 133, 0.35) transparent;
  -webkit-mask-image: linear-gradient(transparent, #000 16px, #000 calc(100% - 16px), transparent);
  mask-image: linear-gradient(transparent, #000 16px, #000 calc(100% - 16px), transparent);
}

/* Small diamond on the top rule, like a textbox crest. */
.panel::after {
  content: "◆";
  position: absolute;
  top: -8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0 8px;
  font-size: 10px;
  line-height: 14px;
  color: var(--gold);
  background: var(--ink-2);
}

.group { padding: 12px 0 14px; }

.sec {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font: 600 12px/1.2 var(--serif);
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--muted);
}

.sec .jp { font-size: 12px; }

.sec::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--rule), transparent);
  order: 2;
}

.sec .state { order: 3; font: italic 400 14px var(--serif); letter-spacing: 0.04em; text-transform: none; color: var(--faint); }

.label {
  font: 600 12px/1.2 var(--serif);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--muted);
}

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }

output {
  font: 500 17px var(--serif);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--gold-hi);
  letter-spacing: 0.06em;
}

.privacy, .note, .status {
  margin: 6px 0 0;
  font-size: 15px;
  font-style: italic;
  font-weight: 400;
  color: var(--muted);
}

/* ---------- choices (dialogue-choice style) ---------- */

.choices { display: grid; gap: 1px; }

.choice {
  position: relative;
  isolation: isolate;
  display: block;
  width: 100%;
  margin: 0;
  padding: 6px 12px 6px 30px;
  border: 0;
  text-align: left;
  font: 500 17px/1.3 var(--serif);
  letter-spacing: 0.08em;
  color: var(--paper);
  cursor: pointer;
  /* The hairline that sweeps in under a hovered choice. */
  background: linear-gradient(90deg, transparent, var(--gold), transparent) no-repeat left bottom / 0% 1px;
  transition: background-size 0.4s cubic-bezier(0.2, 0.7, 0.2, 1), color 0.2s;
}

.choice em { font-style: italic; font-weight: 400; font-size: 14px; letter-spacing: 0.03em; color: var(--muted); margin-left: 6px; }

/* Translucent band behind the line. */
.choice::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(90deg, transparent, rgba(200, 178, 133, 0.13) 22%, rgba(200, 178, 133, 0.05) 75%, transparent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1), background-color 0.15s;
}

/* Marker: pointer on hover, diamond when chosen; hollow diamond for off toggles. */
.choice::before {
  content: "▸";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--gold);
  opacity: 0;
  transition: opacity 0.2s;
}

.choice[aria-pressed]::before { content: "◇"; font-size: 12px; opacity: 0.55; }

.choice[aria-checked="true"]::before,
.choice[aria-pressed="true"]::before { content: "◆"; font-size: 12px; opacity: 1; color: var(--gold-hi); }

.choice:hover, .choice:focus-visible { background-size: 100% 1px; color: var(--gold-hi); outline: none; }
.choice:hover::after, .choice:focus-visible::after { transform: scaleX(1); }
.choice:hover::before, .choice:focus-visible::before { opacity: 1; }

.choice[aria-checked="true"], .choice[aria-pressed="true"] {
  color: var(--gold-hi);
  text-shadow: 0 0 14px rgba(242, 227, 191, 0.35);
}

.choice[aria-checked="true"]::after, .choice[aria-pressed="true"]::after { transform: scaleX(1); }

.choice:focus-visible { box-shadow: inset 1px 0 0 var(--gold-hi); }

/* Click: a brief brighter flash of the band. */
.choice:active::after { background-color: rgba(242, 227, 191, 0.16); transition: none; }

.choices.inline { display: flex; gap: 4px; }
.choices.inline .choice { flex: 1; width: auto; text-align: center; padding: 6px 6px 6px 20px; }
.choices.inline .choice::before { left: 8px; }

/* ---------- title-screen menu items ---------- */

.menu-item {
  display: block;
  width: 100%;
  margin: 2px 0;
  padding: 9px 0;
  border: 0;
  background: none;
  color: var(--paper);
  font: 600 15px/1.2 var(--serif);
  letter-spacing: 0.36em;
  text-transform: uppercase;
  text-align: center;
  cursor: pointer;
  transition: color 0.2s, text-shadow 0.3s;
}

.menu-item::before, .menu-item::after {
  content: "—";
  display: inline-block;
  margin: 0 0.8em;
  letter-spacing: 0;
  color: var(--gold);
  opacity: 0.55;
  transition: transform 0.3s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.3s;
}

.menu-item:hover:not(:disabled), .menu-item:focus-visible {
  color: var(--gold-hi);
  text-shadow: 0 0 16px rgba(242, 227, 191, 0.5);
  outline: none;
}

.menu-item:hover:not(:disabled)::before, .menu-item:focus-visible::before { transform: translateX(-8px); opacity: 1; }
.menu-item:hover:not(:disabled)::after, .menu-item:focus-visible::after { transform: translateX(8px); opacity: 1; }
.menu-item:active:not(:disabled) { text-shadow: 0 0 22px rgba(242, 227, 191, 0.9); }
.menu-item:disabled { color: var(--faint); cursor: default; }
.menu-item:disabled::before, .menu-item:disabled::after { opacity: 0.2; }
.menu-item .jp { letter-spacing: 0.2em; margin-left: 0.4em; }

.menu-item.denpa { color: #e7a7ba; margin-top: 12px; }
.menu-item.denpa::before, .menu-item.denpa::after, .menu-item.denpa .jp { color: var(--blood); }
.menu-item.denpa:hover, .menu-item.denpa:focus-visible { color: #ffc2d2; text-shadow: 0 0 18px rgba(216, 69, 111, 0.8); }

.link-choice {
  border: 0;
  background: none;
  padding: 4px 2px;
  font: 600 12px/1.2 var(--serif);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
}

.link-choice::before { content: "◇"; margin-right: 0.6em; color: var(--gold); letter-spacing: 0; }
.link-choice:hover:not(:disabled), .link-choice:focus-visible { color: var(--gold-hi); outline: none; }
.link-choice:hover:not(:disabled)::before, .link-choice:focus-visible::before { content: "◆"; }
.link-choice:disabled { opacity: 0.4; cursor: default; }

/* ---------- sliders: hairline track, diamond thumb ---------- */

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0 0 8px;
  background: transparent;
  cursor: pointer;
  --p: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 1px;
  background: linear-gradient(90deg, var(--gold) 0 var(--p), rgba(236, 229, 214, 0.2) var(--p) 100%);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -5px;
  background: var(--ink-2);
  border: 1px solid var(--gold-hi);
  transform: rotate(45deg);
  box-shadow: 0 0 0 3px rgba(9, 8, 13, 0.85), 0 0 10px rgba(242, 227, 191, 0.3);
}

input[type="range"]::-moz-range-track { height: 1px; background: rgba(236, 229, 214, 0.2); }
input[type="range"]::-moz-range-progress { height: 1px; background: var(--gold); }
input[type="range"]::-moz-range-thumb {
  width: 9px;
  height: 9px;
  border-radius: 0;
  background: var(--ink-2);
  border: 1px solid var(--gold-hi);
  transform: rotate(45deg);
}

input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { background: var(--gold-hi); box-shadow: 0 0 0 3px rgba(9, 8, 13, 0.85), 0 0 14px rgba(242, 227, 191, 0.8); }
input[type="range"]:focus-visible::-moz-range-thumb { background: var(--gold-hi); }

/* ---------- toggles: native checkbox, drawn as a diamond ---------- */

.toggle {
  position: relative;
  display: flex;
  align-items: center;
  padding: 4px 0;
  font: 500 17px/1.3 var(--serif);
  letter-spacing: 0.05em;
  cursor: pointer;
}

.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.toggle span::before { content: "◇"; display: inline-block; width: 1.5em; font-size: 12px; color: var(--gold); }
.toggle input:checked + span { color: var(--gold-hi); }
.toggle input:checked + span::before { content: "◆"; }
.toggle input:focus-visible + span { box-shadow: 0 1px 0 var(--gold-hi); }
.toggle.small { font-size: 15px; color: var(--muted); }

/* ---------- text fields ---------- */

.box-fields { margin-top: 10px; display: grid; gap: 12px; }
.box-fields[hidden] { display: none; }
.field { display: grid; gap: 4px; }

input[type="text"], textarea {
  width: 100%;
  font: 500 17px/1.4 var(--serif);
  color: var(--paper);
  background: rgba(9, 8, 13, 0.55);
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-radius: 0;
  padding: 6px 8px;
  resize: vertical;
}

textarea { border: 1px solid var(--rule); }

input[type="text"]:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--gold-hi);
  box-shadow: 0 0 12px rgba(242, 227, 191, 0.18);
}

/* ---------- distortion drawer ---------- */

.distort summary { cursor: pointer; list-style: none; margin: 0; }
.distort summary::-webkit-details-marker { display: none; }
.distort summary::before { content: "▸"; font-size: 10px; color: var(--gold); letter-spacing: 0; transition: transform 0.2s; }
.distort[open] summary::before { transform: rotate(90deg); }
.distort summary:focus-visible { outline: none; color: var(--gold-hi); }
.distort .sec .jp { color: var(--blood); }
.distort.live .sec .state { color: var(--blood); font-style: normal; }
.distort-body { padding-top: 12px; display: grid; gap: 6px; }
.seed-row { align-items: center; justify-content: flex-start; }
.seed-row output { margin-right: auto; }

/* ---------- drop veil ---------- */

.veil {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(9, 8, 13, 0.78);
  outline: 1px solid var(--gold);
  outline-offset: -14px;
  font: italic 400 28px var(--serif);
  letter-spacing: 0.08em;
  z-index: 10;
  pointer-events: none;
}

.veil.on { display: flex; }

@media (max-width: 860px) {
  .app { padding: 16px 16px 28px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .panel { position: relative; top: auto; max-height: none; }
  .panel-scroll { overflow: visible; padding: 12px 18px 8px; -webkit-mask-image: none; mask-image: none; }
  .title { letter-spacing: 0.34em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- v2.1: per-mode strength rows ---------- */

.choices.modes { gap: 1px; }

.mode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 34px;
  align-items: center;
  gap: 8px;
}

.mode-row .choice { white-space: nowrap; }

.mode-row output {
  font-size: 15px;
  text-align: right;
}

.mode-row.off input, .mode-row.off output { opacity: 0.35; }

input[type="range"].mini { height: 18px; margin: 0; }
input[type="range"].mini::-webkit-slider-thumb { width: 8px; height: 8px; margin-top: -3.5px; }
input[type="range"].mini::-moz-range-thumb { width: 7px; height: 7px; }

/* ---------- WebKit / iOS hardening ---------- */

/* Safari draws its own rounded, shaded buttons and fields unless told not to. */
.choice, .menu-item, .link-choice, input[type="text"], textarea {
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}

/* The choices have their own press flash; the grey iOS tap box fights it. */
button, summary, label, .frame { -webkit-tap-highlight-color: transparent; }

/* Fingers need a bigger target than the 11px diamond. */
@media (pointer: coarse) {
  input[type="range"] { height: 32px; }
  input[type="range"]::-webkit-slider-thumb { width: 18px; height: 18px; margin-top: -9px; }
  input[type="range"]::-moz-range-thumb { width: 15px; height: 15px; }
  input[type="range"].mini::-webkit-slider-thumb { width: 14px; height: 14px; margin-top: -7px; }
  .mode-row { grid-template-columns: minmax(0, 1fr) 96px 34px; }
}
