/* =========================================================================
   RolePlay English — giao diện "vở học trò"
   Ý tưởng: trang vở kẻ dòng, thẻ viền mực như giấy dán lên vở, lời sửa lỗi
   là nét bút đỏ của giáo viên. Ban đêm: vở kẻ dòng nền xanh than.
   Ưu tiên điện thoại: hội thoại toàn màn hình, mic to dưới ngón cái;
   máy tính bảng/máy tính: thêm cột nhiệm vụ.
   ========================================================================= */

/* Phần tử có thuộc tính hidden luôn ẩn, kể cả khi CSS khác đặt display */
[hidden] { display: none !important; }

:root {
  --bg: #FBF7EC;            /* giấy */
  --paper-line: #DCE6F2;    /* dòng kẻ */
  --surface: #FFFFFF;
  --surface-2: #F4EFE2;
  --ink: #1F2A44;           /* mực */
  --muted: #5E6678;
  --line: #DDD5C2;          /* đường mảnh, phân cách nhẹ */
  --edge: #1F2A44;          /* viền đậm của thẻ, nút */
  --hard: #1F2A44;          /* màu bóng đổ cứng */
  --accent: #1F2A44;
  --accent-ink: #FFFFFF;
  --accent-soft: #E6EAF3;
  --pen: #D9472F;           /* bút đỏ */
  --pen-soft: #FDEBE5;
  --pen-line: #F0B8AA;
  --good: #2E7D4F;
  --good-soft: #E3F2E6;
  --good-line: #B5DCC0;
  --warn: #8F5600;
  --warn-soft: #FFF3D1;
  --tape: #FFE68A;          /* băng dính vàng */
  --tape-ink: #1F2A44;
  --t1: #FFF0B8; --t2: #FFE1D6; --t3: #DDF0E2; --t4: #E1E7FA;   /* nền ô biểu tượng */
  --shadow: 3px 3px 0 var(--hard);
  --shadow-sm: 2px 2px 0 var(--hard);
  --shadow-up: 0 -8px 30px rgba(31, 42, 68, .18);

  --display: "Fraunces", "Times New Roman", "Noto Serif", serif;
  --body: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", "Segoe Print", "Comic Sans MS", cursive;

  --r-sm: 6px;
  --r: 8px;
  --r-lg: 10px;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
  --paper: repeating-linear-gradient(to bottom, transparent 0 27px, var(--paper-line) 27px 28px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171B24;
    --paper-line: #232A38;
    --surface: #202634;
    --surface-2: #283043;
    --ink: #E6E4DC;
    --muted: #A3A9B8;
    --line: #353D50;
    --edge: #8B93A7;
    --hard: #05070B;
    --accent: #E6E4DC;
    --accent-ink: #171B24;
    --accent-soft: #2C3548;
    --pen: #FF7A68;
    --pen-soft: #3A2120;
    --pen-line: #6B3129;
    --good: #7AD3A0;
    --good-soft: #15291D;
    --good-line: #2A5A3E;
    --warn: #F0B35A;
    --warn-soft: #33290F;
    --tape: #C9A93A;
    --tape-ink: #171B24;
    --t1: #3A3420; --t2: #3A2622; --t3: #1F3328; --t4: #252E48;
    --shadow-up: 0 -8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ---------- Nền tảng ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background-color: var(--bg);
  background-image: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--display); font-weight: 700; margin: 0; text-wrap: balance; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--pen); }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 2.5px solid var(--pen); outline-offset: 2px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
/* Nhãn kiểu băng dính dán trên vở */
.eyebrow {
  justify-self: start; display: inline-block;
  font-size: 12.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--tape-ink); background: var(--tape); padding: 3px 10px;
  transform: rotate(-1.5deg);
}

.wrap {
  min-height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-block: max(12px, env(safe-area-inset-top, 0px)) max(24px, env(safe-area-inset-bottom, 0px));
  padding-left: var(--gutter);
  padding-right: var(--gutter-r);
}

