:root {
  --bg: #120f0d;
  --bg-2: #1b1714;
  --panel: #231d19;
  --line: #3a302a;
  --text: #ece2d0;
  --muted: #a8998a;
  --accent: #e3a649;
  --accent-ink: #1a1206;
  --you: #2c3a3f;
  --danger: #d4624f;
  --story-font: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --mood: #e3a649;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--ui-font); }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.screen { position: fixed; inset: 0; display: none; flex-direction: column; padding-top: var(--safe-t);
  background: radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--mood) 14%, transparent), transparent 70%), var(--bg);
  transition: background 2s; }
.screen.active { display: flex; }

/* ---------- home ---------- */
#screen-home { padding: calc(var(--safe-t) + 20px) 18px calc(var(--safe-b) + 20px); overflow-y: auto; }
.home-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.eyebrow { margin: 0; letter-spacing: .18em; text-transform: uppercase; font-size: 12px; color: var(--accent); }
h1 { margin: 2px 0 0; font-family: var(--story-font); font-weight: 600; font-size: 34px; }
.section-label { font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin: 28px 0 10px; font-weight: 600; }
.adventure-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.adv-card { display: flex; align-items: stretch; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.adv-card .open { flex: 1; text-align: left; background: none; border: 0; padding: 14px 14px 13px; min-width: 0; }
.adv-card h3 { margin: 0 0 4px; font-family: var(--story-font); font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adv-card p { margin: 0; color: var(--muted); font-size: 13px; }
.adv-card .snippet { margin-top: 6px; color: #cbbfae; font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.adv-card .del { background: none; border: 0; border-left: 1px solid var(--line); width: 48px; color: var(--muted); display: grid; place-items: center; }
.adv-card .del:active { color: var(--danger); }
.empty-hint { color: var(--muted); font-size: 14px; line-height: 1.5; }

/* ---------- buttons ---------- */
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 700; width: 100%; }
.btn-primary.big { padding: 16px 18px; font-size: 17px; display: flex; gap: 10px; align-items: center; justify-content: center; }
.btn-primary.big span { font-size: 22px; line-height: 1; }
.btn-primary:active { filter: brightness(.9); }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; color: var(--text); }
.icon-btn { background: none; border: 0; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: var(--text); flex: none; }
.icon-btn:active { background: var(--panel); }

/* ---------- bars ---------- */
.bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(8px); }
.bar h2 { margin: 0; font-size: 17px; flex: 1; text-align: center; }
.bar-spacer { width: 42px; }
.play-title { flex: 1; min-width: 0; text-align: center; }
.play-title h2 { font-family: var(--story-font); font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mood-tag { margin: 1px 0 0; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--mood); transition: color 1.5s; }
#btn-music .ico-off { display: none; }
#btn-music.off .ico-on { display: none; }
#btn-music.off .ico-off { display: block; color: var(--muted); }

