/* Say it — cool chalk paper, cobalt voice, apricot streaks, mint strength.
   One loud thing per screen: the next lesson on Home, the voice ring in a lesson. */
:root {
  --paper: #edf1f7;
  --sheet: #ffffff;
  --ink: #18223a;
  --muted: #5b6780;
  --line: #d3dae6;
  --cobalt: #2c45e8;
  --cobalt-soft: #dfe4ff;
  --apricot: #f28a1c;
  --apricot-soft: #ffe8cf;
  --mint: #138a64;
  --mint-soft: #d5f2e7;
  --danger: #c23b3b;
  --display: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, sans-serif;
  --ja: "Noto Sans JP", var(--body);
  --ar: "Noto Naskh Arabic", var(--body);
  --radius-lg: 22px;
  --radius-sm: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #111a2b; --sheet: #1a2439; --ink: #e9eef9; --muted: #9aa6bf; --line: #2b3752;
    --cobalt: #8497ff; --cobalt-soft: #26315a; --apricot: #ffae5c; --apricot-soft: #3d2c1b;
    --mint: #4fd1a2; --mint-soft: #183a31; --danger: #ff7b7b; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #111a2b; --sheet: #1a2439; --ink: #e9eef9; --muted: #9aa6bf; --line: #2b3752;
  --cobalt: #8497ff; --cobalt-soft: #26315a; --apricot: #ffae5c; --apricot-soft: #3d2c1b;
  --mint: #4fd1a2; --mint-soft: #183a31; --danger: #ff7b7b; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font: 17px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--cobalt); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.wrap { max-width: 560px; margin: 0 auto; padding: 0 16px; }

/* ---------- top bar ---------- */
.top {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 0 6px;
}
.langs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.langs::-webkit-scrollbar { display: none; }
.lang {
  border: 1.5px solid var(--line); background: transparent; border-radius: 999px;
  padding: 6px 13px; white-space: nowrap; font-size: 15px; color: var(--muted);
}
.lang[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.lang .ja { font-family: var(--ja); }
.lang .ar { font-family: var(--ar); }
.me {
  width: 38px; height: 38px; border-radius: 50%; border: 0; flex: none;
  background: var(--cobalt-soft); color: var(--cobalt); font-weight: 700;
}

/* ---------- home hero ---------- */
.hello { color: var(--muted); margin: 18px 0 2px; font-size: 16px; }
.next-title {
  font: 800 clamp(34px, 9.5vw, 46px)/1.02 var(--display);
  letter-spacing: -0.02em; margin: 0 0 12px; text-wrap: balance;
}
.next-meta { color: var(--muted); margin: 0 0 14px; }
.preview { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 20px; }
.chip {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; font-size: 15px;
}
.chip .r { color: var(--muted); }
.go {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; border: 0; border-radius: 18px; padding: 18px;
  background: var(--cobalt); color: #fff; font: 700 20px var(--display);
  box-shadow: 0 10px 24px -12px var(--cobalt);
}
.go:active { transform: translateY(1px); }
.go svg { width: 22px; height: 22px; }
.talk {
  width: 100%; margin-top: 10px; border: 1.5px solid var(--line); background: transparent;
  border-radius: 18px; padding: 14px; font-weight: 700;
}
.talk small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }

/* ---------- stats ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius-lg);
  overflow: hidden; margin: 26px 0 8px;
}
.stat { background: var(--sheet); padding: 12px 12px 10px; }
.stat b { display: block; font: 800 26px/1.1 var(--display); }
.stat span { font-size: 14px; color: var(--muted); }
.stat.streak b { color: var(--apricot); }
.week { display: flex; gap: 4px; align-items: flex-end; height: 26px; margin-top: 6px; }
.week i {
  flex: 1; background: var(--line); border-radius: 3px; min-height: 4px; display: block;
}
.week i.on { background: var(--apricot); }
.share { font-size: 14px; color: var(--muted); margin: 8px 2px 0; }

/* ---------- path ---------- */
h2.section { font: 700 22px var(--display); margin: 34px 0 12px; }
.path { list-style: none; margin: 0; padding: 0; position: relative; }
.path::before {
  content: ""; position: absolute; left: 21px; top: 10px; bottom: 10px; width: 2px;
  background: var(--line);
}
.unit { display: flex; gap: 14px; align-items: center; padding: 9px 0; position: relative; }
.node {
  width: 44px; height: 44px; flex: none; border-radius: 50%; display: grid; place-items: center;
  background: var(--paper); position: relative;
}
.node svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.node .n { font: 700 15px var(--display); color: var(--muted); }
.unit.done .node { background: var(--mint); }
.unit.done .node .n { color: #fff; }
.unit.current .node .n { color: var(--cobalt); }
.unit h3 { margin: 0; font-size: 17px; }
.unit p { margin: 0; color: var(--muted); font-size: 15px; }
.unit.locked h3, .unit.locked p { opacity: .55; }
.unit.current h3 { color: var(--cobalt); }

/* ---------- tabs ---------- */
main { padding-bottom: 96px; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs .wrap { display: flex; }
.tab {
  flex: 1; border: 0; background: none; padding: 10px 0 12px; color: var(--muted);
  font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--cobalt); font-weight: 700; }

/* ---------- phrase book / history ---------- */
.page-title { font: 800 34px/1.1 var(--display); margin: 18px 0 6px; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); margin: 0 0 18px; }
.book-unit { margin: 22px 0 8px; font-weight: 700; color: var(--muted); font-size: 15px; }
.phrase {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
}
.phrase .txt { flex: 1; min-width: 0; }
.phrase .tl { font-size: 19px; font-weight: 700; display: block; }
.phrase .en { color: var(--muted); font-size: 15px; }
.dots { display: flex; gap: 3px; flex: none; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--line); display: block; }
.dots i.on { background: var(--mint); }
.play { width: 20px; height: 20px; color: var(--cobalt); flex: none; }
.empty {
  border: 1.5px dashed var(--line); border-radius: var(--radius-lg); padding: 22px; color: var(--muted);
  text-align: center;
}
.hist {
  display: block; width: 100%; text-align: left; background: var(--sheet); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
}
.hist b { display: block; }
.hist span { color: var(--muted); font-size: 15px; }
.xp { color: var(--apricot); font-weight: 700; }

