/* Voice Profile Studio — theme + layout.
   Light/dark aware, large-type friendly, WCAG-AA contrast, phone-first. */

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ece3;
  --ink: #1c1a17;
  --ink-soft: #4b4741;
  --ink-faint: #726d64;
  --accent: #9a3b2e;      /* deep terracotta — high contrast on cream */
  --accent-ink: #ffffff;
  --accent-soft: #f3e0da;
  --line: #ddd6c9;
  --line-strong: #b8afa0;
  --focus: #1f5f8b;
  --good: #2f6b46;
  --radius: 14px;
  --maxw: 720px;
  --fs-base: 18px;
  --touch: 48px;
}

:root[data-textsize="large"] { --fs-base: 21px; --touch: 54px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1c17;
    --surface-2: #26241e;
    --ink: #f0ebe1;
    --ink-soft: #cfc8ba;
    --ink-faint: #9c9484;
    --accent: #e08a6f;
    --accent-ink: #1a120e;
    --accent-soft: #3a2820;
    --line: #35322a;
    --line-strong: #4d4940;
    --focus: #7cc0ec;
    --good: #7fc79b;
  }
}
/* Explicit theme override wins in both directions (viewer toggle stamps data-theme). */
:root[data-theme="light"] {
  --bg:#f7f5f0;--surface:#fff;--surface-2:#f0ece3;--ink:#1c1a17;--ink-soft:#4b4741;--ink-faint:#726d64;
  --accent:#9a3b2e;--accent-ink:#fff;--accent-soft:#f3e0da;--line:#ddd6c9;--line-strong:#b8afa0;--focus:#1f5f8b;--good:#2f6b46;
}
:root[data-theme="dark"] {
  --bg:#14130f;--surface:#1e1c17;--surface-2:#26241e;--ink:#f0ebe1;--ink-soft:#cfc8ba;--ink-faint:#9c9484;
  --accent:#e08a6f;--accent-ink:#1a120e;--accent-soft:#3a2820;--line:#35322a;--line-strong:#4d4940;--focus:#7cc0ec;--good:#7fc79b;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 8px; text-decoration: none;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 16px;
}
.topbar-tools { display: flex; gap: 6px; }
.dot {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); margin-right: 8px; vertical-align: baseline;
}
.ghost-btn {
  font-family: inherit; font-size: .82em; color: var(--ink-soft);
  background: transparent; border: 1px solid transparent; border-radius: 10px;
  padding: 8px 12px; min-height: 40px; cursor: pointer; font-weight: 600;
}
#home-btn { font-size: .9em; color: var(--ink); border: none; padding-left: 4px; }
.ghost-btn:hover { background: var(--surface-2); }
#text-btn .big-a { font-size: 1.3em; }
#text-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

.progress-rail { height: 4px; background: var(--line); }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .35s ease; }

.banner {
  max-width: var(--maxw); margin: 12px auto 0; padding: 12px 16px;
  background: var(--accent-soft); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: .9em;
}

/* ---- main / views ---- */
main {
  max-width: var(--maxw); margin: 0 auto; padding: 24px 16px 40px;
  outline: none;
}
.view[hidden] { display: none; }

/* ---- welcome ---- */
.hero-art { display: block; margin: 8px auto 20px; width: 100%; max-width: 340px; height: auto; color: var(--accent); }
.hero-eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; font-size: .72em; font-family: ui-sans-serif, system-ui, sans-serif; }
h1 { font-size: 2em; line-height: 1.15; margin: .3em 0; letter-spacing: -.01em; }
.lede { color: var(--ink-soft); font-size: 1.08em; }
.welcome-note { color: var(--ink-faint); font-size: .92em; border-top: 1px solid var(--line); margin-top: 24px; padding-top: 16px; }

.cta {
  font-family: inherit; font-size: 1.05em; font-weight: 700;
  background: var(--accent); color: var(--accent-ink);
  border: none; border-radius: 12px; padding: 15px 26px;
  min-height: var(--touch); cursor: pointer; margin-top: 8px;
}
.cta:hover { filter: brightness(1.06); }
.cta.block { display: block; width: 100%; }

