:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2430; --muted: #6b7686; --line: #dde2e9;
  --accent: #3b6df0; --accent-text: #fff; --xl: #fff3c4; --xl-line: #e3b505; --user: #e6edff; --ai: #f0f2f5;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --panel: #1c2027; --text: #e7eaf0; --muted: #98a2b3; --line: #2c333d;
    --accent: #6f93ff; --accent-text: #0b1020; --xl: #4a3f12; --xl-line: #c9a227; --user: #263556; --ai: #262b34;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, sans-serif; }
header { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; gap: 1rem; flex-wrap: wrap; }
h1 { margin: 0; font-size: 1.3rem; }
nav { display: flex; gap: .25rem; }
.tab { border: 0; background: transparent; color: var(--muted); padding: .4rem 1rem; border-radius: 999px; font: inherit; cursor: pointer; }
.tab.active { background: var(--accent); color: var(--accent-text); }
#settings { display: flex; flex-wrap: wrap; gap: .5rem 1rem; padding: .5rem 1rem; background: var(--panel); border-block: 1px solid var(--line); align-items: end; }
label { display: flex; flex-direction: column; font-size: .75rem; color: var(--muted); gap: .2rem; }
label.check { flex-direction: row; align-items: center; gap: .4rem; font-size: .85rem; color: var(--text); padding-bottom: .45rem; }
label.register { min-width: 190px; }
select, input:not([type=checkbox]):not([type=range]), button {
  font: inherit; padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text);
}
button { cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
[hidden] { display: none !important; }
main { max-width: 860px; margin: 0 auto; padding: 1rem; }
.controls { display: flex; flex-wrap: wrap; gap: .6rem 1rem; align-items: end; margin-bottom: .8rem; }
.grow { flex: 1 1 220px; }
output { font-size: .8rem; color: var(--text); }
.reading { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; font-size: 1.15rem; line-height: 1.7; }
#storyOut { min-height: 220px; white-space: pre-wrap; }
.hint { color: var(--muted); font-size: .95rem; white-space: normal; margin: 0; }
#chatLog { height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; padding: .8rem; }
.msg { max-width: 82%; padding: .55rem .85rem; border-radius: 14px; display: flex; gap: .5rem; align-items: flex-start; }
.msg .text { white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--user); }
.msg.assistant { align-self: flex-start; background: var(--ai); }
.msg .say { border: 0; background: none; padding: 0; font-size: 1rem; opacity: .6; }
.msg.err { color: #c0392b; }
.composer { display: flex; gap: .5rem; margin-top: .6rem; }
.composer input { flex: 1; }
#mic.on { background: #e5484d; color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }
/* Inline translations */
.xl { background: var(--xl); border-bottom: 2px solid var(--xl-line); border-radius: 3px; cursor: pointer; padding: 0 1px; }
.xl.loading { opacity: .6; animation: pulse 1s infinite; cursor: progress; }
.xl.failed { border-bottom-color: #e5484d; }
::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }
#toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: .5rem 1rem; border-radius: 8px; font-size: .9rem; z-index: 9; }

/* Accounts & profile */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1.2rem 1.4rem; margin: 1rem auto; max-width: 720px; }
.card.narrow { max-width: 400px; margin-top: 8vh; }
.card h1, .card h2 { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: .8rem; }
.stack label { font-size: .85rem; }
.stack input, .stack select { font-size: 1rem; }
.seg { display: flex; gap: .25rem; margin: .8rem 0; }
.seg .tab { flex: 1; border: 1px solid var(--line); }
.row { display: flex; gap: .6rem; }
.error { color: #d1383d; margin: 0; font-size: .9rem; }
.or { text-align: center; color: var(--muted); font-size: .85rem; margin: 1rem 0 .6rem; }
#googleBtn { display: flex; justify-content: center; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .6rem .8rem; }
legend { padding: 0 .4rem; font-size: .85rem; color: var(--muted); }
.learn { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .4rem .8rem; }
.learn .lrow { display: flex; align-items: center; gap: .5rem; font-size: .95rem; color: var(--text); }
.learn .lrow span { flex: 1; }
.learn select { width: 9.5rem; padding: .2rem .4rem; font-size: .8rem; }
.learn select:disabled { opacity: .35; }
.user { display: flex; gap: .8rem; align-items: center; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
header nav { margin-inline: auto; }
