*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--wine-2); outline-offset: 3px; border-radius: 8px; }

.app { min-height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; padding: calc(var(--safe-t) + 8px) var(--sp) calc(var(--tab-h) + var(--safe-b) + 24px); }

/* ---------- typography ---------- */
.display {
  font-family: var(--serif);
  font-size: var(--fs-display);
  line-height: 1.02;
  letter-spacing: -0.03em;
  font-weight: 500;
  margin: 0;
}
.display em { font-style: italic; color: var(--wine-2); }
.h1 { font-family: var(--serif); font-size: var(--fs-h1); line-height: 1.1; letter-spacing: -0.02em; font-weight: 600; margin: 0; }
.h2 { font-family: var(--serif); font-size: var(--fs-h2); line-height: 1.2; letter-spacing: -0.015em; font-weight: 600; margin: 0; }
.eyebrow {
  font-size: var(--fs-xs); font-weight: 800; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--wine-2); margin: 0 0 10px;
}
.lead { color: var(--ink-2); font-size: var(--fs-body); margin: 8px 0 0; }
.muted { color: var(--muted); }
.th { font-family: var(--thai); }
.small { font-size: var(--fs-sm); }

/* ---------- shell ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 0 18px; }
.wordmark { font-family: var(--serif); font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.wordmark span { color: var(--wine-2); }
.topbar__spacer { flex: 1; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; overflow: hidden;
  border: 1px solid var(--line); background: var(--card); box-shadow: var(--sh-s);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line-2);
  border-radius: var(--r-lg); box-shadow: var(--sh-s); padding: 18px;
}
.card--flat { box-shadow: none; }
.section { margin-top: 26px; }
.section__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: var(--r-xl);
  background: linear-gradient(158deg, #8E0A26 0%, #7E041D 52%, #5F0B1D 100%);
  color: #fff; box-shadow: var(--sh-wine); padding: 22px 20px 20px; min-height: 208px;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.hero__art {
  position: absolute; right: -26px; bottom: -8px; height: 104%; width: auto; max-width: 62%;
  pointer-events: none;
  -webkit-mask-image: linear-gradient(100deg, rgba(0,0,0,0) 2%, #000 34%);
  mask-image: linear-gradient(100deg, rgba(0,0,0,0) 2%, #000 34%);
}
.hero__eyebrow { font-size: var(--fs-xs); font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: rgba(255,255,255,.82); }
.hero__title {
  font-family: var(--serif); font-size: 30px; line-height: 1.05; letter-spacing: -0.025em;
  margin: 8px 0 0; font-weight: 500; max-width: 56%;
}
.hero__title:lang(th), .hero__title .th { font-family: "Noto Serif Thai", var(--serif); font-size: 23px; line-height: 1.25; }
.hero__title.is-thai { font-family: "Noto Serif Thai", var(--serif); font-size: 23px; line-height: 1.28; font-weight: 700; max-width: 54%; }
.hero__title em { font-style: italic; color: #F6D9DE; }
.hero__sub { font-family: var(--thai); font-size: 12.5px; color: rgba(255,255,255,.78); margin: 8px 0 16px; max-width: 58%; }
.hero__cta { position: relative; z-index: 2; align-self: flex-start; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px; border-radius: var(--r-pill);
  font-weight: 700; font-size: 14px; letter-spacing: 0.01em;
  transition: transform .16s var(--ease), box-shadow .16s var(--ease), background .16s var(--ease);
}
.btn:active { transform: scale(.97); }
.btn--primary { background: linear-gradient(140deg, var(--wine-2), var(--wine)); color: #fff; box-shadow: var(--sh-wine); }
.btn--light { background: #fff; color: var(--wine); box-shadow: 0 10px 24px -14px rgba(40,10,16,.5); }
.btn--ghost { border: 1px solid var(--line); color: var(--ink-2); background: var(--card); }
.btn--block { width: 100%; }

/* ---------- goal ring ---------- */
.ring { --p: 0; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--wine-2) calc(var(--p) * 1%), var(--wine-soft) 0);
  position: relative; flex: none; }
