@font-face { font-family: Poppins; src: url(/fonts/Poppins-Light.ttf); font-weight: 300; font-display: swap; }
@font-face { font-family: Poppins; src: url(/fonts/Poppins-Regular.ttf); font-weight: 400; font-display: swap; }
@font-face { font-family: Poppins; src: url(/fonts/Poppins-SemiBold.ttf); font-weight: 600; font-display: swap; }
@font-face { font-family: Poppins; src: url(/fonts/Poppins-Bold.ttf); font-weight: 700; font-display: swap; }
:root {
  --forest: #2D5638; --forest-deep: #1F3E28; --gold: #BE992D; --gold-deep: #97781F; --gold-soft: #FBF5E3;
  --sage: #8EB07E; --sage-soft: #EEF4EA; --sand: #D4C5A0; --terra: #C4471A; --ink: #1A1208; --muted: #6E6558;
  --line: #E9E3D6; --bg: #FBF6EA; --card: #FFFFFF; --r: 16px; --shadow: 0 2px 10px rgba(26, 18, 8, .07);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: Poppins, system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
#app { height: 100%; display: flex; flex-direction: column; }
.loading { margin: auto; text-align: center; color: var(--forest); font-weight: 600; }
.loading img { width: 96px; border-radius: 50%; border: 3px solid var(--gold); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.05); } }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 999px; font-weight: 600; background: var(--forest); color: #fff; transition: transform .1s, background .2s, opacity .2s; }
.btn:hover { background: var(--forest-deep); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: var(--gold-deep); color: #fff; }
.btn.ghost { background: #fff; color: var(--forest); border: 1.5px solid var(--line); }
.btn.ghost:hover { border-color: var(--sage); background: var(--sage-soft); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 999px; background: #fff; border: 1.5px solid var(--line); color: var(--forest); font-weight: 600; font-size: 14px; }
.chip:hover { border-color: var(--gold); background: var(--gold-soft); }
.chip:disabled { opacity: .4; cursor: default; }
.chip .lvl { display: inline-flex; gap: 3px; }
.chip .lvl i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.chip .lvl i.on { background: var(--gold); }

/* ---------- auth screens ---------- */
.center { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px 16px; overflow: auto; }
.card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 440px; }
.card h1 { font-size: 26px; margin: 8px 0 4px; color: var(--forest); }
.card h2 { font-size: 18px; margin: 18px 0 6px; color: var(--forest); }
.card p { margin: 6px 0; color: var(--muted); }
.hero { text-align: center; }
.hero img { width: 112px; height: 112px; border-radius: 50%; border: 4px solid var(--gold); box-shadow: 0 0 0 6px var(--gold-soft); }
.field { display: block; margin: 12px 0; }
.field span { display: block; font-size: 14px; font-weight: 600; color: var(--forest); margin-bottom: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 10px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--gold); }
.err { color: var(--terra); font-weight: 600; min-height: 1.5em; margin-top: 6px; }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 18px; }
.who button { padding: 18px 10px; border-radius: 16px; border: 2px solid var(--line); background: #fff; font-weight: 600; color: var(--forest); }
.who button:hover, .who button.on { border-color: var(--gold); background: var(--gold-soft); }
.pin { display: flex; justify-content: center; gap: 10px; margin: 18px 0 8px; }
.pin i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--forest); }
.pin i.on { background: var(--forest); }
.pad { display: grid; grid-template-columns: repeat(3, 72px); gap: 10px; justify-content: center; }
.pad button { height: 56px; border-radius: 14px; background: var(--sage-soft); font-size: 22px; font-weight: 600; color: var(--forest); }
.pad button:hover { background: var(--gold-soft); }
.linkish { color: var(--muted); font-size: 14px; text-decoration: underline; margin-top: 14px; }

