/* Thành phần dùng chung: nút, thẻ, chip, Jyutping, ô từ */

/* ---------- generic UI ---------- */
/* biểu tượng SVG nét viền (Y.icon): cùng cỡ chữ, màu theo chữ */
.ic { width: 1.15em; height: 1.15em; flex: 0 0 auto; vertical-align: -.2em; }
.btn .ic, .tab .ic, .chip .ic { vertical-align: 0; }
.chip .ic { width: 1.05em; height: 1.05em; }
/* ô màu chú thích điểm phát âm */
.sq { display: inline-block; width: .8em; height: .8em; border-radius: 2px; vertical-align: -.05em; }
.sq.ok { background: var(--ok); } .sq.tone { background: var(--warn); } .sq.miss { background: var(--bad); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 14px; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 15px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 600;
  font-size: .92rem; line-height: 1.2; text-decoration: none !important; transition: transform .06s, background .15s, box-shadow .15s;
  min-height: 40px;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
/* nút chính kiểu in: nền đặc, viền mực 2px, bóng đặc lệch; khi bấm thì "ấn" xuống, mất bóng */
.btn.primary { background: var(--minibus-red); border: 2px solid var(--ink-line); color: var(--on-accent, #fff8ec); box-shadow: var(--print-shadow); font-weight: 700; }
.btn.primary:hover { background: var(--accent-hover, #e8323a); }
.btn.cyan { background: var(--minibus-green); border: 2px solid var(--ink-line); color: var(--on-accent, #f2fff8); box-shadow: var(--print-shadow); font-weight: 700; }
.btn.primary:active, .btn.cyan:active { transform: translate(2px, 2px); box-shadow: none; }
.btn.sm.primary, .btn.sm.cyan { box-shadow: 2px 2px 0 var(--ink-line); }
.btn.cyan:hover { background: var(--alt-hover, #009e66); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; min-height: 34px; font-size: .84rem; border-radius: 8px; }
.btn.icon { width: 40px; padding: 0; }
.btn.sm.icon { width: 34px; }
.btn.rec { color: var(--bad); }
.btn.rec.on { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 90, 90, .25); } }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; background: var(--surface-3); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip.pink { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chip.cyan { color: var(--accent-2); border-color: color-mix(in srgb, var(--accent-2) 45%, transparent); background: color-mix(in srgb, var(--accent-2) 9%, transparent); }
.chip.yellow { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 45%, transparent); background: color-mix(in srgb, var(--gold) 9%, transparent); }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 9%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 9%, transparent); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tab { padding: 7px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; font-weight: 600; font-size: .86rem; color: var(--muted); text-decoration: none !important; }
.tab.active { background: var(--tram-green); color: var(--on-accent, #fff); border-color: transparent; }
input[type=text], input[type=search], input[type=number], input[type=url], input[type=email], input[type=password], textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text); border: 1px solid var(--field, var(--border)); border-radius: 10px;
  padding: 10px 12px; font: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
label.field { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--minibus-green); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.switch:last-child { border-bottom: 0; }
.switch input[type=checkbox] { width: 20px; height: 20px; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.notice { border-radius: 12px; padding: 12px 14px; background: color-mix(in srgb, var(--warn) 10%, transparent); border: 1px solid color-mix(in srgb, var(--warn) 38%, transparent); font-size: .9rem; }
.notice.info { background: color-mix(in srgb, var(--accent-2) 8%, transparent); border-color: color-mix(in srgb, var(--accent-2) 32%, transparent); }
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--minibus-red), var(--sign-gold)); border-radius: 99px; transition: width .4s; }
.kpi { font-family: var(--font-led); font-size: 2rem; line-height: 1; color: var(--led-on); }
:root[data-theme="light"] .kpi { color: var(--accent); text-shadow: none; }
.kpi-card { background: #0b0b0d; border-color: #222; }
:root[data-theme="light"] .kpi-card { background: var(--surface); border-color: var(--border); }
.kpi-card small { color: #b9b29e; }
:root[data-theme="light"] .kpi-card small { color: var(--muted); }

/* ---------- Jyutping / thanh điệu ---------- */
/* trên nút màu, Jyutping theo màu chữ của nút (màu thanh điệu không đọc được trên nền màu) */
.btn.primary .jp span, .btn.cyan .jp span, .tab.active .jp span, .unit-head .badge .jp span, .station .jp span, .film-chip .jp span { color: inherit !important; }
.jp { font-family: var(--font); font-weight: 600; letter-spacing: .01em; }
.jp sup { font-size: .68em; margin-left: 1px; font-weight: 800; }
.toned .t1 { color: var(--t1); } .toned .t2 { color: var(--t2); } .toned .t3 { color: var(--t3); }
.toned .t4 { color: var(--t4); } .toned .t5 { color: var(--t5); } .toned .t6 { color: var(--t6); }
ruby { ruby-align: center; }
ruby rt { font-family: var(--font); font-size: .5em; font-weight: 700; letter-spacing: 0; padding-bottom: 1px; line-height: 1.1; }
.ruby-under ruby { ruby-position: under; -webkit-ruby-position: after; }
ruby.blank { color: var(--accent); font-weight: 800; }
.line-zh { font-family: var(--font-zh); font-weight: var(--zh-weight, 400); font-size: 1.55rem; line-height: 2.35; word-break: keep-all; overflow-wrap: anywhere; }
.line-zh.lg { font-size: 1.9rem; }
.line-zh.sm { font-size: 1.25rem; line-height: 2.2; }
.line-zh rt sup { font-size: .8em; }
.vi { color: var(--muted); font-style: italic; }
.hide-jp rt { visibility: hidden; }
/* chữ Hán + Jyutping bên cạnh (trong câu tiếng Việt, tên phim, đáp án…) */
.zi { white-space: normal; }
.zi .zc { font-family: var(--font-zh); }
.zi .zj { font-size: .8em; white-space: nowrap; opacity: .95; }
.zi .zj.long { white-space: normal; } /* Jyutping cả câu (từ 5 âm tiết) được xuống dòng giữa các âm tiết, không tràn màn hình điện thoại */
.zi .zj .jp { font-weight: 600; }

/* ---------- Ô từ (giống bảng Excel của bạn) ---------- */
.tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.tile {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 64px;
  padding: 6px 10px 5px; border-radius: 6px; background: var(--tile-bg); color: var(--tile-ink); cursor: pointer; border: 0;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .3); transition: transform .08s; position: relative;
}
.tile:hover { transform: translateY(-2px); }
.tile .z { font-family: var(--font-zh-serif); font-size: 1.45rem; line-height: 1.25; letter-spacing: .25em; margin-right: -.25em; }
.tile .z.lat { letter-spacing: 0; margin-right: 0; font-family: var(--font); font-weight: 600; }
.tile .j { font-size: .86rem; line-height: 1.2; white-space: nowrap; }
.tile .m { font-size: .7rem; color: #5b5f69; max-width: 140px; text-align: center; line-height: 1.2; margin-top: 2px; }
.tile.core { background: var(--taxi-red); color: #fff; } .tile.core .m { color: rgba(255, 255, 255, .88); }
.tile.s { background: #fff3cf; }
.tile .z, .tile .j { pointer-events: none; }
.tile.known::after { content: '✓'; position: absolute; top: 2px; right: 5px; font-size: .7rem; color: var(--minibus-green); font-weight: 800; }
.tile.core.known::after { color: #fff; }
.tile.toned .t1 { color: #d22b2b; } .tile.toned .t2 { color: #c46400; } .tile.toned .t3 { color: #12904a; }
.tile.toned .t4 { color: #1b78c8; } .tile.toned .t5 { color: #7a48d6; } .tile.toned .t6 { color: #56627a; }
.tile.core.toned .jp span { color: #fff !important; }
.pos-row { display: grid; grid-template-columns: 78px 1fr; gap: 10px; padding: 12px 0; border-top: 1px dashed var(--border); }
.pos-label { font-family: var(--font-zh-serif); color: var(--gold); font-weight: 900; font-size: 1.2rem; padding-top: 6px; }
.pos-label small { display: block; font-family: var(--font); font-size: .7rem; color: var(--muted); font-weight: 500; }
@media (max-width: 560px) { .pos-row { grid-template-columns: 1fr; gap: 6px; } .pos-label { padding-top: 0; } .pos-label small { display: inline; margin-left: 6px; } }
.rels { display: flex; flex-wrap: wrap; gap: 8px; }
.rel { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); flex-wrap: wrap; }
.rel .op { font-family: var(--font); font-weight: 800; color: var(--gold); }
.rel .op.opp { color: var(--accent); } .rel .op.eq { color: var(--accent-2); }

/* ---------- cách viết chữ (Hanzi Writer) trong thẻ từ ---------- */
.strokes, .fold { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0 14px; }
.strokes summary, .fold summary { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-weight: 700; list-style: none; }
.strokes summary::-webkit-details-marker, .fold summary::-webkit-details-marker { display: none; }
.strokes[open], .fold[open] { padding-bottom: 14px; }

/* ---------- gợi ý theo tiếng mẹ đẻ (App.l1Hint): chip nhỏ, chạm mới mở ---------- */
.l1-hint { margin-top: 10px; }
.l1-hint summary { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px; border-radius: 999px; cursor: pointer; list-style: none;
  font-size: .9rem; font-weight: 700; color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 10%, transparent); border: 1px dashed color-mix(in srgb, var(--accent-2) 45%, transparent); }
.l1-hint summary::-webkit-details-marker { display: none; }
.l1-hint[open] summary { border-style: solid; }
.l1-hint .l1-body { margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.l1-hint .l1-body p { margin: 0; }
.l1-hint .l1-body p + p { margin-top: 6px; }
.l1-hint .l1-trap { color: var(--muted); }
/* bảng có cột gợi ý: cột ẩn tới khi bấm nút "Giống tiếng Việt?" */
.l1-tbl .l1-col { display: none; }
.l1-tbl.show-l1 .l1-col { display: table-cell; }
.l1-tbl .l1-col .l1-trap { display: block; margin-top: 4px; }
.l1-tg { gap: 6px; }
.l1-tg.on { color: var(--accent-2); border-color: var(--accent-2); }
.stroke-grid { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.stroke-cell { position: relative; border: 1px solid var(--border); border-radius: 8px; background-color: var(--surface-2);
  /* ô chữ điền (田字格): hai đường giữa nét đứt */
  background-image: linear-gradient(var(--border), var(--border)), linear-gradient(90deg, var(--border), var(--border));
  background-size: 100% 1px, 1px 100%; background-position: center; background-repeat: no-repeat; touch-action: none; }
.stroke-cell.active { outline: 3px solid var(--accent); outline-offset: 2px; }
.stroke-cell.no-data { display: grid; place-items: center; align-content: center; gap: 2px; background-image: none; }
.stroke-cell.no-data .z { font-family: var(--font-zh); font-size: 2.6rem; line-height: 1; }
.stroke-cell.no-data small { font-size: .7rem; color: var(--muted); }

/* ---------- đo thanh điệu bằng micro (pitchy) ---------- */
.tm-meter { display: grid; gap: 8px; }
.tm-target { font-size: .9rem; }
.tm-canvas { width: 100%; height: 150px; display: block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.tm-out { font-size: .88rem; line-height: 1.55; }
.tm-syl { display: inline-block; margin: 2px 6px 2px 0; padding: 1px 8px; border-radius: 8px; border: 1px solid var(--border); }
.tm-syl.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.tm-syl.no { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.ex-btn.on { outline: 3px solid var(--accent); outline-offset: 1px; }

/* ---------- thẻ kết quả chấm phát âm kiểu ELSA ---------- */
.ps-card { display: grid; gap: 12px; }
.ps-head { display: flex; gap: 14px; align-items: center; }
.ps-score { flex: 0 0 auto; width: 74px; height: 74px; border-radius: 50%; display: grid; place-items: center; align-content: center; border: 4px solid currentColor; line-height: 1; }
.ps-score b { font-size: 1.7rem; font-variant-numeric: tabular-nums; }
.ps-score small { font-size: .7rem; color: var(--muted); }
.ps-score.ok { color: var(--ok); } .ps-score.mid { color: var(--warn); } .ps-score.low { color: var(--bad); }
.ps-break { font-size: .85rem; margin-top: 2px; }
.ps-heard { font-size: .82rem; overflow-wrap: anywhere; }
.ps-tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.ps-tile { display: grid; justify-items: center; gap: 2px; min-width: 62px; padding: 8px 8px 6px; border-radius: 10px; border: 2px solid var(--border); background: var(--surface-2); color: var(--text); cursor: pointer; font: inherit; }
.ps-tile .z { font-family: var(--font-zh); font-size: 1.5rem; line-height: 1.1; }
.ps-tile small { font-size: .7rem; color: var(--muted); }
.ps-tile.ok { border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.ps-tile.tone, .ps-tile.part { border-color: color-mix(in srgb, var(--warn) 60%, transparent); }
.ps-tile.miss { border-color: color-mix(in srgb, var(--bad) 55%, transparent); border-style: dashed; }
.ps-jp { font-weight: 700; font-size: .95rem; letter-spacing: .01em; }
.ps-jp .ok, .ps-legend .ok { color: var(--ok); }
.ps-jp .bad, .ps-legend .bad { color: var(--bad); text-decoration: underline wavy color-mix(in srgb, var(--bad) 60%, transparent); text-underline-offset: 3px; }
.ps-tips { margin: 0; padding-left: 20px; display: grid; gap: 8px; font-size: .9rem; line-height: 1.5; }
.ps-tips .ps-k { display: block; font-weight: 700; }
.ps-tips .btn { margin-top: 4px; }
.ps-perfect { margin: 0; color: var(--ok); font-weight: 700; }
.ps-legend { font-size: .78rem; line-height: 1.5; }

/* App.tidy: đoạn dài chỉ hiện vài dòng, mờ dần ở cuối, nút "Xem thêm" để mở */
.clamp { overflow: hidden; -webkit-mask-image: linear-gradient(to bottom, #000 58%, transparent); mask-image: linear-gradient(to bottom, #000 58%, transparent); }
.plate-sub.clamp { max-height: 3.05em; }
.notice.clamp { max-height: calc(3.15em + 26px); }
.fold.clamp { max-height: 10.5em; }
.clamp-more { display: inline-flex; align-items: center; gap: 4px; margin: 2px 0 10px; padding: 2px 0; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: .82rem; font-weight: 700; color: var(--accent-2); }
.clamp-more::after { content: ''; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-2px); }
.clamp-more[aria-expanded="true"]::after { transform: rotate(-135deg) translateY(-1px); }
.station .clamp-more { color: inherit; opacity: .9; margin: 4px 0 0; }
.fold.clamp + .clamp-more { margin-top: -4px; }

/* ô chọn bảng màu nhỏ lại: chỉ còn hình xem trước và tên */
.theme-pick { grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)) !important; gap: 8px !important; }
.theme-pick .tp-name small { display: none; }
.theme-pick .tp-art { height: 58px; padding: 8px; }
.theme-pick .tp-art .ln.a { bottom: 20px; } .theme-pick .tp-art .ln.b { bottom: 12px; } .theme-pick .tp-art .bt { bottom: 10px; }
.theme-pick .tp-name { padding: 6px 8px 7px; }
@media (max-width: 560px) { .theme-pick { grid-template-columns: repeat(3, 1fr) !important; } .theme-pick .tp-art .pl { font-size: .8rem; padding: 2px 6px; } .theme-pick .tp-name b { font-size: .8rem; } }

/* ---------- từ ghép bấm được trong câu (Y.rubySeg) & bảng từ ở #/tools ---------- */
.seg-w { display: inline; padding: 0 1px; border-radius: 4px; border-bottom: 1.5px dashed transparent; cursor: pointer; transition: background-color .15s, border-color .15s; }
.seg-w.multi { margin: 0 1.5px; border-bottom-color: color-mix(in srgb, var(--muted) 38%, transparent); }
.seg-w:hover { background: color-mix(in srgb, var(--accent-2) 14%, transparent); border-bottom-color: var(--accent); }
.tool-samples { gap: 6px; margin-top: 8px; }
.tool-samples .chip { cursor: pointer; background: var(--surface-2); }
.tool-samples .chip:hover { border-color: var(--accent-2); color: var(--text); }
.tool-words { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 8px; }
.tw-item { display: flex; align-items: stretch; gap: 6px; min-width: 0; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.tw-item:hover { border-color: var(--accent-2); }
.tw-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; text-align: left; background: none; border: 0; padding: 0; color: var(--text); font: inherit; cursor: pointer; }
.tw-top { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tw-main .z { font-family: var(--font-zh-serif); font-size: 1.35rem; line-height: 1.2; }
.tw-main .m { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }
.tw-main .hv { font-size: .75rem; color: var(--muted); font-style: italic; }
.tw-srs { align-self: center; min-width: 36px; min-height: 36px; padding: 0 8px; flex: 0 0 auto; }
.tw-srs.is-in { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--border)); }
