/* HVSC Game — layout + components */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font-family: var(--font); background: var(--c-bg); color: var(--c-ink); line-height: 1.5; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; min-height: 100dvh; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
p { margin: 0; }
a { color: var(--c-primary); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 2px; border-radius: 8px; }
.muted { color: var(--c-muted); }
.icon { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5em; min-height: var(--tap); padding: 0 1.15em; border-radius: 999px; border: 2px solid transparent; background: var(--c-surface); color: var(--c-ink); font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap; transition: transform .12s var(--ease-out), box-shadow .12s, background .15s; touch-action: manipulation; user-select: none; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--c-primary); color: var(--c-primary-ink); box-shadow: var(--shadow-press); }
.btn-accent { background: var(--c-accent); color: #fff; box-shadow: var(--shadow-press); }
.btn-soft { background: var(--c-primary-soft); color: var(--c-ink); }
.btn-ghost { background: transparent; border-color: var(--c-line); }
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-danger { background: var(--c-bad-soft); color: var(--c-bad); }
.btn-icon { width: var(--tap); padding: 0; flex: none; }
.btn-lg { min-height: calc(var(--tap) + 12px); font-size: 1.15rem; padding: 0 1.6em; }
.btn-xl { min-height: 80px; font-size: 1.5rem; padding: 0 2em; border-radius: 28px; }
.btn-block { width: 100%; }
.chip { display: inline-flex; align-items: center; gap: .4em; min-height: 40px; padding: 0 1em; border-radius: 999px; background: var(--c-surface); border: 2px solid var(--c-line); font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"], .chip.is-on { background: var(--c-ink); color: var(--c-bg); border-color: var(--c-ink); }
.chip .dot { width: .7em; height: .7em; border-radius: 50%; }

/* ---------- Forms ---------- */
.field { display: grid; gap: .35rem; }
.field > span, .label { font-weight: 700; font-size: .92rem; }
.input, .select, .textarea { width: 100%; min-height: var(--tap); padding: .6em .9em; border-radius: var(--r-sm); border: 2px solid var(--c-line); background: var(--c-surface); outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--c-primary); box-shadow: 0 0 0 4px var(--c-primary-soft); }
.textarea { min-height: 160px; resize: vertical; line-height: 1.5; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .92rem; }
.switch { display: inline-flex; align-items: center; gap: .65em; cursor: pointer; font-weight: 600; min-height: 40px; }
.switch input { appearance: none; width: 48px; height: 28px; border-radius: 99px; background: var(--c-line); position: relative; cursor: pointer; transition: background .2s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s var(--ease-out); }
.switch input:checked { background: var(--c-primary); }
.switch input:checked::after { transform: translateX(20px); }

/* ---------- Shell ---------- */
.app-header { position: sticky; top: 0; z-index: 30; height: var(--header-h); display: flex; align-items: center; gap: var(--sp-4); padding: 0 var(--page-pad); background: color-mix(in srgb, var(--c-bg) 86%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--c-line); }
.brand { display: flex; align-items: center; gap: .6rem; text-decoration: none; color: var(--c-ink); flex: none; }
.brand-logo { display: block; width: 192px; height: auto; aspect-ratio: 3 / 1; }
@media (min-width: 1700px) { .brand-logo { width: 184px; } }
.logo-on-dark { display: none; }
[data-theme="dem"] .logo-on-light { display: none; }
[data-theme="dem"] .logo-on-dark { display: block; }
.header-nav { display: flex; gap: .25rem; margin-left: var(--sp-4); }
.header-nav a { padding: .5em .9em; border-radius: 99px; font-weight: 700; text-decoration: none; color: var(--c-muted); }
.header-nav a[aria-current="page"] { background: var(--c-surface); color: var(--c-ink); box-shadow: var(--shadow-card); }
.header-spacer { flex: 1; }
.header-actions { display: flex; align-items: center; gap: .5rem; }
.app-main { padding: var(--sp-5) var(--page-pad) var(--sp-7); }
body[data-view="play"] .app-header, body[data-view="print"] .app-header.print-hide { display: none; }
body[data-view="play"] .app-main { padding: 0; }
.fab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40; width: 64px; height: 64px; border-radius: 22px; display: none; }
@media (max-width: 760px) {
  .header-nav, .hide-sm { display: none !important; }
  .fab { display: inline-flex; }
}
@media (min-width: 761px) { .show-sm { display: none !important; } }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-5); }
.page-head h1 { font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.6rem); font-weight: 800; }
.page-head .sub { color: var(--c-muted); margin-top: .25rem; }
.page-head .grow { flex: 1; min-width: 220px; }
.back-link { display: inline-flex; align-items: center; gap: .3em; color: var(--c-muted); font-weight: 700; text-decoration: none; margin-bottom: .5rem; }