/* ---------- top bar ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--forest); color: #fff; flex: none; }
.top .me { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.top .me img { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--gold); }
.top .sp { flex: 1; }
.top .nuts { display: flex; align-items: center; gap: 6px; background: rgba(255, 255, 255, .12); padding: 4px 12px; border-radius: 999px; font-weight: 600; }
.top .nuts.bump { animation: bump .6s; }
@keyframes bump { 40% { transform: scale(1.25); background: var(--gold); } }
.top .tb { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.top .tb:hover { background: rgba(255, 255, 255, .14); }
.top .tb svg { width: 22px; height: 22px; }
.top .badges { display: flex; gap: 4px; }
.top .badges img { width: 30px; height: 30px; }
.tabs { display: flex; gap: 4px; }
.tabs button { color: #e8efe6; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.tabs button.on, .tabs button:hover { background: rgba(255, 255, 255, .16); color: #fff; }

/* ---------- tutor ---------- */
.main { flex: 1; display: flex; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.stream { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; }
.stream-in { max-width: 860px; margin: 0 auto; }
.problem { background: #fff; border-left: 5px solid var(--gold); border-radius: 0 var(--r) var(--r) 0; box-shadow: var(--shadow); padding: 12px 18px; margin: 4px 0 18px; }
.problem .lbl { font-size: 13px; font-weight: 700; color: var(--gold-deep); text-transform: uppercase; letter-spacing: .04em; }
.problem .st { margin-top: 4px; }
.problem .st p { margin: 4px 0; }
.msg { display: flex; gap: 12px; margin: 12px 0; align-items: flex-start; }
.msg .av { width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--gold); flex: none; }
.msg.speaking .av { animation: halo 1.2s ease-in-out infinite; }
@keyframes halo { 50% { box-shadow: 0 0 0 6px rgba(190, 153, 45, .25); } }
.bubble { background: #fff; border-radius: 4px var(--r) var(--r) var(--r); padding: 12px 16px; box-shadow: var(--shadow); max-width: 680px; min-width: 0; }
.step { opacity: 0; transform: translateY(6px); transition: opacity .45s, transform .45s; }
.step.show { opacity: 1; transform: none; }
.step + .step { margin-top: 10px; }
.step .say { margin: 0; }
.step .tex { margin: 8px 0 2px; padding: 8px 12px; background: var(--gold-soft); border-radius: 10px; overflow-x: auto; font-size: 1.15em; }
.step.now .say { color: var(--forest-deep); }
.msg.me { justify-content: flex-end; }
.msg.me .bubble { background: var(--forest); color: #fff; border-radius: var(--r) 4px var(--r) var(--r); }
.msg.me .bubble .kind { font-size: 12px; opacity: .75; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.msg.me .shot { max-width: 260px; border-radius: 10px; display: block; margin-top: 6px; background: #fff; }
.fr { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.fr .fr-b { font-size: 12px; color: var(--muted); border: 1px dashed var(--sand); border-radius: 999px; padding: 2px 10px; }
.fr .fr-w { font-size: 13px; background: var(--sage-soft); color: var(--forest); border-radius: 999px; padding: 2px 10px; }
.typing { display: inline-flex; gap: 5px; padding: 6px 2px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--sage); animation: dot 1s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 50% { transform: translateY(-5px); opacity: .5; } }
.welcome { text-align: center; padding: 30px 10px 10px; color: var(--muted); }
.welcome img { width: 104px; border-radius: 50%; border: 4px solid var(--gold); }
.welcome h1 { color: var(--forest); margin: 10px 0 2px; font-size: 26px; }
.examples { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }

.endcard { background: #fff; border: 2px solid var(--gold); border-radius: var(--r); padding: 14px 18px; margin: 14px 0 14px 56px; box-shadow: var(--shadow); }
.endcard h3 { margin: 0 0 8px; color: var(--forest); font-size: 17px; }
.endcard .row { display: flex; flex-wrap: wrap; gap: 8px; }
.reward { position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--gold); color: var(--ink); font-weight: 700; font-size: 26px; padding: 14px 26px; border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); animation: pop 1.8s forwards; pointer-events: none; z-index: 50; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.7); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); } 75% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -90%); } }