/* ---------- Nút & ô nhập ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: var(--r); border: 1.5px solid var(--edge);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
  font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background .15s, transform .1s, box-shadow .1s;
}
.btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--hard); }
.btn:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 38px; padding: 7px 13px; font-size: 14px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--surface); }
.btn.danger { background: var(--pen-soft); color: var(--pen); }
.btn.pen-btn { background: var(--pen-soft); color: var(--pen); }

input, select {
  font: inherit; font-size: 16px; /* 16px để iPhone không tự phóng to khi gõ */
  color: var(--ink); background: var(--surface);
  border: 1.5px solid var(--edge); border-radius: var(--r);
  min-height: 46px; padding: 10px 14px; width: 100%; min-width: 0;
  transition: box-shadow .15s;
}
input:focus, select:focus { outline: none; box-shadow: 3px 3px 0 var(--pen); }
input::placeholder { color: var(--muted); opacity: .8; }
.field { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.field input, .field select { font-weight: 400; }
.err { color: var(--pen); font-size: 14px; min-height: 1.2em; }
.card { background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow); }

/* ---------- Thanh trên cùng ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 6px 4px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px 0; font-family: var(--display); font-weight: 600; font-size: 20px; color: var(--ink); text-decoration: none; }
.brand b { font-family: var(--hand); font-weight: 700; font-size: 1.3em; line-height: 1; color: var(--pen); }
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--r); display: grid; place-items: center;
  background: var(--pen); color: #fff; font-family: var(--hand); font-weight: 700; font-size: 24px; line-height: 1;
  border: 1.5px solid var(--edge); box-shadow: var(--shadow-sm); transform: rotate(-4deg);
}
.top-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.quota {
  font-size: 13px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1.5px solid var(--edge); border-radius: 99px; padding: 5px 11px;
}
.who-me { font-weight: 600; font-size: 14px; }

/* ---------- Đăng nhập ---------- */
.login { flex: 1; display: grid; grid-template-columns: 1.1fr 1fr; gap: 48px; align-items: center; padding-block: 32px; }
.login-intro { display: grid; gap: 18px; }
.login-intro h1 { font-size: clamp(30px, 4.6vw, 50px); line-height: 1.08; font-weight: 800; }
.login-intro h1 em, .hero h1 em {
  font-style: normal; font-family: var(--hand); font-weight: 700; font-size: 1.22em; line-height: .9;
  color: var(--pen); white-space: nowrap;
}
.login-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; color: var(--muted); }
.login-points li { display: flex; gap: 12px; align-items: baseline; }
.login-points span { font-size: 18px; }
.login-card { padding: 28px; display: grid; gap: 16px; transform: rotate(.6deg); }
.login-card h2 { font-size: 26px; }

/* Thông tin liên hệ ở trang đăng nhập */
.contact { justify-self: start; display: grid; grid-template-columns: auto auto; align-items: center; gap: 4px 18px;
  background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 12px 16px; transform: rotate(-.6deg); }
.contact-label { grid-column: 1 / -1; font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.contact-phone { font-family: var(--hand); font-weight: 700; font-size: 34px; line-height: 1.1; color: var(--pen); text-decoration: none; white-space: nowrap; }
.contact-btns { display: flex; gap: 8px; }
.center { text-align: center; }

/* Thẻ Đăng nhập / Đăng ký */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border: 1.5px solid var(--edge); border-radius: var(--r); }
.tab { border: 0; background: transparent; border-radius: var(--r-sm); min-height: 42px; font-family: var(--display); font-weight: 700; font-size: 18px; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--bg); }
.auth-form { display: grid; gap: 16px; }
.hint-text { font-weight: 400; font-size: 12.5px; color: var(--muted); }

/* Gói dùng trên thanh trên cùng */
.quota { display: inline-flex; align-items: center; gap: 6px; }
.quota.low { border-color: var(--pen); color: var(--pen); }
.plan-tag { font-size: 11px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 1px 7px; border-radius: 99px; background: var(--good-soft); color: var(--good); }
.plan-tag.free { background: var(--surface-2); color: var(--muted); }
.btn.buy-btn { background: var(--tape); color: var(--tape-ink); }

