/* Lexi design system: one shell (top bar + 5 tabs) for every signed-in page. */
:root {
  --p-bg: #fbf7f2;
  --p-surface: #ffffff;
  --p-surface-2: #f3eee7;
  --p-ink: #1d1a2b;
  --p-muted: #6f6a7d;
  --p-line: #e7e0d6;
  --p-flame: #ff7a1a;
  --p-flame-2: #ffb347;
  --p-xp: #7c4dff;
  --p-xp-2: #b39dff;
  --p-ok: #22a95a;
  --p-ok-2: #d8f5e3;
  --p-bad: #e5484d;
  --p-bad-2: #fde3e4;
  --p-gold: #f5b700;
  --p-ice: #3fa7ff;
  --p-radius: 18px;
  --p-shadow: 0 1px 0 rgba(29, 26, 43, .06), 0 8px 24px -12px rgba(29, 26, 43, .18);
  --p-font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --p-bg: #14121c;
    --p-surface: #1f1c2b;
    --p-surface-2: #2a2639;
    --p-ink: #f4f1fb;
    --p-muted: #a39db5;
    --p-line: #353046;
    --p-ok-2: #173a26;
    --p-bad-2: #43191c;
    --p-shadow: 0 1px 0 rgba(0, 0, 0, .3), 0 10px 30px -14px rgba(0, 0, 0, .7);
  }
}

[hidden] { display: none !important; }
.play-body {
  margin: 0; background: var(--p-bg); color: var(--p-ink); font-family: var(--p-font);
  -webkit-font-smoothing: antialiased; min-height: 100vh; padding-bottom: calc(92px + env(safe-area-inset-bottom));
}
.play-body a { color: inherit; }
.play-wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.p-top {
  position: sticky; top: 0; z-index: 50; background: color-mix(in srgb, var(--p-bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--p-line);
}
.p-top-inner { max-width: 640px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 10px; }
.p-brand { font-weight: 900; letter-spacing: -.02em; font-size: 1.15rem; text-decoration: none; margin-right: auto; }
.p-brand span { color: var(--p-xp); }
.p-chip {
  display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: .95rem; padding: 6px 10px;
  border-radius: 999px; background: var(--p-surface); box-shadow: var(--p-shadow); text-decoration: none; white-space: nowrap;
}
.p-chip.flame { color: var(--p-flame); }
.p-chip.flame.cold { color: var(--p-muted); filter: grayscale(1); }
.p-chip.flame.risk { animation: p-pulse 1.4s ease-in-out infinite; }
.p-chip.xp { color: var(--p-xp); }
.p-chip.boost { background: linear-gradient(90deg, var(--p-gold), var(--p-flame)); color: #fff; }
.p-ring { width: 22px; height: 22px; }

/* ── Bottom tabs ─────────────────────────────────────────────────────────── */
.p-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--p-surface);
  border-top: 1px solid var(--p-line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.p-tabs-inner { max-width: 640px; margin: 0 auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.p-tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; border-radius: 12px;
  text-decoration: none; font-size: .68rem; font-weight: 800; color: var(--p-muted); position: relative;
}
.p-tab .ico { font-size: 1.45rem; line-height: 1; transition: transform .2s; }
.p-tab.active { color: var(--p-xp); background: color-mix(in srgb, var(--p-xp) 10%, transparent); }
.p-tab.active .ico { transform: translateY(-2px) scale(1.12); }
.p-tab .dot {
  position: absolute; top: 4px; right: 22%; min-width: 16px; height: 16px; border-radius: 999px; background: var(--p-bad);
  color: #fff; font-size: .62rem; display: grid; place-items: center; padding: 0 4px;
}

/* ── Cards & bits ────────────────────────────────────────────────────────── */
.p-h1 { font-size: 1.6rem; font-weight: 900; letter-spacing: -.02em; margin: 18px 0 4px; }
.p-sub { color: var(--p-muted); margin: 0 0 14px; font-weight: 600; }
.p-card { background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow); padding: 16px; margin: 12px 0; }
.p-card h2 { font-size: 1rem; margin: 0 0 10px; font-weight: 900; display: flex; align-items: center; gap: 8px; }
.p-card h2 .right { margin-left: auto; font-size: .8rem; color: var(--p-muted); font-weight: 700; }
.p-muted { color: var(--p-muted); }
.p-row { display: flex; align-items: center; gap: 12px; }
.p-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.p-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--p-surface-2); font-size: .75rem; font-weight: 800; }

