/* Interactive Stories: shared look for the listening and writing pages */
:root {
  --bg: #14182b; --bg2: #1d2340; --card: #252c50; --card2: #2e3661; --line: #3a4374;
  --text: #f4efe3; --muted: #b9b4c9; --gold: #f2c35b; --gold2: #ffd982; --teal: #5fd3c1; --rose: #f08a8a; --violet: #a99cff;
  --radius: 18px; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(1200px 700px at 80% -10%, #2a2f5c 0%, transparent 60%), var(--bg); background-attachment: fixed; color: var(--text); font-family: var(--font); font-size: 18px; line-height: 1.5; }
a { color: var(--gold2); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 20px; }

/* top bar */
.top { display: flex; align-items: center; gap: 14px; padding: 14px 20px; position: sticky; top: 0; z-index: 20; background: rgba(20, 24, 43, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 24px; font-weight: 700; color: var(--gold); text-decoration: none; white-space: nowrap; }
.brand img { width: 36px; height: 36px; }
.top .grow { flex: 1; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 600; text-decoration: none; color: var(--text); min-height: 44px; transition: background .15s, transform .1s; }
.btn:hover { background: var(--card2); }
.btn:active { transform: scale(.98); }
.btn.gold { background: var(--gold); color: #24180a; border-color: var(--gold); }
.btn.gold:hover { background: var(--gold2); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: #7a3c4a; color: var(--rose); background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; }
.icon-btn svg { width: 26px; height: 26px; fill: currentColor; }

/* forms */
label.field { display: block; margin: 0 0 14px; }
label.field > span { display: block; font-size: 15px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
input[type=text], input[type=password], input[type=search], textarea, select { width: 100%; background: #10142a; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 3px solid rgba(242, 195, 91, .55); outline-offset: 1px; }
textarea { resize: vertical; min-height: 80px; }
.error { color: var(--rose); min-height: 1.5em; }
.muted { color: var(--muted); }
.center-card { max-width: 440px; margin: 10vh auto; background: var(--card); padding: 30px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.center-card h1 { font-family: var(--serif); color: var(--gold); margin-top: 0; }

/* story cards (shelf) */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 22px; }
.story-card { background: var(--card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; text-align: left; padding: 0; color: inherit; text-decoration: none; transition: transform .15s; }
.story-card:hover { transform: translateY(-3px); }
.cover { aspect-ratio: 1 / 1; background: linear-gradient(135deg, #3a2d6b, #1a5b67); display: flex; align-items: flex-end; padding: 16px; position: relative; overflow: hidden; }
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover .ct { position: relative; font-family: var(--serif); font-size: 26px; font-weight: 700; line-height: 1.15; text-shadow: 0 2px 10px rgba(0,0,0,.6); }
.cover.has-img .ct { display: none; }
.story-card .meta { padding: 14px 16px 18px; }
.story-card h3 { margin: 0 0 4px; font-family: var(--serif); font-size: 22px; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--card2); color: var(--muted); }
.badge.gold { background: rgba(242, 195, 91, .18); color: var(--gold2); }
.badge.teal { background: rgba(95, 211, 193, .15); color: var(--teal); }
.badge.rose { background: rgba(240, 138, 138, .15); color: var(--rose); }

/* listening page */
.intro { display: grid; grid-template-columns: minmax(220px, 340px) 1fr; gap: 30px; align-items: start; }
.intro .cover { border-radius: var(--radius); box-shadow: var(--shadow); }
.intro h1 { font-family: var(--serif); font-size: 40px; margin: 0 0 6px; line-height: 1.1; }
.intro .actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 20px 0; }
.intro .actions .btn { font-size: 20px; padding: 14px 26px; }
.how { background: var(--bg2); border-radius: var(--radius); padding: 16px 20px; border: 1px solid var(--line); }
@media (max-width: 700px) { .intro { grid-template-columns: 1fr; } .intro .cover { max-width: 320px; } }

.player { max-width: 760px; margin: 0 auto; padding: 10px 20px 60px; text-align: center; }
.player .seg-title { font-family: var(--serif); font-size: 34px; margin: 18px 0 2px; line-height: 1.15; }
.player .story-name { color: var(--muted); }
.controls { display: flex; align-items: center; justify-content: center; gap: 22px; margin: 26px 0 10px; }
.play-big { width: 112px; height: 112px; border-radius: 50%; background: var(--gold); color: #24180a; border: none; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 8px 30px rgba(242, 195, 91, .35); }
.play-big svg { width: 52px; height: 52px; fill: currentColor; }
.bar { display: flex; align-items: center; gap: 12px; max-width: 560px; margin: 0 auto; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }
.bar input[type=range] { flex: 1; accent-color: var(--gold); height: 30px; }
.words { text-align: left; background: var(--bg2); border-radius: var(--radius); padding: 18px 22px; margin: 18px 0; font-family: var(--serif); font-size: 21px; line-height: 1.6; white-space: pre-wrap; border: 1px solid var(--line); }

.choice-panel { margin: 26px auto 0; background: linear-gradient(180deg, #2b3363, #222852); border: 2px solid var(--gold); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); animation: pop .35s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.choice-panel .q { font-family: var(--serif); font-size: 28px; margin: 0 0 18px; line-height: 1.25; }
.choices { display: grid; gap: 14px; }
.choice { width: 100%; min-height: 72px; font-size: 24px; font-weight: 700; border-radius: 18px; border: 2px solid var(--line); background: var(--card2); padding: 14px 20px; text-align: left; display: flex; align-items: center; gap: 16px; transition: border-color .15s, background .15s; }
.choice:hover, .choice.heard { border-color: var(--gold); background: #39427a; }
.choice .num { flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--gold); color: #24180a; display: inline-flex; align-items: center; justify-content: center; font-size: 22px; }
.mic-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 18px; }
.mic { font-size: 20px; padding: 12px 22px; }
.mic.listening { background: var(--rose); color: #2a0d10; border-color: var(--rose); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px rgba(240, 138, 138, .15); } }
.heard-text { min-height: 1.5em; margin-top: 10px; color: var(--muted); }
.end-panel { margin: 26px auto 0; padding: 30px 24px; border-radius: 24px; background: var(--bg2); border: 2px solid var(--teal); }
.end-panel h2 { font-family: var(--serif); font-size: 44px; margin: 0; color: var(--teal); }
.end-panel .actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; margin-top: 18px; }
.trail { margin-top: 30px; text-align: left; color: var(--muted); font-size: 16px; }
.trail ol { padding-left: 22px; }
.continue-note { margin-top: 18px; color: var(--teal); font-size: 20px; }
.preview-banner { background: #5b3b0a; color: var(--gold2); text-align: center; padding: 6px; font-weight: 700; font-size: 15px; }

.settings { display: grid; gap: 10px; text-align: left; }
.toggle { display: flex; align-items: center; gap: 12px; font-size: 18px; }
.toggle input { width: 26px; height: 26px; accent-color: var(--gold); }
dialog { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 520px; width: calc(100% - 30px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 8, 20, .7); }
dialog h2 { margin-top: 0; font-family: var(--serif); color: var(--gold); }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--card2); border: 1px solid var(--line); padding: 12px 20px; border-radius: 14px; box-shadow: var(--shadow); z-index: 100; max-width: 90vw; }

/* formatted words (both pages) */
.words { white-space: normal; }
.words p, .reader p { margin: 0 0 1em; }
hr.scene { border: 0; text-align: center; margin: 1.6em 0; }
hr.scene::after { content: "✦  ✦  ✦"; color: var(--gold); letter-spacing: .3em; }
blockquote { margin: 0 0 1em; padding: .2em 1em; border-left: 3px solid var(--gold); color: var(--muted); font-style: italic; }

/* reader */
.reader { max-width: 720px; margin: 0 auto; padding: 0 22px 80px; font-family: var(--serif); font-size: var(--rs, 21px); line-height: 1.7; }
.r-tools { display: flex; gap: 8px; align-items: center; padding: 14px 0; font-family: var(--font); font-size: 16px; position: sticky; top: 66px; background: inherit; }
.r-tools .grow { flex: 1; }
.r-ch { font-size: 1.6em; text-align: center; color: var(--gold); margin: 1.4em 0 .6em; line-height: 1.2; }
.r-title { font-size: 1em; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); text-align: center; margin: 2em 0 1em; font-family: var(--font); font-size: 14px; }
.r-seg h3, .r-seg h4, .r-seg h5 { line-height: 1.3; }
.reader .choice-panel, .reader .end-panel { font-family: var(--font); font-size: 18px; text-align: center; }
html.paper, body.paper { background: #f7f1e3; color: #2b2418; --muted: #6f6455; --line: #d8ccb2; --card: #efe6d2; --card2: #e6dbc2; --bg2: #efe6d2; --gold: #9a6a12; --gold2: #7a530c; --teal: #2f7d72; --text: #2b2418; color-scheme: light; }
body.paper .top { background: rgba(247, 241, 227, .94); }
body.paper .choice-panel { background: #efe6d2; }
body.paper .choice .num, body.paper .btn.gold { color: #fff; }
