:root {
  color-scheme: light;

  --bg: #f5ebe0;        /* linen */
  --paper: #edede9;     /* parchment */
  --fg: #14213d;        /* prussian-blue */
  --accent: #d5bdaf;    /* almond-silk */
  --accent-strong: #b8860b;

  --muted: color-mix(in srgb, var(--fg) 55%, transparent);
  --text-2: color-mix(in srgb, var(--fg) 76%, transparent);
  --border-fade: color-mix(in srgb, var(--fg) 16%, transparent);
  --focus: var(--accent-strong);
  --good: #2f6e44;
  --bad: #a3402f;
  --warn: #b8860b;
  --idle: color-mix(in srgb, var(--fg) 28%, transparent);

  --font-display: "Instrument Serif", "Times New Roman", serif;
  --font-mono: "Courier Prime", "Courier New", monospace;
  --font-rules: "Archivo", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14213d;
    --paper: #000000;
    --fg: #e5e5e5;
    --accent: #fca311;
    --accent-strong: #fca311;

    --muted: color-mix(in srgb, var(--fg) 55%, transparent);
    --text-2: color-mix(in srgb, var(--fg) 78%, transparent);
    --border-fade: color-mix(in srgb, var(--fg) 15%, transparent);
    --good: #6fcf8f;
    --bad: #e2735a;
    --warn: #fca311;
    --idle: color-mix(in srgb, var(--fg) 30%, transparent);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 50% -10%, color-mix(in srgb, var(--accent-strong) 12%, transparent), transparent 55%),
    var(--bg);
  color: var(--fg);
  font-family: var(--font-rules);
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.1em; }
.muted { color: var(--muted); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 40px 24px 80px; }

.top-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.home-link { font-size: 0.7rem; color: var(--muted); text-decoration: none; transition: color 0.18s ease; }
.home-link:hover { color: var(--accent-strong); }

.lang-toggle { display: flex; gap: 4px; }
.lang-btn {
  font-size: 0.66rem; padding: 5px 9px; background: transparent; color: var(--muted);
  border: 1px solid var(--border-fade); border-radius: 4px; cursor: pointer;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}
.lang-btn:hover { color: var(--fg); }
.lang-btn.on { color: var(--bg); background: var(--accent-strong); border-color: var(--accent-strong); }

header.hero { margin-bottom: 30px; max-width: 720px; }
.eyebrow { display: inline-block; font-size: 0.66rem; color: var(--accent-strong); margin-bottom: 14px; }
h1 { font-family: var(--font-display); font-weight: 400; font-size: clamp(2.2rem, 6vw, 3.6rem); line-height: 1.02; margin: 0 0 16px; }
h1 .hl { font-style: italic; color: var(--accent-strong); }
header.hero p { font-size: 1.02rem; line-height: 1.55; color: var(--text-2); margin: 0; }