/* ---- module map ---- */
.map-head h1 { margin-bottom: .1em; }
.map-sub { color: var(--ink-soft); margin-top: 0; }
.module-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 12px; }
.module-card {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-height: var(--touch); cursor: pointer; font-family: inherit; color: var(--ink);
}
.module-card:hover { border-color: var(--line-strong); }
.module-card.done { border-color: var(--good); }
.module-icon { flex: 0 0 auto; width: 46px; height: 46px; color: var(--accent); }
.module-meta { flex: 1 1 auto; min-width: 0; }
.module-name { display: block; font-weight: 700; font-size: 1.06em; }
.module-tag { display: block; color: var(--ink-faint); font-size: .86em; margin-top: 2px; }
.module-status { flex: 0 0 auto; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .78em; font-weight: 700; color: var(--ink-faint); text-align: right; }
.module-status .count { display: block; }
.module-status.done { color: var(--good); }
.mini-rail { height: 5px; width: 62px; background: var(--line); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.mini-fill { height: 100%; background: var(--accent); width: 0; }
.module-status.done .mini-fill { background: var(--good); }

.map-actions { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }

/* ---- question view ---- */
.q-scene { display: block; width: 100%; max-width: 300px; height: auto; margin: 0 auto 18px; color: var(--accent); }
.q-module-label { font-family: ui-sans-serif, system-ui, sans-serif; font-size: .74em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
.q-stem { font-size: 1.42em; line-height: 1.28; margin: 8px 0 6px; letter-spacing: -.01em; }
.q-help { color: var(--ink-soft); font-size: .96em; margin: 0 0 20px; }

fieldset { border: none; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

.options { display: grid; gap: 10px; }
.option {
  position: relative; display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; min-height: var(--touch);
}
.option:hover { border-color: var(--line-strong); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option .mark {
  flex: 0 0 auto; width: 24px; height: 24px; margin-top: 1px;
  border: 2px solid var(--line-strong); background: var(--surface);
  display: grid; place-items: center; color: var(--accent-ink);
  font-size: 15px; font-weight: 800;
}
.option[data-multi="false"] .mark { border-radius: 50%; }
.option[data-multi="true"] .mark { border-radius: 6px; }
.option:has(input:checked) .mark { background: var(--accent); border-color: var(--accent); }
.option .mark::after { content: ""; }
.option:has(input:checked) .mark::after { content: "✓"; }
.option[data-multi="false"]:has(input:checked) .mark::after { content: "●"; font-size: 12px; }
.option .label { font-size: 1.02em; line-height: 1.4; }
.option .keyhint {
  position: absolute; right: 12px; top: 12px; font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: .68em; color: var(--ink-faint); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 6px; opacity: .7;
}
@media (hover: none) { .option .keyhint { display: none; } }

.max-note { color: var(--ink-faint); font-size: .85em; margin-top: 10px; font-family: ui-sans-serif, system-ui, sans-serif; }

/* free text */
.freetext-wrap { margin-top: 16px; }
.freetext-wrap summary {
  cursor: pointer; color: var(--accent); font-weight: 600; font-size: .92em;
  font-family: ui-sans-serif, system-ui, sans-serif; list-style: none; padding: 6px 0;
}
.freetext-wrap summary::-webkit-details-marker { display: none; }
.freetext-wrap summary::before { content: "＋ "; }
.freetext-wrap[open] summary::before { content: "－ "; }
textarea {
  width: 100%; font-family: inherit; font-size: 1em; color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-top: 8px; resize: vertical; min-height: 96px; line-height: 1.5;
}
textarea::placeholder { color: var(--ink-faint); }

.skip-row { margin-top: 18px; }
.link-btn {
  background: none; border: none; font-family: ui-sans-serif, system-ui, sans-serif;
  color: var(--ink-faint); font-size: .9em; cursor: pointer; text-decoration: underline;
  text-underline-offset: 3px; padding: 8px 4px; min-height: 40px;
}
.link-btn:hover { color: var(--ink-soft); }

/* ---- ear test ---- */
.passages { display: grid; gap: 12px; }
.passage {
  display: block; background: var(--surface); border: 2px solid var(--line);
  border-radius: 12px; padding: 16px 16px 16px 52px; cursor: pointer; position: relative;
}
.passage:hover { border-color: var(--line-strong); }
.passage:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.passage:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.passage input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.passage .tag {
  position: absolute; left: 14px; top: 16px; width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line-strong); display: grid; place-items: center;
  font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 800; font-size: .8em; color: var(--ink-soft);
}
.passage:has(input:checked) .tag { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.passage .ptext { font-size: 1.08em; line-height: 1.5; font-style: italic; }

/* ---- axis scale ---- */
.axis-scale { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.axis-pole { flex: 0 0 auto; width: 58px; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .78em; font-weight: 700; color: var(--ink-soft); line-height: 1.15; }
.axis-scale .axis-pole:first-child { text-align: right; }
.axis-dots { flex: 1 1 auto; display: flex; justify-content: space-between; gap: 4px; }
.axis-dot { flex: 1 1 0; display: grid; place-items: center; min-height: var(--touch); cursor: pointer; position: relative; }
.axis-dot input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.axis-dot .dotmark {
  width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--line-strong);
  display: grid; place-items: center; background: var(--surface);
  font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 700; color: var(--ink-faint);
}
.axis-dot:has(input:checked) .dotmark { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.axis-dot:has(input:focus-visible) .dotmark { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- cut / kill-the-line ---- */
.cut-para { display: grid; gap: 6px; }
.cutline { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 2px solid transparent; cursor: pointer; position: relative; min-height: var(--touch); }
.cutline:hover { background: var(--surface-2); }
.cutline input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.cut-text { font-size: 1.05em; line-height: 1.5; }
.cutline:has(input:checked) { background: var(--accent-soft); }
.cutline:has(input:checked) .cut-text { text-decoration: line-through; text-decoration-color: var(--accent); text-decoration-thickness: 2px; color: var(--ink-faint); }
.cutline:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.cut-flag { margin-left: auto; flex: 0 0 auto; align-self: center; font-family: ui-sans-serif, system-ui, sans-serif; font-size: .66em; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); opacity: 0; }
.cutline:has(input:checked) .cut-flag { opacity: 1; }

/* ---- rank ---- */
.rank-list { display: grid; gap: 10px; }
.rank-item { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; background: var(--surface); border: 2px solid var(--line); border-radius: 12px; padding: 12px 16px; min-height: var(--touch); cursor: pointer; font-family: inherit; color: var(--ink); }
.rank-item:hover { border-color: var(--line-strong); }
.rank-item.ranked { border-color: var(--accent); background: var(--accent-soft); }
.rank-badge { flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; border: 2px solid var(--line-strong); background: var(--surface); font-family: ui-sans-serif, system-ui, sans-serif; font-weight: 800; color: var(--ink-faint); }
.rank-item.ranked .rank-badge { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.rank-label { font-size: 1.05em; }

/* ---- write ---- */
.write-area { min-height: 148px; font-size: 1.1em; margin-top: 4px; }

/* ---- review / export ---- */
.review-group { margin-top: 24px; }
.review-group h2 { font-size: 1.15em; border-bottom: 2px solid var(--line); padding-bottom: 6px; }
.review-q { margin: 14px 0; }
.review-stem { font-weight: 600; }
.review-ans { color: var(--ink-soft); margin-top: 2px; }
.review-ans.empty { color: var(--ink-faint); font-style: italic; }
.review-note { color: var(--ink-faint); font-size: .9em; margin-top: 2px; }
.review-note::before { content: "“"; }
.review-note::after { content: "”"; }

.export-panel { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 8px; }
.export-panel h1 { margin-top: 0; }
.export-stat { color: var(--ink-soft); font-family: ui-sans-serif, system-ui, sans-serif; font-size: .92em; }
.export-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.export-buttons .cta.secondary { background: var(--surface); color: var(--accent); border: 2px solid var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 10px;
  font-family: ui-sans-serif, system-ui, sans-serif; font-size: .9em; z-index: 60; max-width: 90vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
}

/* ---- footer nav ---- */
.footbar {
  position: sticky; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.footbar-inner {
  max-width: var(--maxw); margin: 0 auto; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 12px 16px;
}
.nav-btn {
  font-family: inherit; font-size: 1em; font-weight: 700; border-radius: 12px;
  padding: 12px 22px; min-height: var(--touch); min-width: 92px; cursor: pointer;
}
.nav-btn.primary { background: var(--accent); color: var(--accent-ink); border: none; }
.nav-btn.primary:hover { filter: brightness(1.06); }
.nav-btn.secondary { background: transparent; color: var(--ink-soft); border: 2px solid var(--line); }
.nav-btn.secondary:hover { border-color: var(--line-strong); }
.nav-btn:disabled { opacity: .4; cursor: default; }
.q-counter { font-family: ui-sans-serif, system-ui, sans-serif; font-size: .82em; color: var(--ink-faint); }

@media (max-width: 480px) {
  h1 { font-size: 1.7em; }
  .q-stem { font-size: 1.24em; }
  .nav-btn { min-width: 78px; padding: 12px 16px; }
}

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