.p-btn, .p-modal-card { box-sizing: border-box; }
.p-btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 900; letter-spacing: .02em;
  text-transform: uppercase; font-size: .95rem; padding: 14px 18px; border-radius: 16px; width: 100%;
  background: var(--p-xp); color: #fff; box-shadow: 0 4px 0 color-mix(in srgb, var(--p-xp) 70%, #000);
  transition: transform .06s, box-shadow .06s, filter .2s; text-decoration: none; display: inline-block; text-align: center;
}
.p-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 color-mix(in srgb, var(--p-xp) 70%, #000); }
.p-btn:disabled { filter: grayscale(1) opacity(.5); cursor: default; }
.p-btn.flame { background: var(--p-flame); box-shadow: 0 4px 0 #c55500; }
.p-btn.ok { background: var(--p-ok); box-shadow: 0 4px 0 #157a3e; }
.p-btn.bad { background: var(--p-bad); box-shadow: 0 4px 0 #a52a2e; }
.p-btn.ghost { background: var(--p-surface-2); color: var(--p-ink); box-shadow: 0 4px 0 var(--p-line); }
.p-btn.small { padding: 8px 12px; font-size: .78rem; width: auto; border-radius: 12px; }

.p-bar { height: 14px; border-radius: 999px; background: var(--p-surface-2); overflow: hidden; position: relative; }
.p-bar > i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--p-xp), var(--p-xp-2)); transition: width .6s cubic-bezier(.2, .9, .3, 1.2); }
.p-bar.flame > i { background: linear-gradient(90deg, var(--p-flame), var(--p-flame-2)); }
.p-bar.ok > i { background: linear-gradient(90deg, var(--p-ok), #6ee7a0); }
.p-bar > i::after { content: ""; position: absolute; inset: 3px 8px auto; height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .35); }

/* hero */
.p-hero { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; }
.p-flame-big { font-size: 64px; line-height: 1; filter: drop-shadow(0 6px 12px rgba(255, 122, 26, .35)); }
.p-flame-big.cold { filter: grayscale(1) opacity(.5); }
.p-streak-n { font-size: 2.4rem; font-weight: 900; line-height: 1; }
.p-week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 10px; }
.p-week div { text-align: center; font-size: .7rem; font-weight: 800; color: var(--p-muted); }
.p-week b { display: grid; place-items: center; width: 30px; height: 30px; margin: 3px auto 0; border-radius: 50%; background: var(--p-surface-2); font-size: .9rem; }
.p-week .on b { background: var(--p-flame); color: #fff; }
.p-week .today b { outline: 3px solid color-mix(in srgb, var(--p-flame) 35%, transparent); }

.p-cta { display: block; text-decoration: none; padding: 18px; border-radius: var(--p-radius); color: #fff; position: relative; overflow: hidden; }
.p-cta h3, .p-cta p { position: relative; z-index: 1; text-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.p-cta h3 { margin: 0; font-size: 1.25rem; font-weight: 900; }
.p-cta p { margin: 4px 0 0; opacity: .9; font-weight: 700; font-size: .9rem; }
.p-cta .big { position: absolute; right: -6px; bottom: -14px; font-size: 64px; opacity: .45; transform: rotate(-12deg); }
.p-cta.practice { background: linear-gradient(135deg, #7c4dff, #b25cff); }
.p-cta.daily { background: linear-gradient(135deg, #ff7a1a, #ff4d6d); }
.p-cta.done { background: linear-gradient(135deg, #22a95a, #2bc4a6); }

.p-quest { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; }
.p-quest + .p-quest { border-top: 1px dashed var(--p-line); }
.p-quest .qi { font-size: 1.5rem; text-align: center; }
.p-quest .qt { font-weight: 800; font-size: .92rem; margin-bottom: 5px; }
.p-quest .qr { font-weight: 900; color: var(--p-xp); font-size: .85rem; }
.p-quest.done .qt { text-decoration: line-through; color: var(--p-muted); }

.p-chest { display: flex; align-items: center; gap: 14px; }
.p-chest .box { font-size: 52px; transition: transform .2s; }
.p-chest.ready .box { animation: p-wiggle 1.6s ease-in-out infinite; cursor: pointer; }
.p-chest.locked .box { filter: grayscale(.9) opacity(.6); }

.p-board { list-style: none; margin: 0; padding: 0; }
.p-board li { display: grid; grid-template-columns: 30px 38px 1fr auto; gap: 10px; align-items: center; padding: 9px 6px; border-radius: 12px; }
.p-board li.me { background: color-mix(in srgb, var(--p-xp) 10%, transparent); }
.p-board .rank { font-weight: 900; text-align: center; }
.p-board .rank.r1 { color: var(--p-gold); }
.p-avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #fff; font-size: 1rem; position: relative; }
.p-avatar .fl { position: absolute; right: -4px; bottom: -4px; font-size: .8rem; }
.p-board .name { font-weight: 800; }
.p-board .meta { font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--p-muted); font-weight: 700; }
.p-board .score { font-weight: 900; color: var(--p-xp); }

.p-wotd .w { font-size: 1.7rem; font-weight: 900; }
.p-wotd .ipa { color: var(--p-muted); font-weight: 700; margin-left: 6px; }
.p-wotd .m { font-weight: 700; margin: 4px 0; }
.p-wotd .ex { color: var(--p-muted); font-style: italic; }
.p-speak { border: 0; background: var(--p-surface-2); border-radius: 50%; width: 36px; height: 36px; cursor: pointer; font-size: 1.1rem; }

/* feed */
.p-post { display: grid; grid-template-columns: 38px 1fr; gap: 10px; padding: 12px 0; }
.p-post + .p-post { border-top: 1px solid var(--p-line); }
.p-post .head { font-weight: 700; font-size: .92rem; }
.p-post .head b { font-weight: 900; }
.p-post .time { color: var(--p-muted); font-size: .75rem; font-weight: 700; }
.p-post .box { margin-top: 8px; background: var(--p-surface-2); border-radius: 14px; padding: 10px 12px; }
.p-post .grid { font-size: .8rem; letter-spacing: 0; white-space: nowrap; }
.p-reacts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.p-react { border: 1px solid var(--p-line); background: var(--p-surface); border-radius: 999px; padding: 3px 9px; cursor: pointer; font: inherit; font-weight: 800; font-size: .85rem; }
.p-react.on { border-color: var(--p-xp); background: color-mix(in srgb, var(--p-xp) 12%, transparent); }
.p-react.pop { animation: p-pop .35s; }

/* achievements */
.p-badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.p-badge { text-align: center; padding: 12px 6px; border-radius: 16px; background: var(--p-surface-2); }
.p-badge .bi { font-size: 2.2rem; }
.p-badge .bt { font-weight: 900; font-size: .78rem; margin-top: 4px; }
.p-badge .bd { font-size: .68rem; color: var(--p-muted); font-weight: 700; }
.p-badge.locked .bi { filter: grayscale(1) opacity(.35); }
.p-badge.locked .bt { color: var(--p-muted); }

/* ── Lesson (practice / daily) ───────────────────────────────────────────── */
.l-head { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
.l-x { border: 0; background: none; font-size: 1.6rem; min-width: 44px; min-height: 44px; display: inline-grid; place-items: center; color: var(--p-muted); cursor: pointer; text-decoration: none; }
.l-head .p-bar { flex: 1; }
.l-combo { font-weight: 900; color: var(--p-flame); min-width: 54px; text-align: right; transition: transform .2s; }
.l-combo.bump { transform: scale(1.4); }
.l-kind { font-weight: 900; font-size: 1.25rem; margin: 10px 0 4px; }
.l-prompt { font-size: 2rem; font-weight: 900; margin: 12px 0 6px; line-height: 1.15; word-break: break-word; }
.l-prompt.sentence { font-size: 1.3rem; font-weight: 800; }
.l-hint { color: var(--p-muted); font-weight: 700; }
.l-choices { display: grid; gap: 10px; margin-top: 18px; }
.l-choice {
  appearance: none; font: inherit; font-weight: 800; font-size: 1.02rem; text-align: left; cursor: pointer; color: var(--p-ink);
  background: var(--p-surface); border: 2px solid var(--p-line); border-bottom-width: 5px; border-radius: 16px; padding: 14px 16px;
  display: flex; gap: 12px; align-items: center; transition: transform .06s;
}
.l-choice .k { display: grid; place-items: center; width: 26px; height: 26px; border: 2px solid var(--p-line); border-radius: 8px; font-size: .8rem; color: var(--p-muted); flex: none; }
.l-choice:active { transform: translateY(2px); }
.l-choice.right { border-color: var(--p-ok); background: var(--p-ok-2); }
.l-choice.wrong { border-color: var(--p-bad); background: var(--p-bad-2); animation: p-shake .35s; }
.l-choice:disabled { cursor: default; }
.l-type { width: 100%; box-sizing: border-box; font: inherit; font-size: 1.3rem; font-weight: 800; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--p-line); background: var(--p-surface); color: var(--p-ink); margin-top: 18px; }
.l-listen { width: 110px; height: 110px; border-radius: 30px; border: 0; background: var(--p-ice); color: #fff; font-size: 3rem; cursor: pointer; box-shadow: 0 6px 0 #1f7fd0; margin: 14px auto 0; display: block; }
.l-listen:active { transform: translateY(4px); box-shadow: 0 2px 0 #1f7fd0; }
.l-feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(110%); transition: transform .25s cubic-bezier(.2, .9, .3, 1.1);
}
.l-feedback:not(.show) { visibility: hidden; transition: transform .25s, visibility 0s .25s; }
.l-feedback.show { transform: none; }
.l-feedback.good { background: var(--p-ok-2); }
.l-feedback.bad { background: var(--p-bad-2); }
.l-feedback .inner { max-width: 640px; margin: 0 auto; }
.l-feedback .title { font-size: 1.3rem; font-weight: 900; margin-bottom: 4px; }
.l-feedback.good .title { color: var(--p-ok); }
.l-feedback.bad .title { color: var(--p-bad); }
.l-feedback .detail { font-weight: 700; margin-bottom: 12px; }
.l-feedback .ex { font-style: italic; color: var(--p-muted); font-weight: 600; margin-bottom: 12px; }
.l-timer { font-weight: 900; color: var(--p-ice); min-width: 54px; text-align: right; }

.l-result { text-align: center; padding-top: 24px; }
.l-result .trophy { font-size: 90px; animation: p-pop .6s; }
.l-result h1 { font-size: 2rem; font-weight: 900; margin: 8px 0; }
.l-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.l-stat { border-radius: 16px; padding: 3px; }
.l-stat .lab { font-size: .7rem; font-weight: 900; color: #fff; padding: 4px; text-transform: uppercase; }
.l-stat .val { background: var(--p-surface); border-radius: 13px; padding: 12px 4px; font-size: 1.3rem; font-weight: 900; }
.l-stat.xp { background: var(--p-xp); } .l-stat.xp .val { color: var(--p-xp); }
.l-stat.acc { background: var(--p-ok); } .l-stat.acc .val { color: var(--p-ok); }
.l-stat.combo { background: var(--p-flame); } .l-stat.combo .val { color: var(--p-flame); }
.l-mistake { text-align: left; padding: 8px 0; border-top: 1px solid var(--p-line); font-weight: 700; }

/* ── Overlays: toasts, modal, confetti, floating XP ──────────────────────── */
.p-toasts { position: fixed; bottom: calc(96px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 2000; display: grid; gap: 8px; width: min(92vw, 380px); pointer-events: none; }
.p-toast { background: var(--p-ink); color: var(--p-bg); border-radius: 16px; padding: 10px 14px; font-weight: 800; display: flex; gap: 10px; align-items: center; box-shadow: 0 12px 30px -10px rgba(0, 0, 0, .5); animation: p-drop .35s cubic-bezier(.2, .9, .3, 1.3); }
.p-toast .ti { font-size: 1.6rem; }
.p-toast small { display: block; opacity: .75; font-weight: 700; }
.p-toast.out { opacity: 0; transform: translateY(10px); transition: .3s; }
.p-float { position: fixed; z-index: 2001; font-weight: 900; color: var(--p-xp); font-size: 1.4rem; pointer-events: none; animation: p-float 1.1s ease-out forwards; text-shadow: 0 2px 0 #fff; }
.p-modal { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; background: rgba(15, 12, 25, .55); backdrop-filter: blur(4px); animation: p-fade .2s; padding: 20px; }
.p-modal-card { background: var(--p-surface); color: var(--p-ink); border-radius: 26px; padding: 26px 22px; max-width: 360px; width: 100%; text-align: center; animation: p-pop .45s cubic-bezier(.2, .9, .3, 1.4); }
.p-modal-card .mi { font-size: 84px; line-height: 1.1; }
.p-modal-card h2 { margin: 6px 0; font-size: 1.6rem; font-weight: 900; }
.p-modal-card p { color: var(--p-muted); font-weight: 700; margin: 0 0 18px; }
.p-confetti { position: fixed; inset: 0; pointer-events: none; z-index: 2999; }

/* Gamebar pill on the classic pages */
.gb-pill { position: fixed; left: 16px; bottom: 16px; z-index: 999; display: flex; gap: 6px; font-family: var(--p-font); }
.gb-pill a { text-decoration: none; }
.gb-pill .p-chip { font-size: .85rem; padding: 6px 10px; }
@media (max-width: 520px) { .gb-pill { left: 8px; bottom: 8px; } }

@keyframes p-pop { 0% { transform: scale(.4); opacity: 0 } 70% { transform: scale(1.08); opacity: 1 } 100% { transform: scale(1) } }
@keyframes p-drop { from { transform: translateY(20px); opacity: 0 } to { transform: none; opacity: 1 } }
@keyframes p-fade { from { opacity: 0 } }
@keyframes p-float { 0% { transform: translateY(0) scale(.8); opacity: 0 } 15% { opacity: 1; transform: translateY(-10px) scale(1.15) } 100% { transform: translateY(-80px) scale(1); opacity: 0 } }
@keyframes p-shake { 0%, 100% { transform: translateX(0) } 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }
@keyframes p-wiggle { 0%, 80%, 100% { transform: rotate(0) } 85% { transform: rotate(-12deg) scale(1.08) } 90% { transform: rotate(10deg) scale(1.08) } 95% { transform: rotate(-6deg) } }
@keyframes p-pulse { 50% { transform: scale(1.08) } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── Shell: language sheet, wide pages, widgets ──────────────────────────── */
button.p-chip { border: 0; font: inherit; font-weight: 800; color: inherit; cursor: pointer; }
.p-chip.lang { font-size: 1.1rem; padding: 5px 9px; }
.p-chip.lang .caret { font-size: .6rem; color: var(--p-muted); }
.play-wrap.wide { max-width: 1100px; }
.p-sheet {
  border: 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0;
  width: 100%; max-width: 480px; margin: auto auto 0; background: var(--p-surface); color: var(--p-ink);
  font-family: var(--p-font); box-sizing: border-box; box-shadow: var(--p-shadow);
}
@media (min-width: 700px) { .p-sheet { margin: auto; border-radius: 24px; } }
.p-sheet::backdrop { background: rgba(20, 18, 28, .45); backdrop-filter: blur(2px); }
.p-sheet h2 { margin: 0 0 12px; font-size: 1.15rem; font-weight: 900; }
.p-sheet form { margin: 0; }
.p-sheet-x { position: absolute; top: 12px; right: 12px; border: 0; background: var(--p-surface-2); color: var(--p-ink);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer; font-weight: 900; }
.p-sheet-row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 10px 14px; margin: 6px 0;
  border: 2px solid var(--p-line); border-radius: 16px; background: var(--p-surface); color: var(--p-ink);
  font: inherit; font-weight: 800; font-size: 1rem; text-align: left; cursor: pointer; text-decoration: none; box-sizing: border-box;
}
.p-sheet-row .fl { font-size: 1.4rem; width: 28px; text-align: center; }
.p-sheet-row .check { margin-left: auto; color: var(--p-xp); }
.p-sheet-row.on { border-color: var(--p-xp); background: color-mix(in srgb, var(--p-xp) 8%, var(--p-surface)); cursor: default; }
.p-sheet-row.add { color: var(--p-xp); border-style: dashed; }
.p-desktop-only { display: contents; }
@media (max-width: 899px) { .p-desktop-only { display: none; } }
/* Floating chat sits above the tab bar; the word-queue popup tucks under the top bar
   (top right) so it never covers buttons at the bottom of a page. */
.play-body .cw-float { bottom: 88px; }
.play-body .jobs-popup { top: 62px !important; bottom: auto !important; right: 12px; left: auto; width: min(340px, calc(100vw - 24px)); }
/* Nothing scrolls/focuses into the space behind the fixed bars */
html:has(.play-body) { scroll-padding-top: 70px; scroll-padding-bottom: 100px; }
/* During a lesson the tab bar is hidden and the feedback panel owns the bottom: toasts go up top */
.play-body:has(#lesson:not([hidden])) .p-toasts { bottom: auto; top: 70px; }

/* Sub-navigation inside a tab (e.g. Friends: League · Chat) */
.p-seg { display: flex; gap: 6px; background: var(--p-surface-2); padding: 4px; border-radius: 14px; margin: 14px 0 4px; }
.p-seg a { flex: 1; text-align: center; padding: 9px 6px; border-radius: 11px; font-weight: 900; font-size: .9rem; text-decoration: none; color: var(--p-muted); }
.p-seg a.on { background: var(--p-surface); color: var(--p-ink); box-shadow: var(--p-shadow); }

/* Forms */
.p-input, .p-select {
  font: inherit; font-weight: 700; font-size: 1rem; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--p-line);
  background: var(--p-surface); color: var(--p-ink); box-sizing: border-box; min-height: 48px; max-width: 100%;
}
.p-input:focus, .p-select:focus { outline: none; border-color: var(--p-xp); }
.p-label { display: block; font-size: .78rem; font-weight: 800; color: var(--p-muted); margin: 0 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.p-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.p-chips::-webkit-scrollbar { display: none; }
.p-chipf {
  flex: none; padding: 8px 12px; border-radius: 999px; background: var(--p-surface); box-shadow: var(--p-shadow);
  font-weight: 800; font-size: .85rem; text-decoration: none; white-space: nowrap; border: 2px solid transparent;
}
.p-chipf.on { border-color: var(--p-xp); color: var(--p-xp); }
.p-list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--p-line); text-decoration: none; }
.p-list-row:first-of-type { border-top: 0; }
.p-list-row .go { margin-left: auto; color: var(--p-muted); font-weight: 900; }
.p-flash { max-width: 640px; margin: 12px auto 0; padding: 0 16px; }
.p-flash > div { background: var(--p-ok-2); color: var(--p-ink); border-radius: 14px; padding: 10px 14px; font-weight: 700; }

/* ── Words tab ───────────────────────────────────────────────────────────── */
.w-add-row { display: flex; gap: 8px; }
.w-add-row .p-input { flex: 1; min-width: 0; }
.w-add-row .p-btn.small { padding: 0 18px; font-size: .9rem; }
.w-msg { font-size: .85rem; color: var(--p-muted); font-weight: 700; min-height: 1em; margin-top: 8px; }
.w-msg:empty { display: none; }
.w-packs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.w-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 4px 0 6px; align-items: end; }
.w-filter { display: block; min-width: 0; }
.w-filter .p-select { width: 100%; padding: 10px; font-size: .9rem; }
.w-clear { grid-column: 1 / -1; font-weight: 800; color: var(--p-xp) !important; font-size: .85rem; }
@media (max-width: 420px) { .w-filters { grid-template-columns: 1fr 1fr; } .w-filters .w-filter:first-child { grid-column: 1 / -1; } }
.w-list { display: grid; gap: 10px; margin: 10px 0; }
.w-card { background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow); padding: 14px 16px; min-width: 0; }
.w-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.w-word { font-size: 1.25rem; font-weight: 900; letter-spacing: -.01em; overflow-wrap: anywhere; }
.w-speak { width: 32px; height: 32px; font-size: .9rem; }
.w-tags { margin-left: auto; display: flex; gap: 6px; }
.w-tag { font-size: .72rem; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: var(--p-surface-2); color: var(--p-muted) !important; text-decoration: none; }
.w-card .ipa { color: var(--p-muted); font-size: .9rem; margin-top: 2px; }
.w-mean { font-weight: 700; margin-top: 6px; }
.w-trs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 6px; font-size: .9rem; }
.w-tr b { font-size: .7rem; color: var(--p-xp); margin-right: 2px; }
.w-more { margin-top: 8px; font-size: .9rem; }
.w-more summary { cursor: pointer; color: var(--p-xp); font-weight: 800; font-size: .85rem; }
.w-more p { margin: 6px 0 0; }
.w-ex { font-style: italic; }
.topic-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.topic-badge { font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--p-xp) 12%, var(--p-surface)); color: var(--p-xp); }
.w-pager { display: flex; justify-content: space-between; gap: 10px; margin: 6px 0 20px; }
.w-pager .p-btn { width: auto; }
.attribution { font-size: .75rem; }
.empty-state { text-align: center; color: var(--p-muted); font-weight: 700; }
.status-failed { background: var(--p-bad-2); color: var(--p-bad); }

/* ── Play + Me tabs ──────────────────────────────────────────────────────── */
.g-row > div { min-width: 0; }
.g-row .p-muted { font-size: .82rem; font-weight: 600; }
.g-ico { flex: none; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; }
@media (prefers-color-scheme: dark) { .g-ico { filter: saturate(.8) brightness(.7); } }
.g-stats > div { background: var(--p-surface-2); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; }
.g-stats b { font-size: 1.3rem; }
.g-stats span { font-size: .78rem; font-weight: 700; }
.me-head { display: flex; align-items: center; gap: 14px; margin: 18px 0 6px; }
.me-head .p-avatar { width: 58px; height: 58px; font-size: 1.6rem; }
.me-goals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 420px) { .me-goals { grid-template-columns: 1fr 1fr; } }
.me-goal { border: 2px solid var(--p-line); border-radius: 14px; background: var(--p-surface); color: var(--p-ink); font: inherit; padding: 10px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.me-goal span { font-size: .75rem; color: var(--p-muted); font-weight: 700; }
.me-goal.on { border-color: var(--p-xp); background: color-mix(in srgb, var(--p-xp) 8%, var(--p-surface)); }
.me-btn { width: 100%; background: none; border: 0; border-top: 1px solid var(--p-line); font: inherit; color: inherit; cursor: pointer; text-align: left; }
.p-list-row > span:first-child:not(.g-ico) { font-size: 1.2rem; width: 26px; text-align: center; flex: none; }
.p-list-row .p-muted { font-size: .82rem; font-weight: 600; }

/* ── Chat inside the shell: Lexi colours, fits above the tab bar ─────────── */
.play-body .cw {
  --cw-bg: var(--p-surface); --cw-text: var(--p-ink); --cw-muted: var(--p-muted); --cw-border: var(--p-line);
  --cw-soft: var(--p-surface-2); --cw-primary: var(--p-xp); --cw-mine-bg: color-mix(in srgb, var(--p-xp) 12%, var(--p-surface));
  --cw-mine-border: color-mix(in srgb, var(--p-xp) 35%, var(--p-surface)); font-family: var(--p-font);
}
.play-body .cw-page .cw-panel { height: calc(100dvh - 250px); min-height: 320px; border-radius: var(--p-radius); box-shadow: var(--p-shadow); border: 0; }
.chat-note { font-size: .8rem; font-weight: 600; margin: 6px 0 10px; }
.p-seg .online-pill { margin-left: 4px; }
.w-filter-box { margin: 4px 0 8px; }
.w-filter-box > summary { display: inline-block; list-style: none; cursor: pointer; }
.w-filter-box > summary::-webkit-details-marker { display: none; }
.w-filter-box[open] > summary { margin-bottom: 8px; }
.p-back { display: inline-block; margin-top: 14px; font-weight: 800; color: var(--p-xp) !important; text-decoration: none; }
.p-back + .p-h1 { margin-top: 6px; }

/* ── Home: one next step ─────────────────────────────────────────────────── */
.p-next { display: flex; align-items: center; gap: 14px; margin: 12px 0 6px; padding: 18px; border-radius: var(--p-radius); text-decoration: none;
  background: linear-gradient(135deg, var(--p-xp), #b25cff); color: #fff !important; box-shadow: 0 5px 0 color-mix(in srgb, var(--p-xp) 65%, #000); }
.p-next:active { transform: translateY(3px); box-shadow: 0 2px 0 color-mix(in srgb, var(--p-xp) 65%, #000); }
.p-next .ni { font-size: 2.2rem; }
.p-next b { display: block; font-size: 1.2rem; font-weight: 900; }
.p-next small { display: block; opacity: .9; font-weight: 700; }
.p-next .go { margin-left: auto; width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .22); display: grid; place-items: center; font-size: 1rem; }
.p-more { display: block; text-align: right; font-weight: 800; font-size: .85rem; color: var(--p-xp) !important; text-decoration: none; margin-bottom: 4px; }
.p-league-line { text-decoration: none; }
.p-league-line .go { margin-left: auto; color: var(--p-muted); font-weight: 900; }
.play-body .cw textarea:focus { outline: none; border-color: var(--p-xp); box-shadow: 0 0 0 3px color-mix(in srgb, var(--p-xp) 25%, transparent); }
.play-body .cw textarea { border-radius: 14px; }
.play-body .cw button { border-radius: 12px; font-weight: 800; }
/* Settings / admin buttons speak the same language as the rest */
.legacy-settings button:not(.chip button):not(.topic-chip):not(.pack-target-change), .legacy-admin button {
  border: 0; border-radius: 12px; font-weight: 800; background: var(--p-xp); color: #fff; box-shadow: 0 3px 0 color-mix(in srgb, var(--p-xp) 70%, #000); min-height: 42px; padding: 10px 16px;
}
.legacy-settings .pack-btn.reimport-btn { background: var(--p-surface-2); color: var(--p-ink); box-shadow: 0 3px 0 var(--p-line); }
.legacy-settings .pack-target-change { margin: 0 0 0 auto; padding: 6px 12px; border: 0; border-radius: 999px; background: var(--p-surface-2); color: var(--p-xp); font-weight: 800; cursor: pointer; }

/* ── Phones ──────────────────────────────────────────────────────────────── */
/* iOS zooms into any field under 16px when it gets focus */
@media (pointer: coarse) {
  .play-body input, .play-body select, .play-body textarea { font-size: max(16px, 1em) !important; }
  .play-body button, .play-body a, .play-body .key-btn, .play-body .l-choice { touch-action: manipulation; }
  .play-body { -webkit-tap-highlight-color: transparent; }
  .play-body .hangman-keyboard { -webkit-user-select: none; user-select: none; }
}
/* The word-queue popup only on Home and Words on phones; never over lessons, games or chat */
@media (max-width: 899px) { .play-body:not(.jobs-ok) .jobs-popup { display: none !important; } }
/* Sheets lock the page behind them */
html:has(dialog[open]) { overflow: hidden; }
.p-sheet { overscroll-behavior: contain; }
.p-top { -webkit-backdrop-filter: blur(10px); }
.w-search { margin: 4px 0 8px; }
.w-search .p-input { width: 100%; }
.me-more { margin-top: 10px; }
.me-more summary { cursor: pointer; color: var(--p-xp); font-weight: 800; font-size: .85rem; padding: 10px 0; }

.p-react-who { font-size: .75rem; color: var(--p-muted); font-weight: 700; margin-top: 4px; }
/* Thumb-sized targets on touch screens (44px, Apple HIG) */
@media (pointer: coarse) {
  .p-top .p-chip { min-height: 44px; box-sizing: border-box; }
  .p-speak { min-width: 44px; min-height: 44px; }
  .w-speak { width: 44px; height: 44px; }
  .p-react { min-height: 40px; padding: 6px 12px; }
  .p-sheet-x { width: 44px; height: 44px; }
  .p-card h2 .right a, .p-muted a { display: inline-block; padding: 10px 4px; margin: -10px -4px; }
  .legacy-settings .chip button { min-width: 32px; min-height: 32px; }
}

/* ── Word origins ────────────────────────────────────────────────────────── */
.o-q { font-size: .8rem; font-weight: 800; margin: 10px 0 6px; }
.o-chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.o-chips::-webkit-scrollbar { display: none; }
.o-chip { flex: none; border: 2px solid var(--p-line); background: var(--p-surface); color: var(--p-ink); border-radius: 999px;
  padding: 6px 11px; font: inherit; font-weight: 800; font-size: .82rem; cursor: pointer; min-height: 36px; }
.o-chip[aria-pressed="true"] { border-color: var(--p-xp); background: color-mix(in srgb, var(--p-xp) 10%, var(--p-surface)); color: var(--p-xp); }
.o-chip.recent { border-style: dashed; }
.o-note { width: 100%; margin-top: 8px; }
.w-origin { display: inline-block; margin-top: 6px; font-size: .78rem; font-weight: 800; padding: 3px 9px; border-radius: 999px;
  background: color-mix(in srgb, var(--p-flame) 12%, var(--p-surface)); color: color-mix(in srgb, var(--p-flame) 75%, var(--p-ink)); text-decoration: none; }
.w-from { margin: 2px 0 8px; }
@media (pointer: coarse) { .o-chip { min-height: 44px; } }

/* ── Daily story ─────────────────────────────────────────────────────────── */
.s-story { background: var(--p-surface); border-radius: var(--p-radius); box-shadow: var(--p-shadow); padding: 18px; margin: 10px 0 12px; }
.s-kicker { font-size: .78rem; font-weight: 900; color: var(--p-flame); text-transform: uppercase; letter-spacing: .05em; }
.s-story .p-h1 { margin: 4px 0 10px; }
.s-text { font-size: 1.15rem; line-height: 1.7; margin: 0 0 12px; white-space: pre-line; }
.s-w { font: inherit; border: 0; padding: 0 2px; margin: 0 -1px; border-radius: 6px; cursor: pointer; color: inherit; background: none; }
.s-w.known { background: color-mix(in srgb, var(--p-xp) 14%, transparent); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--p-xp) 55%, transparent); }
.s-w.new { background: color-mix(in srgb, var(--p-flame) 16%, transparent); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--p-flame) 60%, transparent); font-weight: 800; }
.s-legend { font-size: .78rem; color: var(--p-muted); font-weight: 700; margin-bottom: 12px; }
.s-legend .s-w { cursor: default; padding: 1px 6px; }
.s-new .s-save { margin-left: auto; flex: none; }
.s-foot { text-align: center; font-size: .82rem; font-weight: 700; margin: 12px 0 24px; }
.s-empty { text-align: center; padding: 24px 6px; }
.s-book { font-size: 72px; animation: p-float 3s ease-in-out infinite; }
@keyframes p-float { 50% { transform: translateY(-6px); } }
.s-card { text-decoration: none; background: linear-gradient(135deg, color-mix(in srgb, var(--p-flame) 14%, var(--p-surface)), var(--p-surface)); }
.s-card.done { background: var(--p-surface); opacity: .85; }
.s-card-ico { font-size: 1.8rem; }
.s-card .go { margin-left: auto; color: var(--p-muted); font-weight: 900; }
@media (pointer: coarse) {
  .p-brand { display: inline-block; padding: 11px 6px 11px 0; }
  .w-tag { padding: 8px 10px; }
  .p-card h2 .right a, .p-muted a, .p-more { padding: 12px 4px; margin: -12px -4px; display: inline-block; }
  .legacy .hm-mode-btn, .legacy #lg-board-lang, .p-btn.small { min-height: 44px; }
}
.p-board li > * { min-width: 0; }
.p-board .score { white-space: nowrap; }
.o-chip.recent[aria-pressed="true"] { border-style: solid; border-color: var(--p-xp); color: var(--p-xp); }
.s-legend .s-w { pointer-events: none; }
.w-practice-from { margin: 2px 0 10px; }
.w-notes .p-chipf { font-size: .8rem; max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }

/* Word-queue popup on phones: one slim line under the top bar, not a card over the title */
@media (max-width: 899px) {
  .play-body .jobs-popup { left: 12px !important; right: 12px !important; width: auto !important; padding: 4px 4px 4px 12px !important; border-radius: 999px !important; }
  .play-body .jobs-popup .jp-sub, .play-body .jobs-popup .jp-bar { display: none !important; }
  .play-body .jobs-popup .jp-row { gap: 8px; }
  .play-body .jobs-popup #jp-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .play-body.jobs-ok .play-wrap { padding-top: 44px; }
  .play-body.jobs-ok:not(:has(.jobs-popup:not([hidden]))) .play-wrap { padding-top: 0; }
}