.composer { flex: none; border-top: 1px solid var(--line); background: #fff; padding: 10px 16px 12px; }
.composer-in { max-width: 860px; margin: 0 auto; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.inrow { display: flex; gap: 8px; align-items: flex-end; }
.inrow textarea { flex: 1; resize: none; min-height: 46px; max-height: 140px; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 14px; outline: none; background: var(--bg); }
.inrow textarea:focus { border-color: var(--gold); background: #fff; }
.round { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--sage-soft); color: var(--forest); }
.round:hover { background: var(--gold-soft); }
.round svg { width: 22px; height: 22px; }
.round.send { background: var(--forest); color: #fff; }
.round.send:hover { background: var(--forest-deep); }
.round.rec { background: var(--terra); color: #fff; animation: halo 1.2s infinite; }
.round:disabled { opacity: .4; cursor: default; }
.limit { margin: auto; text-align: center; }

/* ---------- drawing board ---------- */
.board { position: fixed; inset: 0; background: rgba(26, 18, 8, .45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 16px; }
.board-in { background: #fff; border-radius: 20px; padding: 14px; width: min(980px, 100%); display: flex; flex-direction: column; gap: 10px; max-height: 100%; }
.board canvas { width: 100%; aspect-ratio: 16 / 8; border: 1.5px solid var(--line); border-radius: 12px; touch-action: none; background: #fff; cursor: crosshair; }
.board .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.board .pen { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--line); }
.board .pen.on { box-shadow: 0 0 0 3px var(--gold); }
.board video { width: 100%; border-radius: 12px; background: #000; max-height: 60vh; }

/* ---------- pages (history, traps, parent) ---------- */
.page { flex: 1; overflow-y: auto; padding: 20px 16px 40px; }
.page-in { max-width: 980px; margin: 0 auto; }
.page h1 { color: var(--forest); font-size: 24px; margin: 4px 0 12px; }
.page h2 { color: var(--forest); font-size: 18px; margin: 22px 0 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: #fff; border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; color: var(--forest); }
.stat span { color: var(--muted); font-size: 14px; }
.list { background: #fff; border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.list table { width: 100%; border-collapse: collapse; font-size: 14px; }
.list th { text-align: left; background: var(--sage-soft); color: var(--forest); padding: 8px 10px; font-weight: 600; }
.list td { padding: 8px 10px; border-top: 1px solid var(--line); }
.list tr.click { cursor: pointer; } .list tr.click:hover td { background: var(--gold-soft); }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--sage-soft); color: var(--forest); }
.tag.solved { background: #e3f0dd; } .tag.revealed { background: #f8e3d9; color: var(--terra); } .tag.open { background: var(--gold-soft); color: var(--gold-deep); }
.md p { margin: 6px 0; } .md h3 { color: var(--forest); margin: 16px 0 4px; font-size: 17px; } .md ul { margin: 4px 0; padding-left: 22px; }
.transcript .msg .bubble .step { opacity: 1; transform: none; }
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 14px; }
.chapters label { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.badgegrid { display: flex; flex-wrap: wrap; gap: 14px; }
.badgegrid .bd { width: 130px; text-align: center; font-size: 13px; color: var(--muted); }
.badgegrid .bd img { width: 84px; height: 84px; }
.badgegrid .bd.off img { filter: grayscale(1); opacity: .35; }
.note { background: var(--gold-soft); border-radius: 12px; padding: 10px 14px; font-size: 14px; color: var(--ink); }

/* ---------- diagrams ---------- */
.dg-wrap { margin: 8px 0 2px; }
.dg { width: 100%; max-width: 520px; height: auto; display: block; }
.dg-rect { max-width: 420px; } .dg-graph { max-width: 300px; }
.dg-t { font-family: Poppins, sans-serif; font-size: 14px; fill: var(--ink); }
.dg-b { font-weight: 600; } .dg-s { font-size: 11px; fill: var(--muted); } .dg-big { font-size: 18px; font-weight: 600; }
.dg-draw { stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: draw 1.6s ease-out forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.dg-table { border-collapse: collapse; margin: 6px 0; font-size: 15px; }
.dg-table th, .dg-table td { border: 1.5px solid var(--forest); padding: 4px 14px; text-align: center; }
.dg-table th { background: var(--sage-soft); color: var(--forest); }

@media (max-width: 640px) {
  .tabs button span { display: none; }
  .endcard { margin-left: 0; }
  .top .me span { display: none; }
}