.ring::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--card); }
.ring b { position: relative; font-family: var(--serif); font-size: 17px; color: var(--wine); }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-md); padding: 14px; box-shadow: var(--sh-s); }
.stat__k { font-size: var(--fs-xs); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 800; }
.stat__v { font-family: var(--serif); font-size: 24px; line-height: 1.1; margin-top: 4px; }
.stat__v small { font-family: var(--sans); font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- lesson row ---------- */
.lesson { display: flex; gap: 14px; align-items: center; padding: 14px; background: var(--card);
  border: 1px solid var(--line-2); border-radius: var(--r-md); box-shadow: var(--sh-s); width: 100%; text-align: left; }
.lesson + .lesson { margin-top: 10px; }
.lesson__badge {
  width: 46px; height: 46px; border-radius: 13px; flex: none; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--wine-3), var(--wine)); color: #fff;
  font-family: var(--serif); font-size: 15px; font-weight: 700;
}
.lesson__body { flex: 1; min-width: 0; display: block; }
.lesson__meta { display: block; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--wine-2); font-weight: 800; }
.lesson__title { display: block; font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.lesson__sub { display: block; font-family: var(--thai); font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lesson__go { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--wine-tint); color: var(--wine); flex: none; }

/* ---------- tabs ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(4, 1fr); align-items: center;
  background: rgba(251, 246, 240, 0.94);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-top: 1px solid var(--line-2);
}
.tab { display: grid; place-items: center; gap: 3px; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: .04em; }
.tab svg { width: 23px; height: 23px; stroke-width: 1.7; }
.tab.is-active { color: var(--wine); }
.tab.is-active svg { stroke-width: 2.2; }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--line-2); margin: 16px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  background: var(--card); border: 1px solid var(--line); font-size: 12px; font-weight: 600; color: var(--ink-2); }
.chip--on { background: var(--wine); color: #fff; border-color: transparent; }
.stack > * + * { margin-top: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- sheet ---------- */
.sheet-host { position: fixed; inset: 0; z-index: 80; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(23, 16, 15, 0.38); opacity: 0; transition: opacity .22s var(--ease); }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--paper); border-radius: 26px 26px 0 0;
  padding: 10px 20px calc(22px + var(--safe-b));
  transform: translateY(102%); transition: transform .28s var(--ease);
  max-height: 88dvh; overflow-y: auto; box-shadow: 0 -20px 60px -30px rgba(40,10,16,.5);
}
.sheet-host.is-open .sheet-backdrop { opacity: 1; }
.sheet-host.is-open .sheet { transform: translateY(0); }
.sheet__grip { width: 42px; height: 4px; border-radius: 99px; background: var(--line); margin: 2px auto 16px; }