.card {
  background: color-mix(in srgb, var(--paper) 60%, transparent);
  border: 1px solid var(--border-fade);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
#setup { max-width: 720px; }

.lbl { display: block; font-size: 0.66rem; color: var(--muted); margin-bottom: 8px; }
.lbl b { color: var(--accent-strong); font-weight: 700; margin-left: 6px; }
.field { display: block; margin-bottom: 14px; }
.field.narrow { width: 110px; margin-bottom: 0; }

input[type=text], input[type=number], textarea, select {
  width: 100%; font: inherit; font-size: 0.98rem; color: var(--fg);
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  border: 1px solid var(--border-fade); border-radius: 6px; padding: 10px 12px;
  transition: border-color 0.18s ease;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }

input[type=range] { width: 100%; accent-color: var(--accent-strong); }

.examples { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chip {
  font: inherit; font-size: 0.8rem; color: var(--text-2); background: transparent;
  border: 1px dashed var(--border-fade); border-radius: 999px; padding: 5px 12px; cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.chip:hover { border-color: var(--accent-strong); color: var(--fg); transform: translateY(-1px); }

.row { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.hint { flex: 1; min-width: 200px; font-size: 0.8rem; line-height: 1.45; color: var(--muted); margin: 0; }

.go {
  font: inherit; font-weight: 600; font-size: 0.92rem; cursor: pointer;
  color: var(--bg); background: var(--accent-strong); border: 1px solid var(--accent-strong);
  border-radius: 6px; padding: 11px 20px;
  transition: transform 0.18s ease, filter 0.18s ease, opacity 0.18s ease;
}
.go:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.go:disabled { opacity: 0.45; cursor: default; }
.ghost {
  font-size: 0.7rem; cursor: pointer; color: var(--text-2); background: transparent;
  border: 1px solid var(--border-fade); border-radius: 6px; padding: 11px 14px;
  transition: border-color 0.18s ease, color 0.18s ease;
}
.ghost:hover:not(:disabled) { border-color: var(--accent-strong); color: var(--fg); }
.ghost:disabled { opacity: 0.4; cursor: default; }

.error { color: var(--bad); font-size: 0.9rem; margin: 0 0 16px; }

.grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.stage-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.tag { font-size: 0.7rem; color: var(--accent-strong); }
.tag.dim { color: var(--muted); animation: blink 1.1s ease-in-out infinite; }
@keyframes blink { 50% { opacity: 0.35; } }

.canvas-box { position: relative; }
#map { width: 100%; display: block; border-radius: 8px; background: color-mix(in srgb, var(--bg) 55%, transparent); cursor: crosshair; }
.tip {
  position: absolute; pointer-events: none; font-size: 0.62rem; padding: 4px 8px; border-radius: 4px;
  background: var(--fg); color: var(--bg); white-space: nowrap; transform: translate(-50%, -140%);
}
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 12px 0 0; padding: 0; font-size: 0.6rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.side .card { margin-bottom: 14px; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { background: color-mix(in srgb, var(--paper) 60%, transparent); border: 1px solid var(--border-fade); border-radius: 8px; padding: 10px 12px; }
.kpi .k { font-size: 0.56rem; color: var(--muted); display: block; margin-bottom: 4px; }
.kpi .v { font-family: var(--font-display); font-size: 1.5rem; line-height: 1; }
.kpi .v.good { color: var(--good); }
.kpi .v.bad { color: var(--bad); }
.chart-card canvas { width: 100%; height: 150px; display: block; }

.detail { font-size: 0.86rem; line-height: 1.5; min-height: 120px; }
.detail h3 { font-family: var(--font-display); font-weight: 400; font-size: 1.35rem; margin: 0 0 4px; }
.detail .persona { color: var(--text-2); margin: 0 0 10px; }
.bars { display: grid; gap: 7px; }
.bar { display: grid; grid-template-columns: 110px 1fr 38px; align-items: center; gap: 8px; font-size: 0.62rem; color: var(--muted); }
.bar .track { height: 7px; background: var(--border-fade); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent-strong); border-radius: 4px; transition: width 0.5s ease; }
.bar .n { text-align: right; color: var(--fg); }
.sub { font-size: 0.58rem; color: var(--muted); margin: 10px 0 6px; }

.controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; align-items: end; }
.controls .btns, .controls .hint { grid-column: 1 / -1; }
.btns { display: flex; gap: 10px; flex-wrap: wrap; }

.offer { border-color: var(--accent-strong); }
.offer p { margin: 0 0 12px; line-height: 1.5; }
#end h2 { font-family: var(--font-display); font-weight: 400; font-size: 1.8rem; margin: 0 0 8px; }
#end p { margin: 4px 0; color: var(--text-2); line-height: 1.5; }

.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.actors { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.actors li { font-size: 0.84rem; line-height: 1.45; color: var(--text-2); }
.actors b { color: var(--fg); font-weight: 600; }
.actors .meta { font-size: 0.6rem; color: var(--muted); display: block; margin-top: 3px; }
.mini { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 5px; background: var(--border-fade); }
.mini span { display: block; height: 100%; }

.log { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow: auto; font-size: 0.86rem; line-height: 1.5; }
.log li { padding: 6px 0; border-bottom: 1px solid var(--border-fade); color: var(--text-2); animation: slide 0.4s ease both; }
.log li:last-child { border-bottom: 0; }
.log .m { color: var(--accent-strong); font-size: 0.62rem; margin-right: 8px; }
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.footnote { font-size: 0.6rem; color: var(--muted); margin: 22px 0 0; line-height: 1.7; }

@media (max-width: 900px) {
  .grid, .two { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) {
  .wrap { padding: 28px 16px 60px; }
  .controls { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

.coach {
  margin: 0 0 18px; padding: 14px 18px; font-size: 1rem; line-height: 1.5; color: var(--fg);
  border-left: 3px solid var(--accent-strong); background: color-mix(in srgb, var(--accent-strong) 9%, transparent);
  border-radius: 0 8px 8px 0; animation: slide 0.4s ease both;
}
.coach:empty { display: none; }
.desc { display: block; margin-top: 6px; font-size: 0.74rem; line-height: 1.4; color: var(--muted); }
#auto-btn { color: var(--fg); }

.controls { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpis { grid-template-columns: repeat(2, 1fr); }
.more, .fold { grid-column: 1 / -1; }
.more summary, .fold summary { cursor: pointer; font-size: 0.68rem; color: var(--muted); padding: 6px 0; }
.more summary:hover, .fold summary:hover { color: var(--accent-strong); }
.more[open] select { margin-top: 6px; max-width: 360px; }
.fold { margin-bottom: 18px; }
.fold[open] summary { margin-bottom: 12px; }
@media (max-width: 900px) { .controls { grid-template-columns: 1fr; } }