/* ---------- Home ---------- */
.home { display: grid; grid-template-columns: 260px 1fr; gap: var(--sp-6); align-items: start; }
@media (min-width: 1700px) { .home { grid-template-columns: 300px 1fr; } }
.sidebar { position: sticky; top: calc(var(--header-h) + 24px); display: grid; gap: .25rem; }
.sidebar h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--c-muted); margin: var(--sp-4) .8rem .4rem; }
.side-item { display: flex; align-items: center; gap: .7rem; min-height: 46px; padding: 0 .8rem; border-radius: 14px; border: 0; background: none; text-align: left; font-weight: 600; cursor: pointer; width: 100%; }
.side-item:hover { background: var(--c-surface-2); }
.side-item[aria-current="true"] { background: var(--c-surface); box-shadow: var(--shadow-card); font-weight: 800; }
.side-item .count { margin-left: auto; color: var(--c-muted); font-size: .85rem; }
.folder-dot { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.folder-chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; margin: 0 calc(var(--page-pad) * -1) var(--sp-4); padding-inline: var(--page-pad); scrollbar-width: none; }
@media (max-width: 1000px) { .home { grid-template-columns: 1fr; } .sidebar { display: none; } }
@media (min-width: 1001px) { .folder-chips { display: none; } }
.toolbar { display: flex; gap: .75rem; align-items: center; margin-bottom: var(--sp-5); flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 560px; }
.search .icon { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: var(--c-muted); }
.search input { padding-left: 2.6rem; border-radius: 999px; }
.grid-cards { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
@media (max-width: 520px) { .grid-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; } }
@media (min-width: 1700px) { .grid-cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); } }
.home > *, .two-col > *, .act-card { min-width: 0; }
.act-card { position: relative; display: flex; flex-direction: column; background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-card); overflow: hidden; transition: transform .18s var(--ease-out), box-shadow .18s; }
.act-card:hover { transform: translateY(-3px); }
.act-thumb { aspect-ratio: 16/10; display: grid; place-items: center; background: var(--c-primary-soft); position: relative; cursor: pointer; border: 0; padding: 0; width: 100%; }
.act-thumb svg { width: 72%; height: 78%; }
.act-thumb .play-badge { position: absolute; inset: auto 12px 12px auto; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--c-primary); color: var(--c-primary-ink); box-shadow: var(--shadow-press); }
.act-body { padding: .9rem 1rem 1rem; display: grid; gap: .3rem; }
.act-title { font-weight: 800; font-size: 1.02rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.act-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; font-size: .82rem; color: var(--c-muted); }
.badge { display: inline-flex; align-items: center; gap: .3em; padding: .15em .6em; border-radius: 99px; background: var(--c-surface-2); font-weight: 700; font-size: .75rem; color: var(--c-ink); }
.act-actions { display: flex; gap: .4rem; padding: 0 1rem 1rem; }
.act-actions .btn { min-height: 40px; padding: 0 .9em; font-size: .88rem; }
.act-actions .btn-icon { width: 40px; }
@media (max-width: 520px) { .act-body { padding: .7rem; } .act-title { font-size: .92rem; } .act-actions { padding: 0 .7rem .7rem; } .act-actions .btn:not(.btn-icon) { flex: 1; } .act-actions .hide-xs { display: none; } }
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); background: var(--c-surface); border-radius: var(--r-xl); border: 2px dashed var(--c-line); display: grid; justify-items: center; gap: var(--sp-3); }
.empty svg { width: 160px; height: 120px; }

/* ---------- Menu / modal / toast ---------- */
.menu { position: fixed; z-index: 80; min-width: 220px; background: var(--c-surface); border-radius: var(--r); box-shadow: 0 20px 50px -12px rgba(0,0,0,.35); padding: .4rem; display: grid; border: 1px solid var(--c-line); }
.menu button { display: flex; gap: .7rem; align-items: center; min-height: 44px; padding: 0 .8rem; border: 0; background: none; border-radius: 10px; cursor: pointer; font-weight: 600; text-align: left; }
.menu button:hover, .menu button:focus-visible { background: var(--c-surface-2); }
.menu button.danger { color: var(--c-bad); }
.menu hr { border: 0; border-top: 1px solid var(--c-line); margin: .3rem .2rem; }
.menu .menu-h { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--c-muted, #777); padding: .35rem .8rem .1rem; }
.menu .menu-t { flex: 1; }
.menu .menu-hint { color: var(--c-muted, #777); font-weight: 600; font-size: .78rem; }
.menu button svg { width: 18px; height: 18px; flex: none; }
@media (hover: hover) and (pointer: fine) { .menu button { min-height: 36px; } }
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(20, 12, 36, .5); display: grid; place-items: center; padding: 16px; animation: fade .18s; }
.modal { background: var(--c-surface); border-radius: var(--r-xl); width: min(640px, 100%); max-height: calc(100dvh - 32px); overflow: auto; padding: var(--sp-5); box-shadow: 0 30px 80px -20px rgba(0,0,0,.5); animation: pop .22s var(--ease-out); }
.modal-head { display: flex; align-items: center; gap: 1rem; margin-bottom: var(--sp-4); }
.modal-head h2 { flex: 1; font-size: 1.35rem; font-weight: 800; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; margin-top: var(--sp-5); flex-wrap: wrap; }
.toast-wrap { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: .5rem; pointer-events: none; }
.toast { background: var(--c-ink); color: var(--c-bg); padding: .8rem 1.2rem; border-radius: 14px; font-weight: 700; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: pop .2s var(--ease-out); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.94) translateY(6px); } }
.theme-swatches { display: flex; gap: .5rem; flex-wrap: wrap; }
.swatch { width: 40px; height: 40px; border-radius: 12px; border: 3px solid var(--c-surface); box-shadow: 0 0 0 2px var(--c-line); cursor: pointer; padding: 0; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--c-ink); }

