/* TEDDY'S FUTURE LAB — design system (shared base). "Space" = deep navy with bright glows (default). "Sky" = light and airy.
   The child screens add their own layer in kids.css. */
@font-face { font-family: "Lab Sans"; src: url("/fonts/Poppins-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Lab Sans"; src: url("/fonts/Poppins-Medium.ttf") format("truetype"); font-weight: 500 600; font-display: swap; }
@font-face { font-family: "Lab Sans"; src: url("/fonts/Poppins-Bold.ttf") format("truetype"); font-weight: 700 900; font-display: swap; }
:root {
  --font: "Lab Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --display: "Lab Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 18px; --radius-sm: 12px; --radius-lg: 26px;
  --sidebar: 252px; --topbar: 60px; --tabbar: 64px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(.2,.8,.2,1);
}
/* Sizes that follow the window. On a very large screen (a 4K monitor or television at its true size) the whole app is enlarged — see the end of
   this file — and these three shrink by the same amount, so "the height of the window" still means the height of the window. */
:root { --zoom: 1; --vw: 1vw; --vh: 1vh; --dvh: 1vh; }
@supports (height: 1dvh) { :root { --dvh: 1dvh; } }
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050a24; --bg2: #09113a; --panel: #0e1848; --panel2: #14225c; --panel3: #1b2c74;
  --line: #2a3d92; --line2: #4767d8; --text: #f3f7ff; --muted: #aebcec; --faint: #7f90c8;
  --gold: #ffcb3d; --gold2: #ffe27f; --gold-ink: #2a1a00; --blue: #2f8fff; --blue2: #72c4ff;
  --ok: #3ddc84; --warn: #ffb020; --danger: #ff6b81; --info: #72c4ff;
  --glow: 0 0 0 1px rgba(71,103,216,.5), 0 0 22px rgba(47,143,255,.22), 0 10px 40px rgba(0,0,0,.45);
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --hero: linear-gradient(135deg, rgba(47,143,255,.22), rgba(255,203,61,.10) 60%, transparent);
  --input: #081033; --chip: #16256a; --me: linear-gradient(135deg, #2f8fff, #1c5fd0); --her: #101c52;
  --sky: radial-gradient(1200px 700px at 78% -10%, rgba(88,64,220,.38), transparent 60%), radial-gradient(900px 600px at 0% 100%, rgba(22,120,255,.28), transparent 60%), #050a24;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #e8f3ff; --bg2: #ffffff; --panel: #ffffff; --panel2: #f1f7ff; --panel3: #e1edff;
  --line: #cbdcf6; --line2: #93b9ee; --text: #13204c; --muted: #4f608e; --faint: #7b89ad;
  --gold: #e59a00; --gold2: #ffbf2f; --gold-ink: #ffffff; --blue: #1f6fe0; --blue2: #1f6fe0;
  --ok: #128a45; --warn: #b26d00; --danger: #cf2c45; --info: #1f6fe0;
  --glow: 0 0 0 1px rgba(31,111,224,.22), 0 10px 30px rgba(30,70,150,.12);
  --shadow: 0 6px 24px rgba(30,70,150,.10);
  --hero: linear-gradient(135deg, rgba(31,111,224,.14), rgba(255,191,47,.14) 60%, transparent);
  --input: #ffffff; --chip: #e8f1ff; --me: linear-gradient(135deg, #2f8fff, #1c5fd0); --her: #f1f7ff;
  --sky: radial-gradient(1200px 700px at 78% -10%, rgba(120,190,255,.55), transparent 60%), radial-gradient(900px 600px at 0% 100%, rgba(255,214,120,.35), transparent 60%), #e8f3ff;
}
:root[data-contrast="high"] { --line: #ffffff; --line2: #ffffff; --muted: #ffffff; --faint: #e6e6e6; --panel: #000; --panel2: #000; --panel3: #111; --bg: #000; --bg2: #000; --text: #fff; --input: #000; --chip: #000; --sky: #000; --gold: #ffe600; --blue: #5cc8ff; --blue2: #9fe0ff; }
:root[data-theme="light"][data-contrast="high"] { --line: #000; --line2: #000; --muted: #000; --faint: #222; --panel: #fff; --panel2: #fff; --panel3: #f2f2f2; --bg: #fff; --bg2: #fff; --text: #000; --input: #fff; --chip: #fff; --sky: #fff; --gold: #7a4b00; --gold-ink: #fff; --blue: #003fa8; --blue2: #003fa8; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body { background: var(--sky); background-attachment: fixed; color: var(--text); font: 15px/1.5 var(--font); overflow: hidden; }
body[data-font="plain"] { --font: Verdana, Tahoma, "Segoe UI", Arial, sans-serif; --display: Verdana, Tahoma, Arial, sans-serif; letter-spacing: .02em; word-spacing: .08em; line-height: 1.7; }
body.text-lg { font-size: 17px; } body.text-xl { font-size: 19px; }
a { color: var(--blue2); } :root[data-theme="light"] a:not([class]) { color: var(--blue); }
a.navlink, a.tile, a.li, a.me-chip, a.iconbtn { color: var(--text); }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: var(--gold); color: var(--gold-ink); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- app frame ---------- */
#app { height: 100%; display: grid; grid-template-rows: calc(var(--topbar) + var(--safe-t)) 1fr; grid-template-columns: var(--sidebar) 1fr; grid-template-areas: "top top" "side main"; }
#app.bare { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
#app.bare #sidebar, #app.bare #tabbar { display: none; }
#topbar { grid-area: top; display: flex; align-items: center; gap: 10px; padding: var(--safe-t) calc(14px + var(--safe-r)) 0 calc(14px + var(--safe-l)); background: color-mix(in srgb, var(--bg2) 88%, transparent); border-bottom: 1px solid var(--line); position: relative; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--gold); font: 800 19px/1 var(--display); letter-spacing: .01em; white-space: nowrap; }
.brand img { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 0 0 1px var(--line2); }
.brand span { background: linear-gradient(180deg, var(--gold2), var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.grow { flex: 1; }
.iconbtn { width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 12px; border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text); font-size: 19px; position: relative; flex: none; }
.iconbtn:hover { background: var(--panel2); border-color: var(--line); }
.iconbtn svg { width: 21px; height: 21px; }
.badge { position: absolute; top: 3px; right: 3px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; }
.me-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px 3px 3px; cursor: pointer; color: var(--text); text-decoration: none; }
.me-chip img, .me-chip .ph { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--panel3); display: grid; place-items: center; font-weight: 700; }

#sidebar { grid-area: side; overflow-y: auto; background: var(--bg2); border-right: 1px solid var(--line); padding: 10px 10px calc(16px + var(--safe-b)) calc(10px + var(--safe-l)); overscroll-behavior: contain; }
.navsearch { width: 100%; margin: 4px 0 8px; }
.navgroup { margin: 12px 0 4px; padding: 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: var(--faint); font-weight: 700; }
.navlink { display: flex; align-items: center; gap: 11px; padding: 8px 10px; margin: 1px 0; border-radius: 11px; color: var(--text); text-decoration: none; border: 1px solid transparent; font-size: 14.5px; }
.navlink .ico { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 9px; background: var(--panel2); font-size: 15px; flex: none; }
.navlink:hover { background: var(--panel); border-color: var(--line); }
.navlink.active { background: linear-gradient(90deg, rgba(241,195,106,.18), rgba(63,169,255,.08)); border-color: var(--line2); }
.navlink.active .ico { background: var(--gold); }
#main { grid-area: main; overflow-y: auto; overflow-x: hidden; position: relative; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#view { padding: 22px calc(24px + var(--safe-r)) calc(40px + var(--safe-b)) calc(24px + var(--safe-l)); max-width: 1500px; margin: 0 auto; animation: fadein .25s var(--ease); }
#view.full { max-width: none; padding: 0; height: 100%; overflow: hidden; }
@keyframes fadein-sheet { from { opacity: 0; } to { opacity: 1; } }   /* 12.8: a sheet that sits on the bottom edge only fades in, so it never hangs below the screen while it appears */
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
#tabbar { display: none; }

/* ---------- typography & layout helpers ---------- */
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 28px; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 20px; } h3 { font-size: 16.5px; color: var(--gold); } h4 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; } .tiny { font-size: 11.5px; }
.gold { color: var(--gold); } .ok { color: var(--ok); } .danger { color: var(--danger); } .warn { color: var(--warn); }
.center { text-align: center; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; } .row.nowrap > * { min-width: 0; } .row.top { align-items: flex-start; } .row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.gauto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); } .gauto-s { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.span2 { grid-column: span 2; }
.pagehead { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.pagehead .title { flex: 1; min-width: 220px; }
.pagehead h1 { margin: 0; } .pagehead p { margin: 4px 0 0; color: var(--muted); }
.pagehead .emoji { font-size: 30px; width: 54px; height: 54px; display: grid; place-items: center; border-radius: 16px; background: var(--hero), var(--panel); border: 1px solid var(--line2); }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---------- panels & cards ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.panel.glow { box-shadow: var(--glow); }
.panel.hero { background: var(--hero), var(--panel); }
.panel > h3:first-child, .panel > .row:first-child > h3 { margin-top: 0; }
.panel.tight { padding: 12px; }
.card { background: var(--panel2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; min-width: 0; position: relative; }
.card.click { cursor: pointer; transition: transform .15s var(--ease), border-color .15s; }
.card.click:hover { transform: translateY(-2px); border-color: var(--line2); }
.card.sel { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 14px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); text-decoration: none; color: var(--text); cursor: pointer; transition: transform .15s var(--ease), border-color .15s; min-height: 92px; }
.tile:hover { transform: translateY(-2px); border-color: var(--line2); }
.tile .e { font-size: 24px; } .tile b { font-size: 14.5px; } .tile small { color: var(--muted); font-size: 12.5px; }
.stat { padding: 14px; border-radius: 14px; background: var(--panel2); border: 1px solid var(--line); }
.stat .v { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; } .stat .l { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.empty .e { font-size: 34px; display: block; margin-bottom: 6px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.li .main { flex: 1; min-width: 0; } .li .main b { display: block; overflow: hidden; text-overflow: ellipsis; }
.li .main small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; }
.li.done .main b { text-decoration: line-through; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); border: 1px solid var(--line); color: var(--text); max-width: 100%; }
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.pill.gold { color: var(--gold); border-color: var(--gold); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--chip); cursor: pointer; font-size: 13.5px; color: var(--text); }
.chip:hover { border-color: var(--line2); } .chip.on { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); font-weight: 700; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
@media (min-width: 900px) { .tabs { flex-wrap: wrap; overflow: visible; } }
.tab { padding: 9px 15px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; white-space: nowrap; color: var(--text); font-weight: 600; font-size: 14px; }
.tab.on { background: var(--gold); color: var(--gold-ink); border-color: var(--gold); }

/* ---------- forms ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 5px; font-weight: 600; }
.field, input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]), select, textarea {
  -webkit-appearance: none; appearance: none; width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--input); color: var(--text); outline: none; min-height: 44px; font-size: 16px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
textarea { resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 25%, transparent); }
input[type=range] { width: 100%; accent-color: var(--gold); min-height: 30px; }
input[type=checkbox], input[type=radio] { accent-color: var(--gold); width: 19px; height: 19px; }
.check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 14px; font-weight: 400; margin: 10px 0; cursor: pointer; }
.check input { flex: none; margin-top: 2px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); cursor: pointer; font-weight: 650; text-decoration: none; white-space: nowrap; transition: transform .1s, filter .15s, background .15s; }
.btn:hover { filter: brightness(1.1); } .btn:active { transform: scale(.98); }
.btn.primary { background: linear-gradient(180deg, #4aa3ff, #1f6fe0); color: #fff; border-color: #6cb6ff; box-shadow: 0 6px 18px rgba(31,111,224,.35); }
.btn.gold { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: var(--gold-ink); border-color: var(--gold); }
.btn.blue { background: linear-gradient(180deg, var(--blue2), var(--blue)); color: #fff; border-color: var(--blue); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13.5px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--panel3); border: 1px solid var(--line2); border-radius: 30px; transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; border-radius: 50%; background: var(--muted); transition: .2s var(--ease); }
.switch input:checked + span { background: var(--gold); border-color: var(--gold); }
.switch input:checked + span::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 2px; }
/* a file chooser inside a button-shaped label: invisible, but still reachable with the keyboard */
.pickfile { position: relative; }
.pickfile input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.pickfile:focus-within { outline: 2px solid var(--gold); outline-offset: 2px; }
.setting { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; } .setting .main { flex: 1; } .setting .main small { display: block; color: var(--muted); }
.formgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.formgrid .full { grid-column: 1 / -1; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0; }

/* ---------- chat ---------- */
.chat-wrap { display: grid; grid-template-columns: 270px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; position: relative; }
.chat-side, .chat-main { min-height: 0; }
.chat-side { border-right: 1px solid var(--line); background: var(--bg2); overflow-y: auto; padding: 12px; }
.chat-main { display: flex; flex-direction: column; min-width: 0; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--bg2); flex-wrap: wrap; }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 16px; display: flex; flex-direction: column; gap: 12px; overscroll-behavior: contain; }
.msg { max-width: min(760px, 88%); padding: 11px 15px; border-radius: 18px; line-height: 1.55; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--me); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--her); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.msg.notice { align-self: center; max-width: 92%; background: transparent; border: 1px dashed var(--line2); color: var(--muted); font-size: 13px; text-align: center; padding: 6px 12px; }
.msg.crisis { align-self: stretch; max-width: none; background: color-mix(in srgb, var(--danger) 12%, var(--panel)); border: 1px solid var(--danger); color: var(--text); }
.msg.action { align-self: flex-start; background: color-mix(in srgb, var(--ok) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--ok) 50%, transparent); font-size: 13.5px; padding: 6px 12px; }
.msg .who { font-size: 11.5px; color: var(--gold); font-weight: 700; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .08em; }
.msg .tools { display: flex; gap: 4px; margin-top: 6px; opacity: .75; }
.msg .tools button { background: transparent; border: 0; cursor: pointer; color: var(--muted); font-size: 13px; padding: 2px 6px; border-radius: 6px; }
.msg .tools button:hover { background: var(--panel3); color: var(--text); }
.msg .sources { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg .sources a { font-size: 12px; text-decoration: none; padding: 3px 9px; border-radius: 999px; background: var(--panel3); border: 1px solid var(--line); color: var(--text); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg img.att { max-width: 220px; border-radius: 10px; display: block; margin-top: 6px; }
.md p:last-child { margin-bottom: 0; } .md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; } .md li { margin: 2px 0; }
.md code { background: var(--panel3); padding: 1px 6px; border-radius: 6px; font-size: .92em; }
.md pre { background: var(--bg); border: 1px solid var(--line); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md h1, .md h2, .md h3 { font-size: 1.05em; color: var(--gold); margin: 10px 0 4px; }
.md blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--gold); color: var(--muted); }
.md table { border-collapse: collapse; width: 100%; font-size: 13.5px; margin: 6px 0; } .md td, .md th { border: 1px solid var(--line); padding: 5px 8px; }
.composer { border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-b)); background: var(--bg2); }
.composer .box { display: flex; gap: 8px; align-items: flex-end; background: var(--input); border: 1px solid var(--line); border-radius: 18px; padding: 6px; }
.composer .box:focus-within { border-color: var(--gold); }
.composer textarea { border: 0; background: transparent; min-height: 40px; max-height: 180px; resize: none; padding: 9px 6px; box-shadow: none !important; }
.composer .send { width: 44px; height: 44px; border-radius: 14px; flex: none; border: 0; background: linear-gradient(180deg, #4aa3ff, #1f6fe0); color: #fff; cursor: pointer; display: grid; place-items: center; }
.composer .send svg, .composer .iconbtn svg { width: 20px; height: 20px; }
.composer .attach-list { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.typing { display: inline-flex; gap: 4px; } .typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100% { opacity: .2; } 40% { opacity: 1; } }
.mic.on { background: var(--danger) !important; color: #fff !important; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,107,122,.6); } 100% { box-shadow: 0 0 0 14px rgba(255,107,122,0); } }
.conv { display: block; padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; color: var(--text); text-decoration: none; }
.conv:hover { background: var(--panel); } .conv.on { background: var(--panel); border-color: var(--line2); }
.conv b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conv small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }

/* ---------- gallery & media ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.gallery figure { margin: 0; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: var(--panel2); cursor: zoom-in; position: relative; }
.gallery img { width: 100%; height: 160px; object-fit: cover; display: block; transition: transform .3s var(--ease); }
.gallery figure:hover img { transform: scale(1.04); }
.gallery figcaption { padding: 6px 10px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(2,5,12,.92); display: grid; place-items: center; padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b)); cursor: zoom-out; animation: fadein .2s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: 0 20px 80px rgba(0,0,0,.6); }

/* ---------- modal, sheet, toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(2,6,15,.6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; animation: fadein .18s; }
.modal { width: min(560px, 100%); max-height: calc(calc(100 * var(--vh)) - 40px); max-height: calc(calc(100 * var(--dvh)) - 40px); overflow: auto; background: var(--panel); border: 1px solid var(--line2); border-radius: var(--radius-lg); padding: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.modal.wide { width: min(900px, 100%); }
.modal .mh { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; } .modal .mh h2 { flex: 1; margin: 0; }
.modal .mf { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
#toasts { position: fixed; z-index: 120; left: 50%; transform: translateX(-50%); bottom: calc(20px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(520px, calc(100% - 24px)); }
.toast { pointer-events: auto; background: var(--panel); border: 1px solid var(--line2); color: var(--text); padding: 11px 16px; border-radius: 14px; box-shadow: var(--shadow); animation: fadein .2s; font-size: 14px; max-width: 100%; }
.toast.ok { border-color: var(--ok); } .toast.err { border-color: var(--danger); }
.banner { padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line2); background: var(--hero), var(--panel); margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { border-color: var(--warn); } .banner.danger { border-color: var(--danger); }
.offline-bar { position: fixed; top: calc(var(--topbar) + var(--safe-t)); left: 0; right: 0; z-index: 25; text-align: center; background: var(--warn); color: #1b1204; font-size: 13px; font-weight: 600; padding: 4px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--gold); animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 60px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tblwrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.spark { width: 100%; height: 44px; }
.bar { height: 8px; border-radius: 8px; background: var(--panel3); overflow: hidden; } .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--blue)); border-radius: 8px; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar .dow { text-align: center; color: var(--muted); font-size: 12px; font-weight: 700; padding: 4px 0; }
.calendar .day { min-height: 74px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); padding: 5px; cursor: pointer; font-size: 12px; overflow: hidden; }
.calendar .day.other { opacity: .45; } .calendar .day.today { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.calendar .day .n { font-weight: 700; } .calendar .day .ev { display: block; margin-top: 2px; padding: 1px 5px; border-radius: 5px; background: var(--chip); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: var(--panel3); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px; max-height: 360px; overflow: auto; }
.diff { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px; max-height: 240px; overflow: auto; }
.auth-wrap { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr); }
.auth-art { position: relative; min-height: 100%; overflow: hidden; display: grid; place-items: center; background: radial-gradient(700px 500px at 30% 20%, rgba(111,76,255,.55), transparent 60%), radial-gradient(700px 500px at 80% 90%, rgba(47,143,255,.5), transparent 60%), #070d33; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 30px 22px calc(30px + var(--safe-b)); }
.auth-card { width: min(430px, 100%); }
.landing-hero { position: relative; border-radius: var(--radius-lg); overflow: hidden; min-height: 420px; display: flex; align-items: flex-end; background: radial-gradient(700px 500px at 20% 10%, rgba(111,76,255,.6), transparent 60%), radial-gradient(800px 500px at 90% 80%, rgba(47,143,255,.55), transparent 60%), #070d33; border: 1px solid var(--line2); }
.landing-hero .over { position: relative; z-index: 1; padding: 28px; width: 100%; color: #fff; }
.landing-hero h1 { font: 800 clamp(34px, calc(6 * var(--vw)), 64px)/1 var(--display); letter-spacing: 0; background: linear-gradient(180deg, #ffe3a3, #f1c36a); -webkit-background-clip: text; background-clip: text; color: transparent; margin: 0 0 8px; }
.price { font-size: 40px; font-weight: 800; } .price small { font-size: 15px; color: var(--muted); font-weight: 500; }
.feature-list { list-style: none; padding: 0; margin: 10px 0; } .feature-list li { padding: 5px 0 5px 26px; position: relative; } .feature-list li::before { content: "★"; position: absolute; left: 2px; color: var(--gold); }
.qr { background: #fff; padding: 10px; border-radius: 12px; display: inline-block; }

/* ---------- lock screen ---------- */
.lockscreen { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: calc(20px + var(--safe-t)) 20px calc(20px + var(--safe-b)); background: var(--bg); background-image: var(--hero); overflow: auto; }
.lockcard { width: min(400px, 100%); text-align: center; }
.lockcard img { border-radius: 24px; box-shadow: var(--glow); margin-bottom: 10px; width: 96px; height: 96px; }
.lockcard form { text-align: left; }

/* ---------- tablet ---------- */
@media (max-width: 1180px) {
  .chat-wrap { grid-template-columns: 240px minmax(0, 1fr); }
    .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1023px) {
  :root { --sidebar: 76px; }
  #sidebar { padding: 8px 6px; }
  #sidebar .navgroup, #sidebar .navlink span:not(.ico), #sidebar .navsearch { display: none; }   /* the narrow side menu shows the pictures only — never nothing */
  #sidebar .navlink { justify-content: center; padding: 7px; } #sidebar .navlink .ico { width: 38px; height: 38px; font-size: 19px; }
  #app.sidebar-open #sidebar { position: fixed; z-index: 60; top: calc(var(--topbar) + var(--safe-t)); bottom: 0; left: 0; width: 280px; box-shadow: var(--shadow); }
  #app.sidebar-open #sidebar .navgroup, #app.sidebar-open #sidebar .navlink span:not(.ico), #app.sidebar-open #sidebar .navsearch { display: block; }
  #app.sidebar-open #sidebar .navlink { justify-content: flex-start; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-wrap { grid-template-columns: 1fr; } .auth-art { min-height: 260px; }
}
/* ---------- phone ---------- */
@media (max-width: 699px) {
  :root { --topbar: 54px; }
  #app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; grid-template-rows: calc(var(--topbar) + var(--safe-t)) 1fr calc(var(--tabbar) + var(--safe-b)); }
  #app:not(.bare) { grid-template-areas: "top" "main" "tabs"; }
  #sidebar { display: none; }
  #app.sidebar-open #sidebar { display: block; position: fixed; inset: calc(var(--topbar) + var(--safe-t)) 0 0 0; width: auto; z-index: 70; padding: 10px 14px calc(90px + var(--safe-b)); }
  #app.sidebar-open #sidebar .navlink { padding: 11px 12px; }
  #tabbar { grid-area: tabs; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--bg2); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); z-index: 40; }
  #tabbar a, #tabbar button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; font-weight: 600; }
  #tabbar .e { font-size: 21px; line-height: 1; filter: grayscale(.4); }
  #tabbar .on { color: var(--gold); } #tabbar .on .e { filter: none; }
  #view { padding: 14px calc(14px + var(--safe-r)) 30px calc(14px + var(--safe-l)); }
  h1 { font-size: 23px; }
  .pagehead .emoji { width: 44px; height: 44px; font-size: 24px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .g2.keep, .g4.keep { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span2 { grid-column: auto; }
  .formgrid { grid-template-columns: 1fr; }
  .chat-wrap, .chat-wrap.nostage { grid-template-columns: 1fr; }
  .chat-side { display: none; } .chat-wrap.show-side .chat-side { display: block; position: absolute; inset: 0; z-index: 20; }
  .msg { max-width: 92%; }
  .composer { padding-bottom: 10px; }
  .clock, .me-chip .nm { display: none; }
  .brand { font-size: 19px; } .brand img { width: 30px; height: 30px; }
  .calendar .day { min-height: 54px; font-size: 11px; } .calendar .day .ev { display: none; } .calendar .day.has::after { content: "•"; color: var(--gold); font-size: 18px; line-height: 0; display: block; text-align: center; margin-top: 8px; }
  .gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); } .gallery img { height: 120px; }
  .modal { padding: 16px; border-radius: 18px; }
  .overlay { align-items: end; padding: 0; animation-name: fadein-sheet; } .overlay .modal { width: 100%; border-radius: 22px 22px 0 0; max-height: calc(92 * var(--dvh)); padding-bottom: calc(16px + var(--safe-b)); }
  .tbl { font-size: 13px; }
  #toasts { bottom: calc(var(--tabbar) + 14px + var(--safe-b)); }
}
/* ---------- very large screens: scale everything UP, so nothing is tiny or lost in an empty screen ---------- */
@media (min-width: 2400px) and (min-height: 1300px) { :root { --zoom: 1.25; } }
@media (min-width: 3000px) and (min-height: 1600px) { :root { --zoom: 1.6; } }
@media (min-width: 3600px) and (min-height: 1900px) { :root { --zoom: 2; } }
@media (min-width: 5000px) and (min-height: 2700px) { :root { --zoom: 2.6; } }
@media (min-width: 7000px) and (min-height: 3900px) { :root { --zoom: 4; } }
@media screen and (min-width: 2400px) and (min-height: 1300px) { :root { zoom: var(--zoom); --vw: calc(1vw / var(--zoom)); --vh: calc(1vh / var(--zoom)); --dvh: calc(1vh / var(--zoom)); } }
@media print { #topbar, #sidebar, #tabbar, .composer { display: none !important; } body { overflow: visible; } #main { overflow: visible; } }
/* an element marked hidden is hidden, whatever its class says */
[hidden] { display: none !important; }
/* 12.9.2: the sign-in / sign-up / testing card sits on its own panel, so its text is readable on the starry background in every theme */
.auth-card { box-sizing: border-box; max-width: 100%; background: var(--panel); border: 1px solid var(--line2); border-radius: 24px; padding: 26px 24px 22px; box-shadow: var(--shadow); }
.auth-card .tabs { flex-wrap: wrap; row-gap: 8px; }
.auth-card .row.nowrap > input { min-width: 0; flex: 1 1 auto; }
@media (max-width: 480px) { .auth-card { padding: 20px 16px 18px; border-radius: 20px; } .auth-card .tabs .tab { padding-inline: 12px; } }
.auth-wrap > * { min-width: 0; } .auth-form > .auth-card { flex: 0 1 430px; } .auth-card .btn.block { white-space: normal; }