/* ---------- new adventure form ---------- */
.form-scroll { flex: 1; overflow-y: auto; padding: 8px 18px calc(var(--safe-b) + 24px); }
.field-label { display: block; margin: 20px 0 8px; font-weight: 600; font-size: 14px; }
.field-label .opt { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 4px; }
input[type=text], textarea, select { width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; font-size: 16px; outline: none; }
input[type=text]:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: none; line-height: 1.4; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.mode-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 26px; }
.mode-pick button { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 13px; text-align: left; display: flex; flex-direction: column; gap: 4px; }
.mode-pick button small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.mode-pick button.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- play ---------- */
.mode-toggle { display: flex; margin: 10px auto 4px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.mode-toggle button { background: none; border: 0; border-radius: 999px; padding: 6px 16px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.mode-toggle button.on { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.story { flex: 1; overflow-y: auto; padding: 12px 18px 18px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
.beat { font-family: var(--story-font); font-size: 18.5px; line-height: 1.62; margin: 0 0 22px; color: var(--text); }
.beat p { margin: 0 0 .8em; }
.beat p:last-child { margin-bottom: 0; }
.beat.streaming p:last-child::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; margin-left: 2px; }
.you { margin: 0 0 22px auto; max-width: 85%; width: fit-content; background: var(--you); border-radius: 16px 16px 4px 16px; padding: 10px 14px; font-size: 15.5px; line-height: 1.45; color: #dbe7ea; }
.you .via { display: block; font-size: 11px; color: #9fb4b9; margin-bottom: 2px; letter-spacing: .05em; }
.thinking { display: flex; gap: 6px; padding: 6px 0 22px; }
.thinking i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: .3; animation: pulse 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: .2s; } .thinking i:nth-child(3) { animation-delay: .4s; }
.sys-note { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.sys-note button { margin-top: 8px; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: 1; transform: scale(1.15); } }

.dock { border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg-2) 92%, transparent); backdrop-filter: blur(10px); padding: 10px 12px calc(var(--safe-b) + 10px); }
.choices { display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; max-height: 38vh; overflow-y: auto; }
.choices:empty { display: none; }
.choice { display: flex; gap: 10px; align-items: baseline; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 15px; line-height: 1.35; }
.choice b { color: var(--accent); font-variant-numeric: tabular-nums; flex: none; }
.choice:active { border-color: var(--accent); }
.choices.locked .choice { opacity: .45; pointer-events: none; }

.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; min-height: 46px; max-height: 120px; border-radius: 23px; padding: 12px 16px; }
.round-btn { width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; flex: none; position: relative; }
.round-btn.send { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.round-btn:disabled { opacity: .45; }
.round-btn.live { background: var(--danger); border-color: var(--danger); color: white; }
.round-btn.live::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--danger); animation: ring 1.2s infinite; }
@keyframes ring { from { transform: scale(.9); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }

.handsfree-panel { display: none; align-items: center; gap: 16px; padding: 4px 4px 2px; }
.hf .handsfree-panel { display: flex; }
.hf .input-row { display: none; }
.hf-text p { margin: 0; }
#hf-status { font-weight: 700; font-size: 16px; }
.hf-sub { color: var(--muted); font-size: 13px; margin-top: 2px !important; }
.orb { position: relative; width: 74px; height: 74px; border-radius: 50%; border: 0; background: none; flex: none; }
.orb-core { position: absolute; inset: 14px; border-radius: 50%; background: var(--muted); transition: background .4s, transform .15s; transform: scale(var(--lvl, 1)); }
.orb-ring { position: absolute; inset: 4px; border-radius: 50%; border: 2px solid var(--line); }
.orb[data-state=listening] .orb-core { background: var(--danger); }
.orb[data-state=listening] .orb-ring { border-color: var(--danger); animation: ring 1.4s infinite; }
.orb[data-state=speaking] .orb-core { background: var(--accent); animation: breathe 1.6s ease-in-out infinite; }
.orb[data-state=thinking] .orb-core { background: #7aa6b0; animation: breathe .9s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(.82); } }

/* ---------- settings sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 10; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; background: var(--bg-2); border-top: 1px solid var(--line); border-radius: 20px 20px 0 0; padding: 8px 20px calc(var(--safe-b) + 20px); transform: translateY(105%); transition: transform .3s cubic-bezier(.2,.8,.2,1); z-index: 11; }
.sheet h2 { margin: 6px 0 0; font-size: 20px; }
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 8px; }
.settings-open .sheet { transform: none; }
.settings-open .sheet-backdrop { opacity: 1; pointer-events: auto; }
.sheet .btn-primary { margin-top: 24px; }
.hint { color: var(--muted); font-size: 12.5px; line-height: 1.45; margin: 6px 0 8px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 20px; font-size: 14.5px; line-height: 1.35; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 110px); transform: translate(-50%, 20px); background: #000c; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: 88vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .screen > * { width: 100%; max-width: 680px; margin-left: auto; margin-right: auto; }
  .bar, .dock { max-width: none; }
  .bar > *, .dock > * { max-width: 680px; }
  .dock > * { margin-left: auto; margin-right: auto; }
  .mode-toggle { width: auto; }
  .sheet { max-width: 560px; margin: 0 auto; }
}