/* Hộp mua gói tháng */
.sheet.buy { max-width: 520px; }
.sheet.buy .eyebrow { margin-bottom: -6px; }
.buy-lead { color: var(--muted); }
.plans { display: grid; grid-template-columns: 1fr 1.25fr; gap: 14px; align-items: stretch; }
.plan { background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 12px 14px; display: grid; gap: 2px; justify-items: center; text-align: center; }
.plan b { font-size: 14px; }
.plan small { color: var(--muted); font-size: 12.5px; }
.plan-n { font-family: var(--hand); font-weight: 700; font-size: 48px; line-height: 1; color: var(--muted); }
.plan.hot { border-width: 2px; box-shadow: 4px 4px 0 var(--pen); transform: rotate(.8deg); }
.plan.hot .plan-n { color: var(--pen); }
.price { margin-top: 6px; font-weight: 700; background: var(--tape); color: var(--tape-ink); padding: 2px 10px; transform: rotate(-1.5deg); }
.buy-steps { margin: 0; padding-left: 22px; display: grid; gap: 8px; }
.buy-steps .btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; margin-left: 4px; }

/* ---------- Trang chọn tình huống ---------- */
.home { display: grid; gap: 34px; padding-block: 12px 8px; }
.hero { display: grid; gap: 14px; padding-top: 18px; }
.hero h1 { font-size: clamp(30px, 5vw, 52px); line-height: 1.08; font-weight: 800; max-width: 17ch; }
.flow { list-style: none; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; max-width: 820px; }
.flow li { display: flex; gap: 12px; align-items: center; background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 12px 14px; }
.flow-ic { width: 40px; height: 40px; flex: none; border-radius: var(--r); display: grid; place-items: center; background: var(--t4); font-size: 20px; }
.flow-ic.pen { background: var(--t2); }
.flow li:last-child .flow-ic { background: var(--t3); }
.flow b { display: block; font-size: 15px; }
.flow small { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; }

