:root {
  --bg: #fbf6ec;
  --paper: #ffffff;
  --ink: #2d2a3e;
  --muted: #6f6a80;
  --line: #e6dccb;
  --accent: #e2502f;
  --accent-2: #f5a623;
  --good: #23a55a;
  --bad: #d64545;
  --blue: #2f74d0;
  --dot-on: #e2502f;
  --dot-b: #2f74d0;
  --dot-off: #efe6d6;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(45, 42, 62, .08), 0 8px 24px rgba(45, 42, 62, .06);
  --dot: 26px;
  --gut: 10px;
  font-family: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body {
  background:
    radial-gradient(circle at 10% -10%, #fde7c8 0, transparent 40%),
    radial-gradient(circle at 110% 10%, #e9e3fb 0, transparent 35%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--ink); }
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.loading { text-align: center; margin-top: 30vh; }

.screen {
  max-width: 1100px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.top { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; margin-bottom: 12px; min-height: 52px; }
.top .logo { text-align: center; }
.logo { margin: 0; font-size: clamp(1.6rem, 4vw, 2.4rem); letter-spacing: .5px; font-weight: 900; }
.logo.small { font-size: 1.3rem; }
.profiles .top { grid-template-columns: 1fr; }
.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border: 1px solid var(--line); }
h2, h3 { margin: .2em 0 .5em; }

.btn {
  border: 0; border-radius: 999px; padding: 10px 20px; font-weight: 800;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 #a8341b; transition: transform .06s;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #a8341b; }
.btn.big { font-size: 1.2rem; padding: 12px 28px; }
.btn.huge { font-size: 1.5rem; padding: 16px 40px; margin: 10px 0; }
.btn.small { font-size: .9rem; padding: 6px 14px; min-height: 38px; box-shadow: 0 3px 0 #a8341b; }
.btn.ghost { background: #f1eadc; color: var(--ink); box-shadow: 0 3px 0 #d8ccb5; }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--paper); box-shadow: var(--shadow); font-size: 1.2rem; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; padding: 8px; }
.link.danger { color: var(--bad); }
.foot { text-align: center; margin-top: 30px; }

/* profiles */
.profile-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin: 16px 0 24px; }
.profile-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; width: 200px; text-align: center; }
.pc-art { font-size: 70px; min-height: 120px; display: grid; place-items: center; }
.pc-name { font-weight: 900; font-size: 1.3rem; }
.pc-belt { color: var(--muted); font-size: .9rem; display: flex; align-items: center; justify-content: center; gap: 6px; }
.belt-chip { display: inline-block; width: 26px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.2); }
.belt-chip.big { width: 40px; height: 14px; }

/* forms */
.form { max-width: 460px; margin: 0 auto; display: grid; gap: 16px; }
.form label { display: grid; gap: 6px; font-weight: 700; }
.form input[type=text], .form input:not([type]), .name-form input { padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); font-size: 1.2rem; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
legend { font-weight: 700; margin-bottom: 6px; }
.radio { display: flex !important; grid-template-columns: none; align-items: center; gap: 8px; font-weight: 600 !important; }
.radio.disabled { color: var(--muted); }
.radio small { font-weight: 400; }

/* builder */
.builder-grid { display: grid; grid-template-columns: minmax(220px, 300px) 1fr; gap: 16px; margin-bottom: 16px; }
.preview { display: grid; place-items: center; position: relative; min-height: 280px; background: linear-gradient(#fff, #f6efe1); }
.preview-pet { position: absolute; right: 18px; bottom: 18px; }
.pick-row { margin-bottom: 12px; }
.pick-row h3 { font-size: 1rem; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; font-weight: 700; min-height: 40px; }
.chip.sel { border-color: var(--accent); background: #fff1ec; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 0 0 2px var(--line); }
.swatch.sel { box-shadow: 0 0 0 3px var(--accent); }
.pet-chip { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 6px; width: 74px; display: grid; justify-items: center; gap: 2px; font-size: .75rem; font-weight: 700; }
.pet-chip.sel { border-color: var(--accent); background: #fff1ec; }
.pet-chip.locked { opacity: .5; font-size: .75rem; }
.pet-chip.locked { line-height: 1.6; }
.pet-emoji { line-height: 1; }

/* ceremony */
.ceremony-stage { display: grid; justify-items: center; gap: 16px; padding-top: 6vh; position: relative; text-align: center; }
.sensei-reveal { min-height: 190px; display: grid; place-items: center; }
.sensei-reveal.pop { animation: pop .6s cubic-bezier(.2,1.6,.5,1); }
.speech { font-size: 1.3rem; max-width: 520px; min-height: 3em; display: grid; place-items: center; }
.name-form { display: grid; gap: 12px; max-width: 420px; width: 100%; }
.name-form label { display: grid; gap: 8px; font-weight: 700; }
.smoke { position: absolute; top: 8vh; width: 240px; height: 240px; border-radius: 50%; background: radial-gradient(#fff, rgba(255,255,255,0)); opacity: 0; pointer-events: none; }
.smoke.poof { animation: poof .9s ease-out; }
@keyframes poof { 0% { opacity: .95; transform: scale(.4); } 100% { opacity: 0; transform: scale(2.2); } }
@keyframes pop { 0% { transform: scale(.3) rotate(-10deg); opacity: 0; } 100% { transform: none; opacity: 1; } }

/* dojo */
.dojo-hero { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; margin-bottom: 14px; }
.hero-ninja { position: relative; }
.hero-pet { position: absolute; right: -16px; bottom: 0; }
.hero-info h2 { font-size: 2rem; margin: 0; }
.belt-line { display: flex; align-items: center; gap: 8px; font-weight: 700; margin: 4px 0; }
.points-big { font-size: 2.4rem; font-weight: 900; color: var(--accent); }
.points-big small { font-size: 1rem; color: var(--muted); }
.progress { height: 16px; border-radius: 999px; background: #f1eadc; overflow: hidden; border: 1px solid var(--line); margin: 6px 0; }
.progress .bar { height: 100%; border-radius: 999px; }
.sensei-box { display: flex; gap: 14px; align-items: center; margin-bottom: 8px; font-size: 1.1rem; }
.stats { margin-top: 6px; }

/* practice */
.practice-top { grid-template-columns: 48px 1fr 48px; }
.score { display: flex; justify-content: center; gap: 18px; font-size: 1.2rem; }
.practice-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.practice-grid.single { grid-template-columns: minmax(0, 720px); justify-content: center; }
.skill-tag { display: inline-block; background: #f1eadc; color: var(--muted); border-radius: 999px; padding: 2px 10px; font-size: .8rem; font-weight: 700; }
.q-text { font-size: 1.3rem; line-height: 1.45; margin: 10px 0; }
.q-big { font-size: clamp(2rem, 6vw, 2.8rem); font-weight: 900; margin: 6px 0 12px; letter-spacing: 1px; }
.q-model:empty { display: none; }
.q-model { margin: 8px 0 14px; }
.model-array { display: inline-grid; gap: 6px; padding: 10px; background: #fff8ee; border-radius: 12px; }
.model-array span { width: 18px; height: 18px; border-radius: 50%; background: var(--dot-on); }
.model-groups { display: flex; flex-wrap: wrap; gap: 10px; }
.mgroup { border: 3px solid var(--blue); border-radius: 50%; width: 92px; height: 92px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 4px; padding: 10px; }
.mgroup i { width: 13px; height: 13px; border-radius: 50%; background: var(--dot-on); }
.data-table { border-collapse: collapse; margin-top: 6px; }
.data-table th, .data-table td { border: 2px solid var(--ink); padding: 6px 12px; }
.data-table td:last-child { text-align: center; }
.data-table th { background: #f1eadc; }

.ans-number, .ans-pair { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ans-in { width: 110px; font-size: 1.6rem; font-weight: 800; text-align: center; padding: 8px; border-radius: 12px; border: 3px solid var(--line); background: #fff; }
.ans-in:focus { outline: none; border-color: var(--blue); }
.ans-in.eq { width: 72px; font-size: 1.3rem; }
.unit { font-size: 1.2rem; font-weight: 700; color: var(--muted); }
.wrong .ans-in, .ans.wrong .ans-in { border-color: var(--bad); }
.ans-mc { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mc-opt { display: flex; align-items: center; gap: 10px; text-align: left; padding: 12px; border-radius: 14px; border: 3px solid var(--line); background: #fff; font-size: 1.2rem; font-weight: 700; min-height: 56px; }
.mc-opt.sel { border-color: var(--blue); background: #eef5ff; }
.mc-letter { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); display: grid; place-items: center; font-size: .9rem; flex: none; }
.mc-opt.sel .mc-letter { background: var(--ink); color: #fff; }
.ans.wrong .mc-opt.sel, .wrong .mc-opt.sel { border-color: var(--bad); background: #fdeeee; }
.ans-match { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 28px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.match-item { position: relative; padding: 12px; border-radius: 12px; border: 3px solid var(--line); background: #fff; font-size: 1.15rem; font-weight: 800; min-height: 52px; box-shadow: inset 6px 0 0 var(--pc, transparent); }
.match-item.active { border-color: var(--blue); background: #eef5ff; }
.match-item.paired::after { content: attr(data-badge); position: absolute; top: -10px; right: -10px; width: 24px; height: 24px; border-radius: 50%; background: var(--pc); color: #fff; font-size: .8rem; display: grid; place-items: center; }
.match-hint { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; margin: 0; }
.ans-table table { border-collapse: collapse; }
.ans-table th, .ans-table td { border: 2px solid var(--ink); padding: 0; }
.ans-table th { padding: 8px 14px; font-size: 1.15rem; background: #f8f3e9; }
.tcell { width: 74px; height: 48px; border: 0; background: #fff; font-size: 1.5rem; font-weight: 900; color: var(--accent); }
.eq-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; flex-wrap: wrap; }
.op { font-size: 1.5rem; font-weight: 900; }
.fam-nums { display: flex; gap: 10px; margin-bottom: 6px; }
.fam-nums span { background: var(--ink); color: #fff; border-radius: 10px; padding: 4px 12px; font-weight: 900; font-size: 1.2rem; }
.parts { display: grid; gap: 14px; }
.part { border-left: 5px solid var(--line); padding-left: 12px; }
.part.wrong { border-left-color: var(--bad); }
.part.wrong .part-head::after { content: ' ← look again'; color: var(--bad); font-weight: 800; }
.part-head { font-size: 1.1rem; margin-bottom: 6px; }
.part-label { font-weight: 900; color: var(--accent); }
.ans-explain textarea, .explain textarea { width: 100%; border-radius: 12px; border: 2px solid var(--line); padding: 10px; font-size: 1.05rem; }
.explain { margin: 14px 0 6px; }
.explain summary { cursor: pointer; font-weight: 700; color: var(--muted); padding: 6px 0; }
.feedback { min-height: 1.6em; font-size: 1.2rem; font-weight: 700; margin: 8px 0; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.feedback.info { color: var(--blue); }
.feedback.reveal { color: var(--ink); background: #fff7e0; border-radius: 12px; padding: 10px; }
.actions { display: flex; gap: 10px; }
.flash-good { animation: flash 0.6s; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(35,165,90,.7); } 100% { box-shadow: 0 0 0 22px rgba(35,165,90,0); } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* strategy tools */
.strategies h3 { margin-top: 0; }
.tool-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tool-tab { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 700; display: inline-flex; gap: 6px; align-items: center; min-height: 40px; }
.tool-tab.sel { background: var(--ink); color: #fff; border-color: var(--ink); }
.ti { font-size: 1.1rem; }
.tool { display: grid; gap: 10px; }
.tool-status { color: var(--muted); font-weight: 700; min-height: 1.3em; }
.tool-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tool-hint { color: var(--muted); margin: 0; }
.array-wrap { overflow-x: auto; padding: 4px; }
.array-grid { display: grid; width: max-content; }
.dot { width: var(--dot); height: var(--dot); border-radius: 50%; border: 0; background: var(--dot-off); padding: 0; }
.dot.on { background: var(--dot-on); }
.dot.on.part-b { background: var(--dot-b); }
.dot.locked { box-shadow: inset 0 0 0 3px rgba(0,0,0,.25); }
.gutter { border: 0; background: transparent; padding: 0; position: relative; }
.gutter::after { content: ''; position: absolute; background: transparent; border-radius: 4px; }
.hgut::after { left: 0; right: 0; top: 50%; height: 4px; margin-top: -2px; }
.vgut::after { top: 0; bottom: 0; left: 50%; width: 4px; margin-left: -2px; }
.gutter:hover::after { background: rgba(47,116,208,.35); }
.gutter.sel::after { background: var(--ink); }
.ans.locked .dot, .ans.locked .gutter { pointer-events: none; }
.groups-area { display: flex; flex-wrap: wrap; gap: 10px; min-height: 40px; }
.group { display: grid; justify-items: center; gap: 4px; }
.group-circle { width: 96px; height: 96px; border-radius: 50%; border: 3px solid var(--blue); background: #f5f9ff; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4px; padding: 12px; }
.gdot { width: 13px; height: 13px; border-radius: 50%; background: var(--dot-on); }
.group-foot { display: flex; align-items: center; gap: 6px; font-weight: 800; }
.mini { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: #fff; line-height: 1; }
.nl-controls { display: flex; gap: 14px; flex-wrap: wrap; }
.nl-controls label { display: flex; gap: 6px; align-items: center; font-weight: 700; }
.nl-controls input { width: 70px; padding: 6px; border-radius: 10px; border: 2px solid var(--line); font-size: 1.1rem; text-align: center; }
.nl { width: 100%; height: auto; }
.nl-axis { stroke: var(--ink); stroke-width: 3; }
.nl-tick { stroke: var(--ink); stroke-width: 2; }
.nl-label { font-size: 13px; text-anchor: middle; fill: var(--muted); }
.nl-arc { fill: none; stroke: var(--accent); stroke-width: 3; }
.nl-arc.back { stroke: var(--blue); }
.nl-pt { fill: var(--accent); }
.nl-start-pt { fill: var(--ink); }
.nl-land { font-size: 13px; font-weight: 800; text-anchor: middle; fill: var(--ink); }
.ba-row { font-size: 1.25rem; font-weight: 800; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.ba-row input, .step-row input { width: 66px; font-size: 1.2rem; padding: 6px; border-radius: 10px; border: 2px solid var(--line); text-align: center; font-weight: 800; }
.ba-row input.bad { border-color: var(--bad); }
.steps-title { font-weight: 800; margin-bottom: 6px; }
.step-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; border-radius: 10px; }
.step-row:nth-child(even) { background: #faf6ee; }
.step-row.bad { background: #fdeeee; outline: 2px solid var(--bad); }
.step-row.good input { border-color: var(--good); }
.step-label { font-weight: 700; }

/* toast */
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; display: flex; align-items: center; gap: 10px; background: var(--ink); color: #fff; border-radius: 18px; padding: 10px 16px; max-width: min(92vw, 520px); box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: up .35s ease-out; z-index: 10; font-size: 1.05rem; }
.toast.out { opacity: 0; transition: opacity .5s; }
.toast-art { background: #fff; border-radius: 12px; padding: 2px; flex: none; }
@keyframes up { from { transform: translate(-50%, 40px); opacity: 0; } }

/* training break */
.break-card { max-width: 760px; margin: 0 auto; }
.break-head { display: flex; gap: 14px; align-items: center; }
.break-head h2 { color: var(--accent); }
.lesson { font-size: 1.2rem; line-height: 1.5; }
.lesson-big { font-size: 1.5rem; font-weight: 800; }
.mini-array { display: inline-grid; gap: 5px; padding: 8px; background: #fff8ee; border-radius: 10px; }
.mini-array span { width: 16px; height: 16px; border-radius: 50%; background: var(--dot-on); }
.mini-array span.b { background: var(--dot-b); }
.mini-groups { display: flex; flex-wrap: wrap; gap: 8px; }
.mg { border: 3px solid var(--blue); border-radius: 50%; width: 74px; height: 74px; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 3px; padding: 8px; }
.mg i { width: 10px; height: 10px; border-radius: 50%; background: var(--dot-on); }

/* grown-ups */
.grownups .card { margin-bottom: 14px; max-width: 720px; margin-left: auto; margin-right: auto; }
.gp-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.row { display: flex; gap: 10px; flex-wrap: wrap; }

/* phones */
@media (max-width: 760px) {
  :root { --dot: 22px; --gut: 8px; }
  .builder-grid, .practice-grid, .dojo-hero { grid-template-columns: 1fr; }
  .preview { min-height: 240px; }
  .dojo-hero { justify-items: center; text-align: center; }
  .belt-line { justify-content: center; }
  .ans-mc { grid-template-columns: 1fr; }
  .q-text { font-size: 1.15rem; }
  .profile-card { width: 160px; }
}
@media (max-width: 380px) {
  :root { --dot: 19px; --gut: 7px; }
  .ans-match { gap: 10px 14px; }
  .match-item { font-size: 1rem; padding: 10px 8px; }
  .tcell { width: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
