:root {
  --paper: #fff6e9;
  --ink: #2b2118;
  --muted: #7a6a5a;
  --card: #fffdf8;
  --orange: #ff8c42;
  --orange-d: #e56a1a;
  --blue: #4f8cff;
  --mint: #22c55e;
  --pink: #fb7185;
  --purple: #8b5cf6;
  --gold: #f5c518;
  --shadow: 0 10px 28px rgba(90, 50, 20, .12);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Be Vietnam Pro', system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  padding-bottom: calc(84px + var(--safe-b));
}
body.admin-body, body.login-page, body.staff-user { padding-bottom: 24px; }
.app-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 400px at -10% -10%, rgba(255,140,66,.22), transparent 55%),
    radial-gradient(700px 380px at 110% 0%, rgba(79,140,255,.18), transparent 50%),
    repeating-linear-gradient(0deg, transparent, transparent 27px, rgba(180,140,90,.07) 28px);
}
a { color: inherit; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; position: sticky; top: 0; z-index: 20;
  background: rgba(255,246,233,.9); backdrop-filter: blur(10px);
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.menu-toggle {
  display: none;
  width: 42px; height: 42px; padding: 0; border: 0; border-radius: 14px;
  background: #fff; box-shadow: var(--shadow); cursor: pointer;
  place-items: center; flex-direction: column; gap: 5px; flex-shrink: 0;
}
.menu-toggle span {
  display: block; width: 18px; height: 2.5px; border-radius: 99px;
  background: var(--ink); transition: transform .2s ease, opacity .2s ease;
}
body.drawer-open .menu-toggle span:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
body.drawer-open .menu-toggle span:nth-child(2) { opacity: 0; }
body.drawer-open .menu-toggle span:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; text-decoration: none; font-size: 1.05rem; }
.brand-mark { font-size: 1.4rem; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.chip {
  background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: .85rem;
  box-shadow: var(--shadow); text-decoration: none; display: inline-flex; gap: 4px;
}
.chip-star { background: #fff7d1; }
.chip-fire { background: #ffe4d6; }
.avatar { font-size: 1.45rem; line-height: 1; }
.avatar-link { text-decoration: none; }
.main { width: min(920px, calc(100% - 28px)); margin: 0 auto; padding-bottom: 12px; }
.main-wide { width: min(1100px, calc(100% - 28px)); }
.flash { width: min(920px, calc(100% - 28px)); margin: 8px auto; padding: 12px 16px; border-radius: 14px; font-weight: 600; }
.flash-ok { background: #dcfce7; color: #166534; }
.flash-err { background: #fee2e2; color: #991b1b; }

.hero {
  background: linear-gradient(135deg, #ffb35c 0%, #ff8c42 55%, #ff6b6b 100%);
  color: #fff; border-radius: 28px; padding: 26px 24px; box-shadow: var(--shadow);
  display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px;
}
.hero h1 { margin: 0 0 6px; font-size: 1.55rem; }
.hero p { margin: 0; opacity: .95; }
.mascot { font-size: 4rem; filter: drop-shadow(0 8px 0 rgba(0,0,0,.08)); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); border: 2px solid rgba(255,255,255,.8);
}
.card h2, .card h3 { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--orange); color: #fff; text-decoration: none; border: 0;
  font: inherit; font-weight: 800; padding: 12px 18px; border-radius: 16px; cursor: pointer;
  box-shadow: 0 6px 0 var(--orange-d);
}
.btn:active { transform: translateY(2px); box-shadow: 0 4px 0 var(--orange-d); }
.btn-blue { background: var(--blue); box-shadow: 0 6px 0 #3b6ed6; }
.btn-mint { background: var(--mint); box-shadow: 0 6px 0 #16a34a; }
.btn-ghost { background: #fff; color: var(--ink); box-shadow: 0 4px 0 #e7d7c1; }
.btn-wide { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: .88rem; box-shadow: 0 4px 0 var(--orange-d); }
.btn-danger {
  background: #ef4444; box-shadow: 0 6px 0 #b91c1c;
}
.btn-sm.btn-danger { box-shadow: 0 4px 0 #b91c1c; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.table-actions form { margin: 0; }
.site-owner {
  width: min(920px, calc(100% - 28px));
  margin: 28px auto 16px;
}
.site-owner-card {
  display: flex;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(120px 80px at 100% 0%, rgba(255,179,92,.28), transparent 70%),
    linear-gradient(180deg, #fffdf8 0%, #fff3e4 100%);
  border: 2px solid rgba(255,255,255,.95);
  border-radius: 22px;
  padding: 16px 18px 16px 20px;
  box-shadow: var(--shadow);
}
.site-owner-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: linear-gradient(180deg, #ffb35c, #ff8c42 55%, #fb7185);
}
.site-owner-mark {
  width: 54px; height: 54px; flex-shrink: 0;
  border-radius: 18px;
  display: grid; place-items: center;
  font-size: 1.75rem;
  background: #fff7d1;
  box-shadow: 0 5px 0 #f0d9a8;
}
.site-owner-body { min-width: 0; }
.site-owner-name {
  margin: 0;
  font-weight: 800;
  font-size: 1.12rem;
  color: var(--ink);
  letter-spacing: .01em;
  line-height: 1.25;
}
.site-owner-role {
  display: inline-block;
  margin: 6px 0 8px;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .02em;
  color: #c2410c;
  background: #ffe4d6;
  border-radius: 999px;
  padding: 3px 10px;
}
.site-owner-school,
.site-owner-place {
  font-size: .84rem;
  color: var(--muted);
  line-height: 1.45;
}
.site-owner-place { margin-top: 2px; }
@media (max-width: 520px) {
  .site-owner-card { align-items: flex-start; padding: 14px 14px 14px 18px; }
  .site-owner-name { font-size: 1.02rem; }
}

.topic {
  display: block; text-decoration: none; background: #fff; border-radius: 22px;
  padding: 16px; box-shadow: var(--shadow); border-left: 8px solid var(--c, var(--blue));
  min-height: 120px;
}
.topic .ico { font-size: 1.8rem; }
.topic h3 { margin: 6px 0 4px; font-size: 1.05rem; }
.bar { height: 10px; background: #f3e6d4; border-radius: 99px; overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--mint), #86efac); width: 0; }

.lesson-row {
  display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 18px;
  padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); text-decoration: none;
  flex-wrap: wrap;
}
.num-badge {
  width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center;
  font-weight: 800; color: #fff; background: var(--blue); flex-shrink: 0;
}
.lesson-row .go { margin-left: auto; font-weight: 800; color: var(--orange); }
.done-dot { color: var(--mint); font-weight: 800; }

.learn-block { background: #fff; border-radius: 22px; padding: 18px 20px; margin-bottom: 14px; box-shadow: var(--shadow); }
.learn-block h2 { margin: 0 0 10px; font-size: 1.15rem; display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.ex-box { background: #fff4d6; border-radius: 16px; padding: 14px; font-weight: 600; margin: 10px 0; }
.learn-block ul { margin: 0; padding-left: 18px; }
.learn-block p { line-height: 1.65; }
.goal-box { background: #e8f0ff; border-radius: 16px; padding: 14px 16px; }
.goal-box li { margin: 4px 0; }
.tip-box { background: #dcfce7; border-radius: 16px; padding: 14px; margin: 10px 0; }
.warn-box { background: #ffe4e6; border-radius: 16px; padding: 14px; margin: 10px 0; }
.num-strip { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.num-strip span {
  width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: #4f8cff; color: #fff; font-weight: 800; font-size: 1.1rem;
}
.num-strip span.zero { background: #9ca3af; }
.num-strip span.ten { background: #ff8c42; }
.add-table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: .92rem; }
.add-table th, .add-table td { border: 1px solid #f3e6d4; padding: 6px 8px; text-align: center; }
.add-table th { background: #fff4d6; }
.steps { margin: 8px 0 0; padding-left: 22px; }
.steps li { margin: 6px 0; }
.emoji-row { font-size: 1.6rem; letter-spacing: .15em; margin: 8px 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .two-col { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 8px; }
.btn-speak {
  background: #8b5cf6; box-shadow: 0 6px 0 #6d28d9; white-space: nowrap;
}
.btn-speak.speaking { animation: pulse-speak 1s ease infinite; }
@keyframes pulse-speak { 50% { transform: scale(1.04); } }
.btn-speak-mini {
  display: inline-flex; align-items: center; margin-left: 10px; vertical-align: middle;
  background: #f3e8ff; color: #5b21b6; border: 0; border-radius: 999px;
  font: inherit; font-weight: 800; font-size: .78rem; padding: 6px 12px; cursor: pointer;
}
.btn-speak-mini.speaking { background: #8b5cf6; color: #fff; }
.speak-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 12px 0 16px; }
.prompt-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.prompt-row h2 { flex: 1; margin: 0; }
.speak-auto { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .92rem; margin: 8px 0; }
.speak-auto input { width: 22px; height: 22px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; flex-wrap: nowrap;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  background: #fffdf8; border-top: 2px solid #f3e6d4;
  padding: 6px 8px calc(8px + var(--safe-b));
  gap: 4px;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar a {
  flex: 1 0 auto;
  min-width: 68px;
  text-decoration: none; text-align: center; font-size: .72rem; font-weight: 700;
  color: #9a8774; padding: 6px 10px; border-radius: 12px;
  white-space: nowrap;
}
.tabbar a span { display: block; font-size: 1.2rem; }
.tabbar a.on { color: var(--orange-d); background: #fff1e0; }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; padding-bottom: 24px; }
.login-card { width: min(420px, 100%); background: #fff; border-radius: 28px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 8px 0 4px; }
.field { margin: 12px 0; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input, .field select, textarea {
  width: 100%; padding: 12px 14px; border: 2px solid #f3e6d4; border-radius: 14px; font: inherit; background: #fff;
}
.demo { background: #fff8e8; border-radius: 14px; padding: 12px; font-size: .88rem; margin-top: 14px; }

.q-card { background: #fff; border-radius: 28px; padding: 22px; box-shadow: var(--shadow); }
.progress-tiny { height: 8px; background: #f3e6d4; border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.progress-tiny > i { display: block; height: 100%; background: var(--orange); }
.visual { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0 18px; min-height: 48px; }
.obj { font-size: 2rem; line-height: 1; animation: pop .25s ease; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.eq { font-size: 2.2rem; font-weight: 800; text-align: center; letter-spacing: .04em; margin: 8px 0 16px; }
.choices { display: grid; gap: 10px; }
.choice {
  background: #fff8ee; border: 3px solid #f3e6d4; border-radius: 16px; padding: 14px;
  font-weight: 800; font-size: 1.15rem; cursor: pointer; text-align: center;
}
.choice:hover { border-color: var(--orange); }
.choice.on { border-color: var(--blue); background: #e8f0ff; }
.choice.good { border-color: var(--mint); background: #dcfce7; }
.choice.bad { border-color: var(--pink); background: #ffe4e6; }
.compare-row { display: flex; gap: 10px; justify-content: center; }
.compare-row .choice { min-width: 76px; font-size: 1.8rem; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 280px; margin: 12px auto; }
.key {
  background: #fff; border: 2px solid #f3e6d4; border-radius: 14px; padding: 14px;
  font-weight: 800; font-size: 1.3rem; cursor: pointer;
}
.answer-box {
  font-size: 2rem; font-weight: 800; text-align: center; min-height: 56px;
  border: 3px dashed #f3e6d4; border-radius: 16px; padding: 8px; margin: 8px auto; max-width: 220px;
}
.explain {
  display: none; margin-top: 14px; padding: 14px; border-radius: 16px; font-weight: 600;
}
.explain.show { display: block; }
.explain.ok { background: #dcfce7; }
.explain.no { background: #ffe4e6; }
.shapes { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.shape-btn { background: #fff8ee; border: 3px solid #f3e6d4; border-radius: 18px; padding: 10px; cursor: pointer; }
.shape-btn.on { border-color: var(--blue); }
.clock-wrap { display: flex; justify-content: center; margin: 8px 0 16px; }
.bars { display: grid; gap: 10px; margin: 10px 0 16px; }
.bar-item { display: flex; align-items: center; gap: 10px; }
.bar-item .track { height: 22px; background: var(--blue); border-radius: 8px; }

.stat { text-align: center; }
.stat .n { font-size: 1.8rem; font-weight: 800; }
.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.badge { text-align: center; padding: 16px 10px; border-radius: 20px; background: #fff; box-shadow: var(--shadow); opacity: .38; filter: grayscale(1); }
.badge.got { opacity: 1; filter: none; }
.badge .ic { font-size: 2rem; }

.table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 16px; overflow: hidden; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #f3e6d4; }
.table th { background: #fff4d6; font-size: .85rem; }
.admin-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.admin-nav .chip.on { background: #fff1e0; color: var(--orange-d); }

.drawer-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(43, 33, 24, .4);
  opacity: 0; pointer-events: none;
  transition: opacity .22s ease;
}
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 80;
  width: min(300px, 86vw);
  background: #fffdf8;
  box-shadow: 10px 0 32px rgba(90, 50, 20, .16);
  transform: translateX(-105%);
  transition: transform .24s ease;
  padding: 18px 12px 24px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
body.drawer-open { overflow: hidden; }
body.drawer-open .drawer { transform: translateX(0); }
body.drawer-open .drawer-backdrop { opacity: 1; pointer-events: auto; }
.drawer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 16px; margin-bottom: 6px;
  border-bottom: 2px solid #f3e6d4;
}
.drawer-title { font-weight: 800; font-size: 1.05rem; }
.drawer-label {
  font-size: .72rem; font-weight: 800; color: var(--muted);
  letter-spacing: .04em; text-transform: uppercase;
  padding: 14px 12px 6px;
}
.drawer a {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-radius: 14px;
  text-decoration: none; font-weight: 700;
}
.drawer a span { font-size: 1.15rem; width: 1.5em; text-align: center; }
.drawer a.on { background: #fff1e0; color: var(--orange-d); }
.drawer a:active { background: #fff4d6; }

@media (max-width: 860px) {
  .staff-user .menu-toggle { display: flex; }
  .staff-user .admin-nav,
  .staff-user .chip-admin { display: none; }
}
.pct { font-weight: 800; color: var(--mint); }
.danger { color: #b91c1c; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.share-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.groups { display: flex; gap: 24px; justify-content: center; align-items: end; }
.group { text-align: center; }
.ruler { width: min(320px, 100%); margin: 12px auto; }
.place-num { font-size: 3rem; font-weight: 800; text-align: center; }
.split-viz { display: flex; justify-content: center; gap: 16px; align-items: center; font-size: 1.4rem; font-weight: 800; }

@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero { flex-direction: column; text-align: center; }
  .mascot { font-size: 3.2rem; }
}

.js-install-app[hidden] { display: none !important; }
body.can-install .js-install-app { display: inline-flex; }
body.can-install .js-install-app[hidden] { display: inline-flex !important; }
.login-card .js-install-app { margin-top: 10px; }
.install-modal[hidden] { display: none !important; }
.install-modal {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 20px;
}
.install-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(43, 33, 24, .45);
}
.install-modal-card {
  position: relative; z-index: 1;
  width: min(400px, 100%);
  background: #fffdf8;
  border-radius: 24px;
  padding: 22px 20px 20px;
  box-shadow: 0 18px 40px rgba(90, 50, 20, .22);
}
.install-modal-close {
  position: absolute; top: 10px; right: 12px;
  width: 36px; height: 36px; border: 0; border-radius: 12px;
  background: #fff4d6; font-size: 1.4rem; line-height: 1; cursor: pointer; color: var(--ink);
}
.install-modal-ico { font-size: 2.4rem; text-align: center; }
.install-modal-card h2 { margin: 6px 0 12px; text-align: center; font-size: 1.2rem; }
.install-steps { margin: 0 0 12px; padding-left: 22px; font-weight: 600; line-height: 1.55; }
.install-steps[hidden] { display: none !important; }
.install-steps li { margin: 8px 0; }
.ios-share {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px; vertical-align: middle;
  background: #e8f0ff; color: var(--blue); margin: 0 2px;
}
