:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2633;
  --muted: #6b7486;
  --line: #e2e6ef;
  --primary: #5b6cff;
  --primary-2: #8b5bff;
  --ok: #1fae6b;
  --ok-bg: #e3f7ec;
  --bad: #e5484d;
  --bad-bg: #fde8e8;
  --warn: #f5a524;
  --shadow: 0 2px 10px rgba(30, 40, 80, .08);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d;
    --card: #1c212c;
    --text: #e8ebf2;
    --muted: #98a1b3;
    --line: #2c3342;
    --ok-bg: #143526;
    --bad-bg: #3a1a1c;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft JhengHei", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { background: none; border: 0; font-weight: 700; font-size: 18px; padding: 4px; }
.stats { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.stat { background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 14px; font-weight: 600; white-space: nowrap; }
.icon-btn { background: var(--bg); border: 0; border-radius: 999px; width: 34px; height: 34px; }

main { max-width: 860px; margin: 0 auto; padding: 16px 16px 60px; }

/* generic */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h2 { font-size: 20px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.btn {
  border: 0; border-radius: 12px; padding: 10px 18px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--line);
}
.btn:hover { filter: brightness(.97); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; border: 0; }
.btn.ok { background: var(--ok); color: #fff; border: 0; }
.btn.big { padding: 14px 24px; font-size: 18px; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.audio { font-size: 15px; }

/* language tabs */
.lang-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.lang-tab {
  border: 2px solid var(--line); background: var(--card); border-radius: var(--radius);
  padding: 14px; font-size: 18px; font-weight: 700; display: flex; gap: 10px; align-items: center; justify-content: center;
}
.lang-tab.active { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }

/* daily goal */
.goal { display: flex; align-items: center; gap: 14px; }
.bar { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; flex: 1; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--warn), #ff7a45); border-radius: 999px; transition: width .4s; }
.bar.blue > i { background: linear-gradient(90deg, var(--primary), var(--primary-2)); }

/* unit grid */
.units { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.unit {
  text-align: left; border: 0; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 6px; min-height: 140px; position: relative;
  transition: transform .12s;
}
.unit:hover:not(.locked) { transform: translateY(-2px); }
.unit .ico { font-size: 32px; }
.unit .ttl { font-weight: 700; }
.unit .lv { font-size: 12px; color: var(--muted); }
.unit.locked { opacity: .5; cursor: not-allowed; }
.unit .lock { position: absolute; top: 12px; right: 14px; }
.stars { color: var(--warn); letter-spacing: 1px; font-size: 14px; }

/* activity list */
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.act {
  text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 14px; display: flex; gap: 12px; align-items: center;
}
.act:hover { border-color: var(--primary); }
.act .ico { font-size: 28px; }
.act .name { font-weight: 700; }
.act .desc { font-size: 13px; color: var(--muted); }

/* session */
.progress-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.combo { font-weight: 700; color: #ff7a45; min-width: 64px; text-align: right; }
.quit { background: none; border: 0; font-size: 22px; color: var(--muted); }
.q-type { font-size: 13px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.q-prompt { font-size: 18px; margin-bottom: 12px; }
.target { font-size: 28px; font-weight: 700; line-height: 1.35; margin: 4px 0; }
.roma { color: var(--muted); font-size: 15px; }
.zh { font-size: 16px; }
.options { display: grid; gap: 10px; margin-top: 12px; }
.opt {
  text-align: left; border: 2px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 12px 14px; font-size: 17px; display: flex; gap: 10px; align-items: center;
}
.opt .k { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 8px; background: var(--bg); font-size: 13px; color: var(--muted); flex: none; }
.opt:hover:not(:disabled) { border-color: var(--primary); }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt:disabled { cursor: default; }
.feedback { margin-top: 14px; border-radius: 14px; padding: 12px 14px; display: none; }
.feedback.show { display: block; }
.feedback.ok { background: var(--ok-bg); }
.feedback.bad { background: var(--bad-bg); }
.feedback .head { font-weight: 700; margin-bottom: 4px; }
.session-foot { margin-top: 16px; }

/* order */
.answer-zone {
  min-height: 64px; border: 2px dashed var(--line); border-radius: 14px; padding: 10px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start; margin: 10px 0;
}
.pool { display: flex; flex-wrap: wrap; gap: 8px; }
.tok {
  border: 2px solid var(--line); border-bottom-width: 4px; background: var(--card); border-radius: 12px;
  padding: 8px 14px; font-size: 18px; font-weight: 600;
}
.tok.used { visibility: hidden; }

/* dialogue */
.dlg { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 16px; background: var(--bg); border: 2px solid transparent; transition: border-color .2s; }
.bubble.B { align-self: flex-end; background: color-mix(in srgb, var(--primary) 14%, var(--card)); }
.bubble.playing { border-color: var(--primary); }
.bubble .sp { font-size: 12px; color: var(--muted); font-weight: 700; }
.bubble .t { font-size: 18px; font-weight: 600; }

/* speaking */
.mic {
  width: 84px; height: 84px; border-radius: 50%; border: 0; font-size: 36px;
  background: linear-gradient(135deg, #ff6b6b, #ff8e53); color: #fff; box-shadow: var(--shadow);
}
.mic.rec { animation: pulse 1s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 107, 107, .6); } 100% { box-shadow: 0 0 0 22px rgba(255, 107, 107, 0); } }
.score { font-size: 32px; font-weight: 800; }

/* lesson */
.lesson .point { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.ex { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.ex .t { font-weight: 600; font-size: 17px; }
.play-mini { border: 0; background: var(--bg); border-radius: 50%; width: 34px; height: 34px; flex: none; }

/* vocab list */
.vlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.vitem { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--card); text-align: left; }
.vitem .w { font-weight: 700; font-size: 17px; }

/* result */
.result { text-align: center; }
.result .big-stars { font-size: 48px; color: var(--warn); letter-spacing: 6px; }
.result .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 16px 0; }
.result .num { background: var(--bg); border-radius: 14px; padding: 12px; }
.result .num b { display: block; font-size: 24px; }

/* settings */
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.set-row:first-of-type { border-top: 0; }
select, input[type=range] { font: inherit; }
select { padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text); max-width: 100%; }
.warn { background: color-mix(in srgb, var(--warn) 18%, var(--card)); border-radius: 12px; padding: 10px 12px; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #222a; color: #fff; backdrop-filter: blur(6px); padding: 10px 18px; border-radius: 999px;
  transition: .25s; pointer-events: none; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.96); } 60% { transform: scale(1.02); } 100% { transform: scale(1); } }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 50% { transform: translateX(6px); } 75% { transform: translateX(-3px); } }

@media (max-width: 520px) {
  .target { font-size: 23px; }
  .brand { font-size: 16px; }
  .stat { padding: 2px 8px; font-size: 13px; }
}