/* ---------- Panels ---------- */
.panel { background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--shadow-card); padding: var(--sp-5); }
.panel + .panel { margin-top: var(--sp-4); }
.panel h2 { font-size: 1.15rem; font-weight: 800; margin-bottom: var(--sp-4); }
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--sp-5); align-items: start; }
@media (min-width: 1700px) { .two-col { grid-template-columns: minmax(0, 1fr) 460px; } }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }
.stack { display: grid; gap: var(--sp-4); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }

/* ---------- Editor ---------- */
.kind-tabs { display: inline-flex; background: var(--c-surface-2); border-radius: 999px; padding: 4px; gap: 4px; }
.kind-tabs button { border: 0; background: none; min-height: 42px; padding: 0 1.1em; border-radius: 999px; font-weight: 700; cursor: pointer; color: var(--c-muted); }
.kind-tabs button[aria-pressed="true"] { background: var(--c-surface); color: var(--c-ink); box-shadow: var(--shadow-card); }
.items { display: grid; gap: .75rem; counter-reset: item; }
.item-row { display: grid; grid-template-columns: 36px 64px minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.4fr) 44px; gap: .6rem; align-items: start; background: var(--c-surface-2); border-radius: var(--r); padding: .7rem; }
.item-row.pairs { grid-template-columns: 36px 64px minmax(0, 1fr) minmax(0, 1fr) 44px; }
.item-num { width: 36px; height: 36px; border-radius: 12px; background: var(--c-surface); display: grid; place-items: center; font-weight: 800; color: var(--c-muted); margin-top: 6px; }
.img-slot { width: 64px; height: 48px; border-radius: 12px; border: 2px dashed var(--c-line); background: var(--c-surface) center/cover no-repeat; display: grid; place-items: center; cursor: pointer; color: var(--c-muted); padding: 0; margin-top: 0; position: relative; }
.img-slot.has-img { border-style: solid; }
.img-slot.has-img .icon { opacity: 0; }
.item-row .input { min-height: 46px; }
.item-row .cap { font-size: .72rem; font-weight: 700; color: var(--c-muted); margin: 0 0 .2rem .2rem; display: block; }
.input.is-ok { border-color: color-mix(in srgb, var(--c-ok) 55%, var(--c-line)); }
.wrongs { display: grid; gap: .35rem; }
@media (max-width: 760px) {
  .item-row, .item-row.pairs { grid-template-columns: 36px 1fr 44px; }
  .item-row .img-slot { grid-column: 1; grid-row: 2; width: 36px; height: 36px; }
  .item-row .q-cell, .item-row .a-cell, .item-row .w-cell { grid-column: 2; }
  .item-row .del { grid-column: 3; grid-row: 1; }
}
.editor-foot { position: sticky; bottom: 0; z-index: 5; display: flex; gap: .6rem; justify-content: flex-end; padding: .9rem 0; background: linear-gradient(transparent, var(--c-bg) 35%); flex-wrap: wrap; }