.block { display: grid; gap: 14px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.block-head h2 { font-size: 24px; }
.block-head h2::after { content: ""; display: block; height: 3px; width: 46px; margin-top: 4px; background: var(--pen); border-radius: 2px; transform: rotate(-1deg); }

.seg { display: inline-grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; padding: 4px; background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); max-width: 520px; width: 100%; }
.seg-btn { border: 0; background: transparent; border-radius: var(--r-sm); padding: 9px 10px; min-height: 52px; display: grid; gap: 1px; justify-items: center; transition: background .15s, color .15s; }
.seg-btn b { font-size: 15px; }
.seg-btn small { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.seg-btn[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.seg-btn[aria-pressed="true"] small { color: inherit; opacity: .75; }

.scenes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.scene {
  position: relative; text-align: left; border: 1.5px solid var(--edge); background: var(--surface);
  border-radius: var(--r-lg); padding: 16px; display: grid; gap: 10px; align-content: start;
  box-shadow: var(--shadow); transition: transform .18s, box-shadow .18s; min-width: 0;
  transform: rotate(-.8deg);
}
.scene:nth-child(even) { transform: rotate(.7deg); }
.scene:nth-child(3n) { transform: rotate(-.4deg); }
.scene:hover { transform: rotate(0) translate(-2px, -3px); box-shadow: 5px 6px 0 var(--hard); }
.scene:active { transform: translate(2px, 2px); box-shadow: none; }
.scene-tile { width: 52px; height: 52px; border-radius: var(--r); display: grid; place-items: center; font-size: 28px; background: var(--t1); border: 1.5px solid var(--edge); }
.scene:nth-child(4n+2) .scene-tile { background: var(--t2); }
.scene:nth-child(4n+3) .scene-tile { background: var(--t3); }
.scene:nth-child(4n+4) .scene-tile { background: var(--t4); }
.scene h3 { font-size: 17.5px; line-height: 1.25; }
.scene p { font-size: 13.5px; color: var(--muted); line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.scene .cast { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.scene .cast span { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px dashed var(--edge); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.custom { display: grid; grid-template-columns: 1fr 1fr 2fr auto; gap: 12px; align-items: end; padding: 16px; }

/* ---------- Hội thoại ---------- */
body.in-chat { overflow: hidden; }
body.in-chat .wrap { height: 100dvh; min-height: 0; padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
.chat { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; padding-top: 10px; }
.convo { display: flex; flex-direction: column; min-height: 0; background: var(--bg); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow); overflow: hidden; }

.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1.5px solid var(--edge); background: var(--surface); }
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: var(--r); border: 1.5px solid var(--edge); background: var(--surface); font-size: 20px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }
.scene-id { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.scene-ic { width: 42px; height: 42px; flex: none; border-radius: var(--r); display: grid; place-items: center; font-size: 22px; background: var(--t1); border: 1.5px solid var(--edge); }
.scene-txt { min-width: 0; }
.scene-txt h1 { font-size: 18px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scene-txt p { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; white-space: nowrap; overflow: hidden; }
.scene-txt p span { overflow: hidden; text-overflow: ellipsis; }
.scene-txt b { color: var(--ink); font-weight: 600; }

.prog { position: relative; width: 46px; height: 46px; flex: none; border: 0; background: none; padding: 0; display: grid; place-items: center; }
.prog svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.prog circle { fill: none; stroke-width: 3.5; }
.prog-bg { stroke: var(--line); }
.prog-fg { stroke: var(--good); stroke-linecap: round; stroke-dasharray: 94.25; stroke-dashoffset: 94.25; transition: stroke-dashoffset .5s ease; }
.prog span { position: relative; font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Tin nhắn: viết trên trang vở, dòng kẻ cuộn theo nội dung */
.messages {
  position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 18px; display: flex; flex-direction: column; gap: 16px; scroll-padding: 12px;
  background-color: var(--bg); background-image: var(--paper); background-attachment: local;
}
.spacer { flex: none; height: 0; }
.msg { max-width: min(78%, 620px); display: grid; gap: 6px; min-width: 0; animation: rise .25s ease both; }
.msg.ai { align-self: flex-start; }
.msg.user { align-self: flex-end; justify-items: end; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.who { font-size: 11.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-inline: 4px; }
.bubble { padding: 11px 15px; border-radius: var(--r-lg); line-height: 1.5; overflow-wrap: anywhere; font-size: 16px; }
.msg.ai .bubble { background: var(--surface); border: 1.5px solid var(--edge); box-shadow: var(--shadow-sm); border-top-left-radius: 2px; }
.msg.user .bubble { background: var(--accent); color: var(--accent-ink); border: 1.5px solid var(--edge); border-top-right-radius: 2px; }
.bubble .vi { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); font-size: 14px; color: var(--muted); }
.speak { background: var(--surface-2); border: 1.5px solid var(--edge); border-radius: 99px; width: 30px; height: 30px; margin-left: 8px; vertical-align: middle; font-size: 13px; display: inline-grid; place-items: center; }

/* Ghi chú sửa lỗi: nét bút đỏ của giáo viên */
.note { font-size: 14.5px; border-radius: var(--r); padding: 10px 14px; text-align: left; background: var(--warn-soft); line-height: 1.45; max-width: 100%; }
.note b { display: block; }
.note.fix { background: var(--surface); border: 1.5px dashed var(--pen); transform: rotate(-.4deg); }
.note.fix .pen-label, .note.good .pen-label { font-family: var(--hand); font-size: 23px; line-height: 1; font-weight: 700; }
.note.fix .pen-label { color: var(--pen); }
.note.fix .pen-label::before { content: "✎ "; font-family: var(--body); font-size: 15px; }
.note.fix .better { display: block; margin: 5px 0; font-size: 16px; font-weight: 600; color: var(--ink); text-decoration: underline wavy var(--pen); text-decoration-thickness: 1.5px; text-underline-offset: 6px; }
.note.fix .why { color: var(--muted); }
.note.good { background: var(--surface); border: 1.5px dashed var(--good); }
.note.good .pen-label { color: var(--good); }
.note.good .pen-label::after { content: " ✓"; }
.note.sys { background: var(--tape); color: var(--tape-ink); align-self: center; text-align: center; max-width: 520px; border-radius: 2px; transform: rotate(-.5deg); box-shadow: var(--shadow-sm); }
.rail .note { transform: none; }

.typing { display: inline-flex; gap: 5px; padding: 15px 16px !important; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25 } 40% { opacity: 1 } }

/* Ô soạn câu */
.composer-wrap { border-top: 1.5px solid var(--edge); background: var(--surface); padding: 10px 12px 12px; display: grid; gap: 10px; }
.suggestions { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 2px 12px 5px; }
.suggestions:empty { display: none; }
.suggestions::-webkit-scrollbar { display: none; }
/* Câu gợi ý như giấy nhớ */
.suggestions button { flex: none; font-size: 14px; border: 0; color: var(--tape-ink); background: var(--tape); border-radius: 2px; padding: 8px 14px; min-height: 40px; max-width: 85vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: 2px 2px 0 var(--hard); }
.suggestions button:nth-child(even) { background: var(--t2); color: var(--ink); }
.suggestions button:active { transform: translate(2px, 2px); box-shadow: none; }
.composer { display: flex; align-items: center; gap: 10px; }
.input-box { flex: 1; min-width: 0; position: relative; }
.input-box input { padding-right: 48px; border-radius: 99px; min-height: 50px; background: var(--surface-2); }
.hint { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0; border-radius: 99px; background: transparent; font-size: 18px; }
.hint:hover { background: var(--surface); }

.mic {
  flex: none; height: 50px; min-width: 50px; padding: 0 18px; border-radius: 99px;
  border: 2px solid var(--edge); background: var(--pen); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 3px 3px 0 var(--hard);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: background .2s, transform .1s, box-shadow .1s;
}
.mic .ic { font-size: 19px; line-height: 1; }
.mic:active { transform: translate(2px, 2px); box-shadow: none; }
/* Đang nghe: nút "ấn xuống" và nhấp nháy đỏ */
.mic.on { background: var(--pen); color: #fff; transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--hard); animation: pulse 1.4s infinite; }
.mic.on.waiting { background: var(--muted); animation: none; }
.mic.ready { background: var(--accent); color: var(--accent-ink); animation: pulse-ready 1.6s infinite; }
.mic.waiting { background: var(--muted); color: var(--bg); animation: none; }
@keyframes pulse-ready { 0% { box-shadow: 3px 3px 0 var(--hard), 0 0 0 0 var(--pen-line); } 70% { box-shadow: 3px 3px 0 var(--hard), 0 0 0 12px transparent; } 100% { box-shadow: 3px 3px 0 var(--hard), 0 0 0 0 transparent; } }
@keyframes pulse { 0% { box-shadow: 1px 1px 0 var(--hard), 0 0 0 0 var(--pen-line); } 70% { box-shadow: 1px 1px 0 var(--hard), 0 0 0 12px transparent; } 100% { box-shadow: 1px 1px 0 var(--hard), 0 0 0 0 transparent; } }

.send { flex: none; height: 50px; min-width: 50px; padding: 0 20px; border-radius: 99px; border: 2px solid var(--edge); background: var(--accent); color: var(--accent-ink); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 6px; box-shadow: 3px 3px 0 var(--hard); transition: transform .1s, box-shadow .1s; }
.send:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.send .arrow { display: none; font-size: 20px; }
.send:disabled { opacity: .5; }

/* Cột nhiệm vụ / bảng trượt */
.rail { display: grid; gap: 14px; align-content: start; overflow-y: auto; min-height: 0; padding: 2px 4px 4px 0; }
.rail-sec { background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: 16px; display: grid; gap: 12px; }
.rail-sec h2 {
  justify-self: start; font-family: var(--body); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--tape-ink); background: var(--tape); padding: 2px 9px; transform: rotate(-1.5deg);
}
.rail-sec h2 small { text-transform: none; letter-spacing: 0; font-weight: 500; opacity: .8; }
.rail-grip, .rail-close { display: none; }
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 14.5px; }
.goals li { display: flex; gap: 10px; align-items: flex-start; line-height: 1.35; }
.goals li::before { content: ""; flex: none; width: 20px; height: 20px; border-radius: 4px; border: 1.5px solid var(--edge); margin-top: -1px; }
.goals li.done { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--pen); text-decoration-thickness: 2px; }
.goals li.done::before { background: var(--good) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M5 10.5l3.2 3L15 7' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/16px no-repeat; border-color: var(--good); }
.vocab { display: flex; flex-wrap: wrap; gap: 8px; }
.vocab button { font-size: 14px; background: var(--surface-2); color: var(--ink); border: 1.5px dashed var(--edge); border-radius: var(--r-sm); padding: 6px 11px; min-height: 36px; }
.vocab button:hover { background: var(--tape); color: var(--tape-ink); border-style: solid; }
.switch { display: flex; align-items: center; gap: 12px; font-size: 14.5px; min-height: 36px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; min-height: 0; padding: 0; flex: none; border-radius: 99px; background: var(--line); border: 1.5px solid var(--edge); position: relative; cursor: pointer; transition: background .2s; }
.switch input:focus { box-shadow: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px; border-radius: 50%; background: #fff; border: 1.5px solid var(--edge); box-sizing: border-box; transition: transform .2s; }
.switch input:checked { background: var(--good); }
.switch input:checked::after { transform: translateX(18px); }
.settings .field { font-size: 13px; }
.settings select { min-height: 42px; font-size: 15px; }
.backdrop { position: fixed; inset: 0; background: rgba(8, 12, 18, .45); z-index: 40; }

/* ---------- Nhận xét (hộp thoại) ---------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(8, 12, 18, .5); display: grid; place-items: center; padding: 16px var(--gutter-r) 16px var(--gutter); }
.sheet { width: 100%; max-width: 680px; max-height: 88dvh; overflow-y: auto; background-color: var(--bg); background-image: var(--paper); background-attachment: local; border: 2px solid var(--edge); border-radius: var(--r-lg); padding: 24px; display: grid; gap: 16px; box-shadow: 6px 6px 0 var(--hard); }
.sheet h2 { font-size: 26px; }
.scores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.score { background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r); box-shadow: var(--shadow-sm); padding: 10px 8px; text-align: center; }
.score:nth-child(even) { transform: rotate(1deg); }
.score:nth-child(odd) { transform: rotate(-.8deg); }
/* Điểm số viết tay bằng bút đỏ */
.score b { display: block; font-family: var(--hand); font-weight: 700; font-size: 44px; line-height: 1; color: var(--pen); font-variant-numeric: tabular-nums; }
.score small { color: var(--muted); font-size: 13px; }
.fb { display: grid; gap: 12px; }
.fb h3 { font-size: 17px; margin-top: 4px; }
.fb ul { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.fb s { color: var(--pen); }
.actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* ---------- Trang quản trị ---------- */
.section { display: grid; gap: 12px; margin-top: 24px; }
.section h1 { font-size: clamp(26px, 4vw, 34px); }
.label { justify-self: start; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tape-ink); background: var(--tape); padding: 2px 9px; transform: rotate(-1deg); }
.admin-form { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; align-items: end; background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow); }
.admin-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.admin-form .check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.admin-form .check input { width: 20px; height: 20px; min-height: 0; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1.5px solid var(--edge); border-radius: var(--r-lg); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1.5px solid var(--edge); }
td.num { font-variant-numeric: tabular-nums; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; background: var(--good-soft); color: var(--good); }
.pill.off { background: var(--pen-soft); color: var(--pen); }
.pill.free { background: var(--surface-2); color: var(--muted); }
.stats { color: var(--muted); }
.stats b { color: var(--ink); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.list-head input { max-width: 340px; }
.admin-form .hint-text { font-weight: 400; }
.toast { position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: var(--r); font-size: 14px; z-index: 70; box-shadow: 3px 3px 0 var(--pen); }

/* =========================================================================
   Máy tính bảng (dưới 1024px): cột nhiệm vụ thành bảng trượt từ dưới lên
   ========================================================================= */
@media (max-width: 1023px) {
  .scenes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chat { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
    max-height: 82dvh; background-color: var(--bg); background-image: var(--paper);
    border-top: 2px solid var(--edge);
    border-radius: 18px 18px 0 0; box-shadow: var(--shadow-up);
    padding: 8px var(--gutter-r) max(16px, env(safe-area-inset-bottom, 0px)) var(--gutter);
    transform: translateY(105%); visibility: hidden;
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .28s;
  }
  .rail.open { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2, .8, .2, 1); }
  .rail-grip { display: block; width: 44px; height: 5px; border-radius: 99px; background: var(--edge); margin: 4px auto 6px; }
  .rail-close { display: inline-flex; }
  .prog { cursor: pointer; }
  .prog::after { content: ""; position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 1px solid var(--edge); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 14'%3E%3Cpath d='M4 6l3 3 3-3' fill='none' stroke='%238B93A7' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E"); background-size: 12px; background-position: center; background-repeat: no-repeat; }
}
@media (min-width: 1024px) {
  .prog { cursor: default; }
}

/* =========================================================================
   Điện thoại (dưới 700px)
   ========================================================================= */
@media (max-width: 699px) {
  body { font-size: 15.5px; }
  .wrap { padding-block: max(8px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-bottom, 0px)); }
  .topbar { padding-block: 4px 0; }
  .brand { font-size: 18px; }
  .brand-mark { width: 30px; height: 30px; font-size: 21px; }
  .who-me, .q-l { display: none; }
  .topbar { flex-wrap: nowrap; }
  .top-right { flex-wrap: nowrap; gap: 6px; }
  .quota { padding: 4px 9px; white-space: nowrap; }
  .brand { white-space: nowrap; }
  /* Đã đăng nhập: chỉ giữ logo để đủ chỗ cho lượt dùng và các nút */
  .topbar:has(#userBar:not([hidden])) .brand-text { display: none; }
  .top-right .btn.small { min-height: 36px; padding: 6px 10px; font-size: 13px; }
  .quota .plan-tag { display: none; }
  .plans { grid-template-columns: 1fr 1fr; gap: 10px; }
  .plan-n { font-size: 40px; }

  .login { grid-template-columns: 1fr; gap: 22px; padding-block: 18px; align-content: start; }
  .login-points { font-size: 14.5px; }
  .login-card { padding: 20px; transform: none; }
  .contact { grid-template-columns: 1fr; justify-self: stretch; }
  .contact-btns .btn { flex: 1; }

  .home { gap: 28px; }
  .hero { padding-top: 8px; gap: 12px; }
  .flow { grid-template-columns: 1fr; gap: 10px; }
  .flow li { padding: 10px 12px; }
  .seg { max-width: none; }
  .scenes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; }
  .scene { padding: 13px; gap: 8px; }
  .scene-tile { width: 44px; height: 44px; font-size: 24px; }
  .scene h3 { font-size: 15.5px; }
  .scene p { font-size: 13px; -webkit-line-clamp: 2; }
  .scene .cast { display: none; }
  .custom { grid-template-columns: 1fr; }
  .custom .btn { width: 100%; }

  /* Hội thoại toàn màn hình */
  body.in-chat .topbar { display: none; }
  body.in-chat .wrap { padding: 0; max-width: none; }
  .chat { padding-top: 0; gap: 0; }
  .convo { border-radius: 0; border: 0; box-shadow: none; }
  .chat-head { padding: max(8px, env(safe-area-inset-top, 0px)) var(--gutter-r) 8px var(--gutter); gap: 8px; }
  .icon-btn { width: 40px; height: 40px; }
  .scene-ic { display: none; }
  .scene-txt h1 { font-size: 16.5px; }
  .scene-txt p span:first-child { display: none; }
  .prog { width: 42px; height: 42px; }
  .pen-btn .lbl { display: none; }
  .pen-btn { width: 42px; padding: 0; }
  .messages { padding: 16px var(--gutter-r) 16px var(--gutter); gap: 14px; }
  .msg { max-width: 88%; }
  .bubble { font-size: 16px; }
  .composer-wrap { padding: 8px var(--gutter-r) max(10px, env(safe-area-inset-bottom, 0px)) var(--gutter); }
  .suggestions { margin: 0 calc(-1 * var(--gutter-r)) 0 calc(-1 * var(--gutter)); padding: 2px var(--gutter-r) 5px var(--gutter); }
  .composer { gap: 8px; }
  .mic { height: 52px; min-width: 52px; padding: 0; width: 52px; }
  .mic .lbl { display: none; }
  .mic.on { width: auto; padding: 0 14px; }
  .mic.on .lbl, .mic.ready .lbl, .mic.waiting .lbl { display: inline; font-size: 13px; }
  .mic.ready, .mic.waiting { width: auto; padding: 0 14px; }
  .send { width: 50px; padding: 0; }
  .send .lbl { display: none; }
  .send .arrow { display: inline; }

  .modal { align-items: end; padding: 0; }
  .sheet { border-radius: 18px 18px 0 0; border-width: 2px 0 0; box-shadow: var(--shadow-up); max-height: 90dvh; padding: 20px var(--gutter-r) max(20px, env(safe-area-inset-bottom, 0px)) var(--gutter); }
  .scores { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions .btn { flex: 1; }

  .admin-form { grid-template-columns: 1fr 1fr; }
  .admin-form > div { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