.level-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-md);
  padding: 13px 14px; box-shadow: var(--sh-s);
}
.level-card:active { transform: scale(.99); }
.level-card__id {
  width: 44px; height: 44px; border-radius: 13px; flex: none; display: grid; place-items: center;
  background: var(--wine-tint); color: var(--wine); font-family: var(--serif); font-weight: 700; font-size: 15px;
}
.level-card__body { flex: 1; min-width: 0; }
.level-card__body b { display: block; font-family: var(--serif); font-size: 15px; }
.level-card__body em { display: block; font-style: normal; font-family: var(--thai); font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.level-card__words { font-size: 10px; color: var(--muted-2); font-weight: 700; letter-spacing: .04em; }

/* ---------- locked lessons ---------- */
.lesson.is-locked { opacity: .55; }
.lesson.is-locked .lesson__badge { background: linear-gradient(150deg, #C9B7BA, #A99196); }
.lesson.is-locked .lesson__go { background: transparent; }

/* ---------- lesson ---------- */
.stepbar { height: 3px; background: var(--wine-soft); border-radius: 99px; overflow: hidden; margin: 6px 0 22px; }
.stepbar span { display: block; height: 100%; background: var(--wine-2); border-radius: 99px; transition: width .3s var(--ease); }
.say { font-family: var(--serif); font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; }
.say-th { font-size: 13px; color: var(--muted); margin-top: 6px; margin-bottom: 14px; }
.dialogue-row { display: grid; grid-template-columns: 52px 1fr 20px; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.dialogue-row:last-child { border-bottom: 0; }
.dialogue-row b { font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--wine-2); }
.dialogue-row span { font-family: var(--serif); font-size: 15px; }
.dialogue-row i { color: var(--wine-2); display: grid; place-items: center; }
.dialogue-row i svg { width: 15px; height: 15px; }
.option { width: 100%; text-align: left; padding: 13px 14px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--card); font-family: var(--thai); font-size: 14px; }
.option.is-right { border-color: #2f9a63; background: #eafbf1; }
.option.is-wrong { border-color: #b3261e; background: #fdecea; }
.score { font-family: var(--serif); font-size: 44px; line-height: 1; display: flex; align-items: baseline; gap: 4px; }
.score small { font-family: var(--sans); font-size: 13px; color: var(--muted); }

/* ---------- record ---------- */
.record-area { display: grid; justify-items: center; gap: 10px; margin: 22px 0 8px; }
.meter { width: 180px; height: 4px; border-radius: 99px; background: var(--wine-soft); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0%; background: var(--wine-2); transition: width .08s linear; }
.mic {
  width: 78px; height: 78px; border-radius: 50%; display: grid; place-items: center; font-size: 28px;
  background: linear-gradient(140deg, var(--wine-3), var(--wine)); color: #fff;
  box-shadow: 0 16px 34px -18px rgba(126,4,29,.75);
  transition: transform .16s var(--ease);
}
.mic:active { transform: scale(.96); }
.mic.is-rec { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(176,31,60,.45); } 50% { box-shadow: 0 0 0 14px rgba(176,31,60,0); } }
.mic-hint { font-family: var(--thai); font-size: 11.5px; color: var(--muted); }
.bars { display: grid; gap: 7px; margin-top: 12px; }
.bars div { display: grid; grid-template-columns: 88px 1fr; align-items: center; gap: 10px; }
.bars span { font-family: var(--thai); font-size: 10.5px; color: var(--muted); }
.bars i { display: block; height: 5px; border-radius: 99px; background: linear-gradient(90deg, var(--wine-2), var(--wine)); }

/* ---------- icon sizing ---------- */
.btn svg, .tab svg, .lesson__go svg, .dialogue-row i svg { width: 16px; height: 16px; flex: none; }
.btn { white-space: nowrap; }
.btn--ghost svg, .btn--light svg { stroke-width: 2; }
.mic svg { width: 30px; height: 30px; }

/* ---------- new artwork ---------- */
.reward-art { display: grid; place-items: center; margin: 6px 0 10px; }
.reward-art img { width: 58%; max-width: 220px; filter: drop-shadow(0 18px 30px rgba(126,4,29,.22)); }
.practice-art { display: grid; place-items: center; margin: 8px 0 18px; }
.practice-art img { width: 52%; max-width: 200px; filter: drop-shadow(0 16px 26px rgba(126,4,29,.16)); }

/* ---------- practice modes ---------- */
.practice-art img { width: 46%; }
.mode-card { display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; }
.mode-card__art { width: 62px; height: 62px; border-radius: 16px; flex: none; display: grid; place-items: center;
  background: var(--wine-tint); border: 1px solid var(--line-2); overflow: hidden; }
.mode-card__art img { width: 78%; height: 78%; object-fit: contain; }

/* ---------- screen artwork ---------- */
.screen-art { display: grid; place-items: center; margin: 10px 0 4px; }
.screen-art img {
  width: 40%; max-width: 170px;
  filter: drop-shadow(0 16px 26px rgba(126,4,29,.18));
  -webkit-mask-image: radial-gradient(115% 105% at 50% 36%, #000 54%, rgba(0,0,0,0) 86%);
  mask-image: radial-gradient(115% 105% at 50% 36%, #000 54%, rgba(0,0,0,0) 86%);
}
.screen-art--sm img { width: 34%; max-width: 140px; }

/* ---------- listening ---------- */
.speed-row { display: flex; gap: 8px; margin-top: 12px; justify-content: center; }