/* target-language text wherever it appears */
.tl-ja, .ja { font-family: var(--ja); }
.tl-ar, .ar { font-family: var(--ar); direction: rtl; unicode-bidi: isolate; }
.r { font-weight: 400; }

/* ---------- lesson ---------- */
.lesson {
  position: fixed; inset: 0; z-index: 10; background: var(--paper);
  display: flex; flex-direction: column;
}
.lesson > .lesson-top, .lesson > .status, .lesson > .captions, .lesson > .typebar, .lesson > .controls {
  width: 100%; max-width: 600px; margin-left: auto; margin-right: auto;
}
.lesson-top { display: flex; align-items: center; gap: 10px; padding: 12px 16px 0; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--line);
  background: var(--sheet); display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.lesson-top .t { flex: 1; min-width: 0; }
.lesson-top .t b { display: block; font: 700 17px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson-top .t span { color: var(--muted); font-size: 14px; }
.stage {
  flex: none; display: grid; place-items: center; position: relative; height: min(40vh, 330px);
}
#ring { width: min(78vw, 330px); height: min(78vw, 330px); max-height: 100%; }
.ring-label { position: absolute; text-align: center; pointer-events: none; }
.ring-label b { font: 800 26px var(--display); display: block; }
.ring-label span { color: var(--muted); font-size: 15px; }
.status { text-align: center; min-height: 26px; font-weight: 700; margin: 0 16px; }
.status.listening { color: var(--mint); }
.status.thinking { color: var(--apricot); }
.status.speaking { color: var(--cobalt); }
.captions {
  flex: 1; overflow-y: auto; padding: 8px 16px 12px; display: flex; flex-direction: column; gap: 8px;
  mask-image: linear-gradient(to bottom, transparent 0, #000 22px);
}
.bubble { max-width: 88%; padding: 9px 13px; border-radius: 16px; line-height: 1.45; }
.bubble.tutor { background: var(--sheet); border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.you { background: var(--mint-soft); align-self: flex-end; border-bottom-right-radius: 5px; }
.bubble.app { align-self: center; color: var(--muted); font-size: 14px; background: none; }
.seg-t { color: var(--cobalt); font-weight: 700; }
.seg-t .r { display: block; font-weight: 400; font-size: 14px; color: var(--muted); }
.seg-t.inline { display: inline-block; vertical-align: top; }
.controls {
  display: flex; gap: 8px; padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--paper);
}
.ctl {
  flex: 1; border: 1.5px solid var(--line); background: var(--sheet); border-radius: 14px;
  padding: 10px 4px; font-size: 14px; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.ctl svg { width: 22px; height: 22px; }
.ctl.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.typebar { display: flex; gap: 8px; padding: 8px 16px 0; }
.typebar input {
  flex: 1; border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit;
  background: var(--sheet); color: var(--ink);
}
.typebar button { border: 0; background: var(--cobalt); color: #fff; border-radius: 12px; padding: 0 16px; font-weight: 700; }

/* the phrase card that rises when the tutor teaches something new */
.card {
  position: absolute; left: 16px; right: 16px; bottom: 96px; z-index: 3;
  max-width: 528px; margin: 0 auto;
  background: var(--ink); color: var(--paper); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: 0 18px 40px -18px rgba(10, 20, 60, .55);
  animation: rise .35s cubic-bezier(.2, .8, .2, 1);
}
.card .kicker { font-size: 14px; opacity: .7; }
.card .big { font: 800 30px/1.15 var(--display); margin: 2px 0; }
.card .big.ja { font-family: var(--ja); font-weight: 700; }
.card .big.ar { font-family: var(--ar); font-weight: 700; text-align: right; }
.card .rom { font-size: 18px; opacity: .85; }
.card .en { margin-top: 6px; opacity: .8; }
.card .note { margin-top: 8px; font-size: 14px; opacity: .75; }
.card .x { position: absolute; top: 8px; right: 8px; border: 0; background: none; color: inherit; opacity: .6; padding: 8px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

/* ---------- results ---------- */
.result { padding-top: 26px; }
.result .xpbig { font: 800 64px/1 var(--display); color: var(--apricot); }
.result h1 { font: 800 30px/1.1 var(--display); margin: 10px 0 6px; text-wrap: balance; }
.unlock {
  background: var(--mint); color: #fff; border-radius: var(--radius-lg); padding: 16px 18px; margin: 18px 0;
}
.unlock b { font: 800 22px var(--display); display: block; }
.change { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.change .txt { flex: 1; }
.change .tl { font-weight: 700; }
.change .en { color: var(--muted); font-size: 15px; }
.tag { font-size: 13px; border-radius: 999px; padding: 2px 9px; font-weight: 700; }
.tag.good { background: var(--mint-soft); color: var(--mint); }
.tag.shaky { background: var(--apricot-soft); color: var(--apricot); }
.tag.missed { background: var(--line); color: var(--muted); }
.fix { background: var(--sheet); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.fix .said { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.fix .better { font-weight: 700; color: var(--cobalt); display: flex; gap: 8px; align-items: center; }
.fix .better button { border: 0; background: none; padding: 0; color: var(--cobalt); }
.fix .why { font-size: 15px; color: var(--muted); }
.wins { padding-left: 20px; }

/* ---------- sheet (settings, session detail) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 16, 32, .45); z-index: 20; display: flex; align-items: flex-end; }
.sheet {
  background: var(--paper); width: 100%; max-height: 88dvh; overflow-y: auto;
  border-radius: 24px 24px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
}
.sheet .wrap { padding: 0; }
.sheet h2 { font: 800 26px var(--display); margin: 0 0 14px; }
.field { margin: 18px 0; }
.field > label, .field > .lbl { font-weight: 700; display: block; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.seg { display: flex; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--sheet); padding: 10px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); font-weight: 700; }
input[type="range"] { width: 100%; accent-color: var(--cobalt); }
.range-ends { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.plain-btn { border: 1.5px solid var(--line); background: var(--sheet); border-radius: 12px; padding: 10px 14px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; }
.login h1 { font: 800 56px/1 var(--display); margin: 0 0 6px; letter-spacing: -0.03em; }
.login p { color: var(--muted); margin: 0 0 26px; }
.login label { display: block; font-weight: 700; margin: 14px 0 6px; }
.login input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font: inherit;
  background: var(--sheet); color: var(--ink);
}
.login .go { margin-top: 22px; }
.login .err { color: var(--danger); min-height: 24px; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%); z-index: 30;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px; max-width: 90vw;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- globe ---------- */
.globe-wrap { position: relative; margin: 4px auto 0; width: min(100%, 420px); aspect-ratio: 1; touch-action: none; }
#globe { width: 100%; height: 100%; display: block; cursor: grab; }
#globe:active { cursor: grabbing; }
.globe-hint { text-align: center; color: var(--muted); font-size: 14px; margin: 0; }
.talk.place { border-style: dashed; }

/* ---------- practice sheet ---------- */
.practise-target { font: 800 30px/1.2 var(--display); margin: 4px 0; }
.practise-target.ja { font-family: var(--ja); font-weight: 700; }
.practise-target.ar { font-family: var(--ar); font-weight: 700; }
.practise-r { color: var(--muted); font-size: 18px; }
.rec {
  width: 96px; height: 96px; border-radius: 50%; border: 0; margin: 22px auto 8px; display: grid; place-items: center;
  background: var(--mint); color: #fff; box-shadow: 0 0 0 0 var(--mint);
}
.rec svg { width: 38px; height: 38px; }
.rec.on { background: var(--danger); animation: breathe 1.2s ease-in-out infinite; }
@keyframes breathe { 50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--danger) 18%, transparent); } }
.rec-label { text-align: center; color: var(--muted); min-height: 24px; }
.score { display: flex; align-items: center; gap: 14px; margin: 18px 0 10px; }
.score b { font: 800 44px/1 var(--display); }
.score.good b { color: var(--mint); } .score.mid b { color: var(--apricot); } .score.low b { color: var(--danger); }
.wordline { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.word { padding: 3px 10px; border-radius: 8px; font-weight: 700; }
.word.ok { background: var(--mint-soft); color: var(--mint); }
.word.no { background: var(--apricot-soft); color: var(--apricot); }
.compare { display: flex; gap: 8px; margin: 12px 0; }
.compare button { flex: 1; }
.phrase-row { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.phrase-row .phrase { margin: 0; }
.mic-btn {
  flex: none; width: 52px; border: 1px solid var(--line); background: var(--sheet); border-radius: 14px;
  color: var(--mint); display: grid; place-items: center;
}
.mic-btn svg { width: 22px; height: 22px; }
.card .practise { margin-top: 10px; border: 0; border-radius: 10px; background: var(--paper); color: var(--ink); padding: 8px 12px; font-weight: 700; }

/* ---------- lesson side panel (wide screens only) ---------- */
.plan-panel { display: none; }

/* ---------- wide screens: tablet landscape and desktop ---------- */
@media (min-width: 900px) {
  body { font-size: 18px; }
  .wrap { max-width: 1160px; padding: 0 32px; }
  .top { padding-top: 20px; }
  .learn { display: grid; grid-template-columns: minmax(360px, 1fr) minmax(0, 1fr); gap: 56px; align-items: start; }
  .learn-globe { position: sticky; top: 24px; }
  .globe-wrap { width: min(100%, 560px); }
  .learn-main { padding-top: 30px; max-width: 560px; }
  .next-title { font-size: clamp(44px, 4.4vw, 60px); }
  .tabs { left: 50%; right: auto; bottom: 18px; transform: translateX(-50%); border: 1px solid var(--line);
          border-radius: 20px; padding-bottom: 0; box-shadow: 0 10px 30px -18px rgba(10, 20, 60, .5); }
  .tabs .wrap { padding: 0 8px; gap: 4px; }
  .tab { flex-direction: row; gap: 8px; padding: 12px 18px; font-size: 16px; }
  #viewPhrases, #viewHistory { max-width: 720px; margin: 0 auto; }
  .sheet-bg { align-items: center; justify-content: center; }
  .sheet { width: min(560px, 92vw); border-radius: 24px; }

  .lesson { display: grid; grid-template-columns: 1fr minmax(0, 600px) 1fr;
            grid-template-rows: auto auto auto 1fr auto auto; }
  .lesson > * { grid-column: 2; }
  .lesson > .stage { height: min(42vh, 380px); }
  #ring { width: min(40vh, 380px); height: min(40vh, 380px); }
  .plan-panel { display: block; grid-column: 3; grid-row: 2 / 6; align-self: start; margin: 90px 24px 0 8px;
                max-width: 300px; }
  .plan-panel h3 { font: 700 17px var(--display); margin: 0 0 10px; }
  .plan-panel .pp { background: var(--sheet); border: 1px solid var(--line); border-radius: 12px;
                    padding: 9px 12px; margin-bottom: 8px; }
  .plan-panel .pp .en { color: var(--muted); font-size: 15px; display: block; }
  .plan-panel .pp .tl { display: block; font-weight: 700; }
  .card { left: 50%; right: auto; width: min(528px, 90vw); transform: translateX(-50%); animation: none; }
  #result .wrap { max-width: 640px; }
}
@media (min-width: 1300px) {
  .plan-panel { grid-column: 3; }
}
/* short landscape phones: shrink the ring so the captions keep some room */
@media (max-height: 500px) {
  .stage { height: 34vh; }
  #ring { width: 34vh; height: 34vh; }
}