/* ---------- Template picker ---------- */
.tpl-grid { display: grid; gap: var(--sp-5); grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@media (max-width: 520px) { .tpl-grid { grid-template-columns: 1fr 1fr; gap: .75rem; } }
.tpl-card { position: relative; display: flex; flex-direction: column; text-align: left; border: 3px solid transparent; border-radius: var(--r-lg); background: var(--c-surface); box-shadow: var(--shadow-card); padding: 0; cursor: pointer; overflow: hidden; transition: transform .18s var(--ease-out), border-color .15s; }
.tpl-card:hover:not([disabled]) { transform: translateY(-4px); border-color: var(--c-primary); }
.tpl-card[aria-current="true"] { border-color: var(--c-primary); }
.tpl-card[disabled] { cursor: not-allowed; opacity: .55; filter: grayscale(.4); }
.tpl-art { aspect-ratio: 4/3; display: grid; place-items: center; background: var(--c-surface-2); }
.tpl-art svg { width: 80%; height: 80%; }
.tpl-info { padding: .8rem 1rem 1rem; display: grid; gap: .2rem; }
.tpl-info b { font-size: 1.05rem; font-weight: 800; }
.tpl-info small { color: var(--c-muted); line-height: 1.35; }
.tpl-flag { position: absolute; top: 10px; left: 10px; }
.tpl-flag.now { background: var(--c-primary); color: var(--c-primary-ink); }

/* ---------- Share / Assign ---------- */
.mode-cards { display: grid; gap: .75rem; grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .mode-cards { grid-template-columns: 1fr; } }
.mode-card { display: grid; gap: .4rem; text-align: left; padding: 1rem; border-radius: var(--r); border: 3px solid var(--c-line); background: var(--c-surface); cursor: pointer; }
.mode-card .icon { width: 28px; height: 28px; color: var(--c-primary); }
.mode-card b { font-weight: 800; }
.mode-card small { color: var(--c-muted); }
.mode-card[aria-checked="true"] { border-color: var(--c-primary); background: var(--c-primary-soft); }
.link-box { display: flex; gap: .5rem; }
.link-box .input { font-family: ui-monospace, Menlo, monospace; font-size: .9rem; }
.qr-box { display: grid; justify-items: center; gap: .6rem; }
.qr-box canvas { width: 220px; height: 220px; image-rendering: pixelated; border-radius: 16px; background: #fff; padding: 10px; box-shadow: var(--shadow-card); }
.code-big { font-size: clamp(2rem, 1.5rem + 3vw, 4rem); font-weight: 900; letter-spacing: .12em; color: var(--c-primary); text-align: center; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .5rem; border-bottom: 1px solid var(--c-line); text-align: left; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Login ---------- */
.auth-card { max-width: 440px; margin: 6vh auto 0; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
@media (max-width: 760px) {
  .editor-foot { flex-wrap: nowrap; }
  .editor-foot .btn-ghost { display: none; }
  .editor-foot .btn { flex: 1; min-height: 52px; font-size: 1rem; padding: 0 .8em; }
}
/* chống tràn ngang trên điện thoại: trường nhập trong hàng flex */
.field, .link-box > .input { min-width: 0; }
.input { max-width: 100%; }
.stack > * { min-width: 0; }
@media (max-width: 520px) { .act-thumb .play-badge { width: 34px; height: 34px; inset: auto 8px 8px auto; } }

/* ===== Thanh tab nổi ở đáy: điện thoại + máy tính bảng (≤1000px) ===== */
.tabbar { display: none; }
@media all {
  .header-nav { display: none !important; }
  .fab { display: none !important; }
  .tabbar { position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 50; max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); align-items: end; gap: 2px; padding: 8px 8px; border-radius: 28px; background: color-mix(in srgb, var(--c-surface) 88%, transparent); backdrop-filter: blur(18px) saturate(1.4); border: 1px solid var(--c-line); box-shadow: 0 14px 40px -12px rgba(20, 20, 40, .32), 0 2px 8px rgba(20, 20, 40, .08); }
  .tab { appearance: none; background: none; border: 0; font: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; padding: 6px 4px; border-radius: 20px; color: var(--c-muted); text-decoration: none; font-weight: 700; font-size: .72rem; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color .2s, background .2s, transform .15s; }
  .tab .tab-ic svg { width: 24px; height: 24px; display: block; }
  .tab:active { transform: scale(.94); }
  .tab[aria-current="page"] { color: var(--c-primary); background: color-mix(in srgb, var(--c-primary) 12%, transparent); }
  .tab-main { color: inherit; }
  .app-main { padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  body[data-view="play"] .tabbar, body[data-view="print"] .tabbar { display: none; }
  body[data-view="play"] .app-main, body[data-view="print"] .app-main { padding-bottom: 0; }
}

/* ---------- Trợ lý AI (editor) ---------- */
.ai-bar { display: grid; gap: .6rem; padding: .85rem; border-radius: var(--r); background: linear-gradient(135deg, var(--c-accent-soft), var(--c-primary-soft)); border: 1px solid color-mix(in srgb, var(--c-accent) 18%, transparent); }
.ai-bar-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.ai-bar-head b { font-size: 1rem; }
.ai-chip { margin-left: auto; display: inline-flex; align-items: center; gap: .35em; padding: .2em .75em; border-radius: 99px; background: var(--c-surface); font-size: .78rem; font-weight: 700; color: var(--c-muted); min-height: 28px; }
.ai-bar-btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.ai-bar-btns .btn { min-height: 44px; }
.ai-bar-btns .btn-soft { background: var(--c-surface); }
@media (max-width: 600px) { .ai-bar-btns { display: grid; grid-template-columns: 1fr 1fr; } .ai-bar-btns .btn-primary { grid-column: 1 / -1; } .ai-bar-btns .btn { white-space: normal; padding: 0 .7em; font-size: .92rem; } }
.ai-form .ai-tabs { justify-self: start; flex-wrap: wrap; }
.ai-ta { font-family: var(--font); font-size: 1rem; min-height: 120px; }
.ai-opts { display: grid; grid-template-columns: 120px 1fr 150px; gap: .6rem; }
@media (max-width: 520px) { .ai-opts { grid-template-columns: 1fr 1fr; } .ai-opts > :nth-child(2) { grid-column: 1 / -1; grid-row: 1; } }
@media (max-width: 520px) { .ai-opts { grid-template-columns: 1fr; } .ai-opts > :nth-child(n) { grid-column: 1 / -1; grid-row: auto; } .ai-opts select { width: 100%; min-width: 0; text-overflow: ellipsis; } }
@media (max-width: 600px) { .ai-opts select, .tts-local-field select, .rec-box select { min-height: 44px; } .tts-local-keep { display: flex; align-items: center; gap: .5rem; min-height: 44px; } .tts-local-keep input { width: 22px; height: 22px; flex: none; } }
.ai-hint { font-size: .85rem; }
.ai-progress { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-radius: var(--r-sm); background: var(--c-accent-soft); font-weight: 700; }
.ai-spin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid color-mix(in srgb, var(--c-accent) 25%, transparent); border-top-color: var(--c-accent); animation: ai-spin .8s linear infinite; flex: none; display: inline-block; }
@keyframes ai-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .ai-spin { animation-duration: 2.4s; } }
.ai-search { display: flex; gap: .5rem; }
.ai-search .input { flex: 1; min-width: 0; }
.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; max-height: 52dvh; overflow: auto; padding: 2px; }
@media (max-width: 520px) { .ai-grid { grid-template-columns: repeat(2, 1fr); } }
.ai-thumb { position: relative; border: 3px solid transparent; border-radius: 14px; overflow: hidden; padding: 0; cursor: pointer; background: var(--c-surface-2); aspect-ratio: 4/3; transition: border-color .15s, transform .15s var(--ease-out); }
.ai-thumb:hover, .ai-thumb:focus-visible { border-color: var(--c-primary); transform: translateY(-2px); }
.ai-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ai-thumb small { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: .68rem; font-weight: 700; padding: .05em .5em; border-radius: 99px; }
.ai-thumb.is-loading { opacity: .5; cursor: progress; }
.aud-btn { display: inline-grid; place-items: center; width: 26px; height: 26px; margin-left: .4rem; border-radius: 50%; border: 0; background: var(--c-accent); color: #fff; font-size: .62rem; cursor: pointer; vertical-align: middle; padding: 0 0 0 2px; }
.aud-btn:hover { transform: scale(1.1); }
.ai-credits { font-size: .8rem; color: var(--c-muted); }
.ai-credits summary { cursor: pointer; font-weight: 700; }
.ai-credits ol { margin: .4rem 0 0; padding-left: 1.4rem; display: grid; gap: .2rem; word-break: break-word; }

/* ---- âm thanh từng ô (🎤 thu âm / tải file / giọng đọc tự động) — views/audio-tools.js ---- */
.inp-mic { position: relative; }
.inp-mic > .input { padding-right: 2.6rem; }
.mic-btn { position: absolute; right: .3rem; top: 50%; transform: translateY(-50%); width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; font-size: 1rem; line-height: 1; filter: grayscale(1); opacity: .55; }
.mic-btn:hover, .mic-btn:focus-visible { opacity: 1; filter: none; background: var(--c-accent-soft); }
.mic-btn.on { opacity: 1; filter: none; background: var(--c-accent-soft); box-shadow: inset 0 0 0 2px var(--c-accent); }
.aud-ctl { display: inline-flex; gap: .25rem; vertical-align: middle; }
.aud-ctl .aud-btn { margin-left: .25rem; }
.aud-btn.aud-del { background: var(--c-surface); color: var(--c-muted); box-shadow: inset 0 0 0 1px var(--c-line); padding: 0; }
.rec-box { min-width: min(420px, 80vw); }
.rec-head { display: flex; align-items: center; gap: .6rem; }
.rec-clock { font-size: 2rem; font-variant-numeric: tabular-nums; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--c-line); }
.rec-dot.on { background: #e5484d; animation: recPulse 1s infinite; }
@keyframes recPulse { 50% { opacity: .3; } }
.rec-box audio, .modal audio { width: 100%; }
.rec-actions { flex-wrap: wrap; }
.aud-progress { width: 100%; height: 14px; accent-color: var(--c-accent); }
@media (prefers-reduced-motion: reduce) { .rec-dot.on { animation: none; } }

/* ---------- Kết nối AI của tôi (BYOK, web/js/ai/) ---------- */
.ai-btn-src { display: inline-flex; align-items: center; gap: .3rem; flex-wrap: nowrap; flex: 0 1 auto; min-width: 0; }
.ai-btn-src > .btn { white-space: nowrap; flex: 1 1 auto; }
@media (max-width: 600px) { .ai-bar-btns .ai-btn-src { grid-column: 1 / -1; } .ai-bar-btns .ai-btn-src > .btn { white-space: nowrap; } }
.ai-src { min-height: 32px; padding: 0 .65em; border-radius: 99px; border: 1.5px solid var(--c-line); background: var(--c-surface); color: var(--c-muted); font-weight: 700; font-size: .78rem; cursor: pointer; white-space: nowrap; }
.ai-src.is-mine { border-color: var(--c-primary); color: var(--c-ink); background: var(--c-primary-soft); }
.ai-srcs { align-items: center; gap: .4rem; flex-wrap: wrap; }
.ai-mine-link { font-weight: 700; font-size: .85rem; text-decoration: none; margin-left: auto; }
.byok { max-width: 760px; margin: 0 auto; display: grid; gap: var(--sp-4); }
.byok .page-head { margin-bottom: 0; }
.byok-warn { background: var(--c-surface); border: 2px solid var(--c-line); border-left: 6px solid var(--c-accent); border-radius: var(--r); padding: .9rem 1rem; }
.byok-warn ul { margin: .4rem 0 0; padding-left: 1.2rem; display: grid; gap: .2rem; }
.byok-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .4rem; }
.byok-tab { display: grid; gap: .1rem; justify-items: center; padding: .55rem .3rem; border-radius: var(--r); border: 2px solid var(--c-line); background: var(--c-surface); cursor: pointer; min-height: 56px; }
.byok-tab small { color: var(--c-muted); font-size: .7rem; text-align: center; line-height: 1.2; }
.byok-tab[aria-selected="true"] { border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-soft); }
.byok-tab.is-main b { font-size: 1.05rem; }
.byok-card { background: var(--c-surface); border-radius: var(--r); border: 1px solid var(--c-line); padding: 1rem 1.1rem; display: grid; gap: .75rem; }
.byok-card h2 { font-size: 1.15rem; margin: 0; }
.byok-card h3 { font-size: 1rem; margin: .4rem 0 0; }
.byok-card-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.badge-ok { background: var(--c-accent-soft); color: var(--c-ok); }
.byok-cost { margin: 0; }
.byok-get, .byok-btns, .byok-pick { display: flex; gap: .5rem; flex-wrap: wrap; }
.byok-steps ol { margin: .5rem 0 0; padding-left: 1.3rem; display: grid; gap: .3rem; }
.byok-steps summary { cursor: pointer; font-weight: 700; min-height: 36px; display: flex; align-items: center; }
.byok-form { display: grid; gap: .7rem; }
.byok-row { display: flex; gap: .4rem; align-items: center; }
.byok-row .input { flex: 1; min-width: 0; }
.byok-status { margin: 0; font-weight: 600; min-height: 1.5em; }
.byok-status.ok { color: var(--c-ok); }
.byok-status.bad { color: var(--c-bad); }
.byok-unlock { display: grid; gap: .4rem; padding: .7rem; border-radius: var(--r-sm); background: var(--c-surface-2); }
.byok-pick .chip input { margin: 0; accent-color: var(--c-primary); }
.byok-danger { display: flex; justify-content: center; padding-bottom: var(--sp-5); }
@media (max-width: 560px) {
  .byok-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .byok-btns .btn, .byok-get .btn { flex: 1 1 100%; }
}
/* thư mục: tên dài không đẩy nút ra ngoài cột */
.sidebar { min-width: 0; }
.folder-row { min-width: 0; overflow: hidden; }
.folder-row .side-item { overflow: hidden; }
.folder-row .side-item > span:not(.folder-dot):not(.count) { flex: 1; min-width: 0; }
/* hình đại diện thẻ bài = ảnh thật trong bài */
.act-thumb .act-cover { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.act-thumb:has(.act-cover) { background: var(--c-surface-2); }

/* thư mục: chỉ 1 nút ⋯ nhỏ gọn (Đổi tên nằm trong menu) */
.folder-row > .btn-icon { width: 28px; height: 28px; min-width: 28px; padding: 0; flex: none; border: 0; background: transparent; opacity: .55; }
.folder-row > .btn-icon svg { width: 16px; height: 16px; }
.folder-row:hover > .btn-icon, .folder-row > .btn-icon:focus-visible { opacity: 1; }
@media (hover: none) { .folder-row > .btn-icon { opacity: .8; } }
.share-state { gap: .25rem; }
.share-state[data-s="private"] { background: #eee; color: #555; }
.share-state:not([data-s="private"]) { background: #dcf5e4; color: #14663a; }
.share-state svg { width: 14px; height: 14px; }

/* Nút nói để nhập (dictate.js) */
.dict-wrap { display: flex; gap: .35rem; align-items: center; width: 100%; }
.dict-wrap.ta { align-items: flex-start; }
.dict-wrap > .input, .dict-wrap > .textarea { flex: 1; min-width: 0; }
.dict-btn { flex: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; border: 1px solid var(--c-line, #d8dee6); background: #fff; display: inline-grid; place-items: center; cursor: pointer; }
.dict-btn .qk-mic-label { display: none; }
.dict-btn[data-state="listen"] { background: #e5484d; color: #fff; animation: dictp 1s infinite; }
.dict-btn[data-state="work"] { opacity: .6; }
.dict-btn.in-row { position: absolute; right: 2.5rem; top: 50%; transform: translateY(-50%); width: 30px; height: 30px; border: 0; background: transparent; }
.inp-mic:has(> .dict-btn) > .input { padding-right: 5.2rem; }
@keyframes dictp { 50% { box-shadow: 0 0 0 6px rgba(229,72,77,.25); } }

/* Nút nói-để-nhập: ghi đè kiểu nút micro lớn của Soạn nhanh */
.dict-btn.qk-mic { width: 40px; height: 40px; aspect-ratio: auto; gap: 0; background: #fff; color: var(--c-ink, #1b2430); box-shadow: none; align-content: center; justify-items: center; }
.dict-btn.qk-mic .icon { width: 20px; height: 20px; }
.dict-btn.qk-mic[data-state="listen"] { background: #e5484d; color: #fff; }
.dict-btn.in-row.qk-mic { width: 30px; height: 30px; background: transparent; }

/* Gọn lại phần đầu trang soạn bài trên điện thoại */
.ai-bar-head .ai-mine-link { font-size: .85rem; font-weight: 700; margin-left: auto; }
.ai-btn-src { display: flex; gap: .4rem; align-items: stretch; }
.ai-btn-src > .btn { flex: 1; }
@media (max-width: 600px) {
  .ed-tools { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; align-items: center; }
  .ed-tools > .kind-tabs { grid-column: 1 / -1; }
  .ed-tools > div[style] { display: none; }
  .ed-tools > .muted { grid-column: 1 / -1; font-size: .85rem; }
  .ed-tools > .btn { width: 100%; justify-content: center; }
  .ai-bar-btns { display: grid; grid-template-columns: 1fr; gap: .5rem; }
  .ai-bar-btns .btn-primary { grid-column: auto; }
  .ai-bar-btns > .btn { width: 100%; }
  .ai-bar-head { gap: .4rem; }
  .ai-bar-head .ai-mine-link { flex-basis: 100%; margin-left: 0; text-align: left; }
}

/* Vùng chạm ≥44px (kiểm tra UI/UX 02/11) */
.dict-btn.qk-mic { width: 44px; height: 44px; }
.dict-btn.in-row.qk-mic { width: 36px; height: 36px; right: 2.6rem; }
.item-row .mic-btn { min-width: 40px; min-height: 40px; }
@media (max-width: 760px) {
  .ed-tools > .btn, .ai-bar-btns .btn, .ai-btn-src > .btn, .ai-src, .item-row .btn-icon { min-height: 44px; }
  .item-row .btn-icon.del { min-width: 44px; }
}
@media (max-width: 760px) {
  body:not([data-view="play"]) .ed-tools > .btn, body:not([data-view="play"]) .ai-bar-btns .btn, body:not([data-view="play"]) .item-row .btn-icon,
  body:not([data-view="play"]) .editor-foot .btn { min-height: 44px; }
}

/* Bảng AI trên máy (models-panel.js) */
.models-panel { display: grid; gap: .4rem; justify-items: start; padding: .9rem 1rem; border: 1px solid var(--c-line); border-radius: var(--r); background: var(--c-surface); font-size: .92rem; }

/* Mobile: nút/ô nhập ở #/ai và #/storage đủ 44px (admin.css đang ép --tap 32px) */
@media (max-width: 600px) {
  body:not([data-view="play"]) .byok .btn, body:not([data-view="play"]) .byok input.input:not([type=checkbox]):not([type=radio]), body:not([data-view="play"]) .byok .input, body:not([data-view="play"]) .stack:has(.stk-kpis) .btn, body:not([data-view="play"]) .stack:has(.stk-kpis) .input, body:not([data-view="play"]) .stack:has(.stk-kpis) select { min-height: 44px; }
  body:not([data-view="play"]) .byok .btn-icon { width: 44px; min-width: 44px; }
  body:not([data-view="play"]) .stack:has(.stk-kpis) th button { min-height: 44px; }
}

/* ===== Thư mục dạng thẻ + bộ lọc (02/11) ===== */
.home-filter { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: var(--sp-3, .75rem) 0; }
.home-sort { width: auto; min-width: 9.5rem; margin-left: auto; min-height: 44px; }
.home-filter .chip { min-height: 44px; }
.folder-card { --fc: #2563eb; position: relative; display: flex; flex-direction: column; background: var(--c-surface, #fff); border: 1px solid var(--c-border, #e5e7eb); border-radius: 18px; overflow: hidden; cursor: pointer; transition: transform .15s, box-shadow .15s; text-align: left; min-width: 0; }
.folder-card:hover, .folder-card:focus-visible { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(15, 23, 42, .12); outline: none; }
.folder-card:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--fc) 50%, transparent); }
.folder-card-art { position: relative; height: 92px; display: grid; place-items: center; overflow: hidden;
  background: radial-gradient(circle at 12% 120%, rgba(255,255,255,.35) 0 38px, transparent 39px), radial-gradient(circle at 92% -10%, rgba(255,255,255,.3) 0 52px, transparent 53px), linear-gradient(135deg, var(--fc), color-mix(in srgb, var(--fc) 62%, #000)); }
.folder-card-emoji { font-size: 2.6rem; line-height: 1; filter: drop-shadow(0 3px 5px rgba(0,0,0,.25)); }
.folder-card-more { position: absolute; top: 6px; right: 6px; width: 44px; height: 44px; background: rgba(255,255,255,.88); color: #0f172a; border: 0; border-radius: 12px; }
.folder-card-body { display: flex; flex-direction: column; gap: .35rem; padding: .85rem 1rem 1rem; min-width: 0; }
.folder-card-name { font-size: 1.05rem; overflow-wrap: anywhere; }
.folder-card-meta { font-size: .85rem; }
.folder-card-bar { height: 6px; border-radius: 6px; background: color-mix(in srgb, var(--fc) 14%, #e5e7eb); overflow: hidden; }
.folder-card-bar i { display: block; height: 100%; background: #22a559; border-radius: 6px; }
.folder-card-badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .15rem; }
.fs-grid { display: flex; flex-wrap: wrap; gap: .5rem; margin: .4rem 0 1rem; }
.fs-sw { width: 44px; height: 44px; border-radius: 12px; border: 3px solid transparent; cursor: pointer; }
.fs-sw[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 3px #0f172a; }
.fs-em { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--c-border, #e5e7eb); background: var(--c-surface, #fff); font-size: 1.4rem; cursor: pointer; }
.fs-em[aria-pressed="true"] { border-color: #2563eb; background: #eff6ff; }
.folder-dot { display: inline-grid; place-items: center; font-size: 9px; }
@media (max-width: 480px) { .home-sort { margin-left: 0; width: 100%; } .folder-card-art { height: 76px; } }
/* admin.css thu .chip/.input xuống 30–36px: ép lại 44px cho thanh lọc thư mục (cổng UI mobile) */
body:not([data-view="play"]) .home-filter .chip, body:not([data-view="play"]) .home-sort { min-height: 44px; }
body:not([data-view="play"]) select.home-sort, body:not([data-view="play"]) .input.home-sort { min-height: 44px; }

/* Đăng nhập gọn: nút phụ thành hàng chip nhỏ, đăng ký là liên kết chữ */
.auth-link { background:none; border:0; color:var(--primary,#1a63d8); font:inherit; font-weight:700; min-height:44px; cursor:pointer; text-align:center; width:100%; }
.auth-alt { display:flex; flex-wrap:wrap; gap:8px; justify-content:center; padding-top:4px; border-top:1px solid rgba(0,0,0,.08); margin-top:4px; }
.auth-alt .btn { flex:0 0 auto; min-height:44px; padding:0 14px; font-size:.9rem; }

@media (max-width: 430px) {
  .app-header { gap: 6px; }
  .app-header .brand-logo { width: 132px; height: auto; }
  .header-actions { gap: 2px; }
}

.home-filter .chip-link{display:inline-flex;align-items:center;text-decoration:none;color:inherit}
@media (max-width:430px){.tabbar.cl-tabs .tab{padding:6px 1px;font-size:.62rem}}

/* Nút VI/EN ở header (js/i18n.js): chừa chỗ trên điện thoại để không tràn ngang */
@media (max-width: 520px) { .app-header { gap: 8px; } }
@media (max-width: 430px) {
  .app-header { padding: 0 10px; }
  .app-header .header-spacer { display: none; }
  .app-header .header-actions { gap: 0; margin-left: auto; }
  body:not([data-view="play"]) .app-header .brand-logo { max-height: 28px; width: auto; }
}

/* Nút header trên điện thoại: 40px + vùng bấm mở rộng tới 44px (vừa khít 360px, không tràn) */
@media (max-width: 760px) {
  .app-header .btn-icon, .app-header .hvm-b { width: 40px !important; height: 40px !important; min-width: 40px !important; min-height: 40px !important; position: relative; }
  .app-header .btn-icon::after, .app-header .hvm-b::after { content: ''; position: absolute; inset: -2px; }
  body:not([data-view="play"]) .app-header .brand-logo { max-height: 26px; }
}
@media (max-width: 380px) {
  .app-header { gap: 4px; padding: 0 6px; }
  .app-header .brand-logo { max-width: 84px !important; width: auto; }
  .app-header .brand { min-width: 0; flex: 0 1 auto; }
}
/* Thanh tab dưới (fixed) không che phần cuối trang */
@media (max-width: 760px) {
  body:not([data-view="play"]):has(.tabbar) { padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important; }
}
