:root {
  --accent: #C2531B;
  --accent-soft: #FBEADF;
  --text: #1C1F2E;
  --muted: #5A6075;
  --line: #E3E5EC;
  --bg: #F4F5F8;
  --card: #FFFFFF;
  --chip: #F0F1F5;
  --ok: #1F8A4C;
  --warn: #B7791F;
  --bad: #C0392B;
  --radius: 14px;
  --font: 'Nunito', system-ui, sans-serif;
  --head: 'Fredoka', 'Nunito', system-ui, sans-serif;
  --fs: 15px;
}
[data-bg="warm"] { --bg: #FBF4EC; --chip: #F5EBDD; --line: #EADCC9; }
[data-bg="cool"] { --bg: #EEF4FA; --chip: #E1EBF5; --line: #D3E0EC; }
[data-bg="dark"] { --bg: #171923; --card: #222534; --text: #EDEFF5; --muted: #A4A9BC; --line: #33374A; --chip: #2C3042; --accent-soft: #3A2A22; }
[data-font="clean"] { --font: system-ui, -apple-system, 'Segoe UI', sans-serif; --head: system-ui, -apple-system, 'Segoe UI', sans-serif; }
[data-font="big"] { --fs: 18px; }
[data-corners="soft"] { --radius: 8px; }
[data-corners="sharp"] { --radius: 2px; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: var(--fs); line-height: 1.45; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--head); font-weight: 600; margin: 0 0 .4em; line-height: 1.15; }
h1 { font-size: 1.8em; } h2 { font-size: 1.3em; } h3 { font-size: 1.05em; }
a { color: var(--accent); }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* Buttons and inputs */
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 999px; padding: 8px 16px; font-weight: 700; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.07); }
.ghost { background: transparent; border-color: transparent; }
.danger { color: var(--bad); }
.icon { padding: 6px 10px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label { display: block; font-weight: 700; font-size: .9em; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.check input { width: auto; margin-top: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.err { color: var(--bad); font-weight: 700; min-height: 1.2em; }
.badge { display: inline-block; font-size: .75em; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.ok { background: #E3F4EA; color: var(--ok); } .badge.warn { background: #FBF0DC; color: var(--warn); } .badge.bad { background: #FBE4E1; color: var(--bad); }
.logo { font-family: var(--head); font-weight: 700; font-size: 1.35em; color: var(--accent); text-decoration: none; letter-spacing: -.01em; }
.logo span { color: var(--text); }

/* Hover words (dev terms) */
.term { border-bottom: 2px dotted var(--accent); cursor: help; position: relative; }
.tip { position: fixed; z-index: 100; max-width: 260px; background: var(--text); color: var(--card); padding: 8px 12px; border-radius: 10px; font-size: .85em; font-weight: 600; pointer-events: none; box-shadow: 0 6px 24px rgba(0,0,0,.18); }

/* Public pages */
.public { min-height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
.center { flex: 1; display: grid; place-items: center; padding: 32px 16px; }
.hero { text-align: center; max-width: 560px; }
.hero h1 { font-size: 2.6em; color: var(--accent); }
.hero .pills { justify-content: center; margin: 18px 0 26px; }
.authbox { width: 100%; max-width: 420px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border-radius: 999px; }
.tabs button.on { background: var(--text); color: var(--card); border-color: var(--text); }

/* Pills */
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { background: var(--card); border: 1.5px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .92em; }
.pill:hover { border-color: var(--accent); color: var(--accent); }
.pill.static { cursor: default; }

/* Grown-up area */
.page { max-width: 1040px; margin: 0 auto; padding: 24px 16px 60px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.kidcard .avatar { font-size: 2.4em; }
.dreamrow { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: .92em; cursor: pointer; }
.dreamrow:hover { color: var(--accent); }
.avatars { display: flex; flex-wrap: wrap; gap: 6px; }
.avatars button { font-size: 1.5em; padding: 4px 8px; border-radius: 12px; }
.avatars button.on { border-color: var(--accent); background: var(--accent-soft); }

/* Tables (admin) */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9em; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.stat b { display: block; font-size: 1.8em; font-family: var(--head); }
.prov { display: grid; grid-template-columns: 1fr; gap: 10px; }
.prov .card { padding: 14px 16px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em; }

/* ===== Kid workspace (agent layout) ===== */
.ws { display: grid; grid-template-columns: 250px 1fr 370px; height: 100vh; height: 100dvh; }
.side { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side .top { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.side .list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.side .item { display: block; width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 9px 10px; background: transparent; font-weight: 600; }
.side .item:hover { background: var(--chip); }
.side .item.on { background: var(--accent-soft); color: var(--accent); }
.side .item small { display: block; color: var(--muted); font-weight: 600; font-size: .78em; }
.side .foot { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 6px; align-items: center; }
.me { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.me .av { font-size: 1.6em; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.mainbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--card); }
.mainbar .title { font-family: var(--head); font-weight: 600; font-size: 1.1em; border: 0; background: transparent; padding: 4px 6px; width: auto; min-width: 80px; flex: 1; }
.stages { display: flex; gap: 4px; padding: 10px 14px; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--card); scrollbar-width: none; }
.stages button { border-radius: 999px; padding: 6px 12px; font-size: .88em; white-space: nowrap; background: var(--chip); border-color: transparent; color: var(--muted); }
.stages button.on { background: var(--accent); color: #fff; }
.stages button.done { color: var(--ok); }
.chat { flex: 1; overflow-y: auto; padding: 20px 16px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 720px; width: fit-content; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.msg.ai { align-self: flex-start; display: flex; gap: 10px; }
.msg.ai .bot { flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); display: grid; place-items: center; font-size: 1.1em; }
.msg.ai .bubble { background: var(--card); border: 1px solid var(--line); padding: 10px 14px; border-radius: 4px 18px 18px 18px; }
.msg .termcard { margin-top: 8px; font-size: .85em; background: var(--chip); border-radius: 10px; padding: 6px 10px; }
.msg .next { margin-top: 8px; }
.typing { color: var(--muted); font-style: italic; }
.composer { padding: 10px 14px 14px; border-top: 1px solid var(--line); background: var(--card); }
.composer .pills { margin-bottom: 10px; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 46px; max-height: 160px; border-radius: 16px; }
.composer .hint { font-size: .78em; color: var(--muted); margin-top: 6px; }

.spec { background: var(--card); border-left: 1px solid var(--line); overflow-y: auto; padding: 16px; }
.spec .id { font-family: ui-monospace, Menlo, monospace; font-size: .8em; color: var(--muted); }
.meter { margin: 10px 0 16px; }
.meter .bar { height: 12px; border-radius: 999px; background: var(--chip); overflow: hidden; position: relative; }
.meter .fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.meter .marks { position: relative; height: 0; }
.meter .marks i { position: absolute; top: -12px; width: 2px; height: 12px; background: var(--card); }
.meter .lbl { display: flex; justify-content: space-between; font-size: .8em; font-weight: 700; margin-top: 6px; }
.sec { border-top: 1px solid var(--line); padding: 12px 0; }
.sec > h3 { display: flex; align-items: center; gap: 6px; font-size: .95em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sec.cur > h3 { color: var(--accent); }
.fld { margin: 8px 0; }
.fld .k { font-size: .8em; font-weight: 800; color: var(--muted); }
.fld .v { font-size: .93em; }
.fld ul { margin: 2px 0 0; padding-left: 18px; font-size: .93em; }
.fld li { margin: 2px 0; }
.fld .v.empty, .fld .empty { color: var(--muted); font-style: italic; }
.fld .edit { float: right; font-size: .75em; padding: 0 6px; border: 0; color: var(--muted); background: transparent; }
.guess { border: 2px dashed var(--accent); border-radius: 14px; padding: 8px 10px; margin: 6px 0; font-size: .9em; background: var(--accent-soft); }
.guess.kept { border-style: solid; border-color: var(--line); background: transparent; }
.guess .acts { display: flex; gap: 6px; margin-top: 6px; }
.guess .acts button { padding: 2px 10px; font-size: .82em; }
.specbtn { display: none; }

.demobar { background: var(--accent-soft); color: var(--text); font-size: .85em; font-weight: 700; padding: 6px 14px; border-bottom: 1px solid var(--line); }
/* Modal + toast */
.overlay { position: fixed; inset: 0; background: rgba(15,17,26,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border-radius: 18px; padding: 22px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; }
.modal.wide { max-width: 720px; }
.pinpad { display: flex; gap: 8px; justify-content: center; margin: 14px 0; }
.pinpad input { width: 180px; text-align: center; font-size: 1.6em; letter-spacing: .4em; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 999px; font-weight: 700; z-index: 60; max-width: 90vw; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches button { width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--text); }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button.on { background: var(--text); color: var(--card); border-color: var(--text); }
pre.preview { white-space: pre-wrap; background: var(--chip); border-radius: 10px; padding: 12px; font-size: .82em; max-height: 50vh; overflow: auto; }

/* Tablet: hide sidebar behind menu */
.menubtn { display: none; }
@media (max-width: 1100px) {
  .ws { grid-template-columns: 1fr 340px; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .ws.sideopen .side { transform: none; }
  .menubtn { display: inline-flex; }
}
/* Phone: spec becomes a drop-down panel */
@media (max-width: 760px) {
  .ws { grid-template-columns: 1fr; }
  .spec { position: fixed; z-index: 30; left: 0; right: 0; top: 54px; bottom: 0; transform: translateY(-110%); transition: transform .2s; border-left: 0; border-top: 1px solid var(--line); }
  .ws.specopen .spec { transform: none; }
  .specbtn { display: inline-flex; padding: 6px 10px; white-space: nowrap; }
  .mainbar { gap: 4px; padding: 8px 10px; }
  .mainbar button { padding: 6px 10px; }
  .dl-label { display: none; }
  .composer .hint { display: none; }
  .msg { max-width: 92%; }
  .hero h1 { font-size: 2em; }
}
