/* xBOOK | TUT — Color Contrast 2.1 (CC-002 r05 canvas-first studio + CC-003).
   Self-hosted assets only (no CDN). One token set → components. App chrome colours are independent of
   the user's sample colours, which appear only inside the preview / swatches / matrix cells.
   Accent hues follow the TUT palette from the TUT Brand skill supplied by Anh JAI (not yet checked
   against the official TUTBRAND guideline); darkened where text must stay readable. */
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 400; font-display: swap; src: url('../fonts/Inter-Regular.subset.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 600; font-display: swap; src: url('../fonts/Inter-SemiBold.subset.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-style: normal; font-weight: 700; font-display: swap; src: url('../fonts/Inter-Bold.subset.woff2') format('woff2'); }

:root {
  /* colour tokens */
  --ink: #14181F; --ink-2: #374151; --muted: #4B5563; --line: #E2E5EA; --line-2: #C8CDD5;
  --surface: #FFFFFF; --surface-2: #F6F7F9; --surface-3: #EEF1F4; --page: #FBFBFC;
  --accent: #0B6E78; --accent-ink: #FFFFFF; --accent-soft: #E3F4F4; --accent-line: #8FD3D4;
  --sel: #0B6E78; --focus: #2457C5;
  --ok: #166534; --ok-bg: #EAF7EE; --mid: #8A4B0B; --mid-bg: #FFF5E5; --bad: #B42318; --bad-bg: #FDEEEC;
  --teal: #39BCBD; --azure: #00A8E1; --blue: #427CBF; --olive: #B0BE36; --yellow: #F6B128; --orange: #F68626; --red: #F1562F;
  --fg: #1F2937; --bg: #FFFFFF;
  /* type, space, radius */
  --font: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .9375rem; --fs-lg: 1.0625rem; --fs-xl: 1.25rem;
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
  --gap: clamp(12px, 1.4vw, 20px);
  --gutter: clamp(16px, 2.6vw, 40px);
  --ctl: 40px;
  color-scheme: light;
}
@media (pointer: coarse), (max-width: 760px) {
  :root { --ctl: 44px; }
  html .seg-tabs [role="tab"] { min-height: var(--ctl); }
  html .select-quiet, html .scene-pick [role="radio"] { min-height: var(--ctl); }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-md); line-height: 1.55; color: var(--ink); background: var(--page); }
.wrap { max-width: 1680px; margin: 0 auto; padding: 0 var(--gutter); }
a { color: #1D4ED8; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: var(--r-sm); z-index: 100; }
.skip-link:focus { top: 8px; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.mono { font-family: var(--mono); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.ic { flex: none; }

/* ---------- Buttons & inputs ---------- */
.btn { font: inherit; font-size: var(--fs-md); font-weight: 600; min-height: var(--ctl); padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); border-color: #9AA3AF; }
.btn:active { background: var(--surface-3); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #095A62; border-color: #095A62; }
.btn-accent { background: var(--accent-soft); border-color: var(--accent-line); color: #08525A; }
.btn-accent:hover { background: #D2EEEE; border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; }
.btn-icon { width: var(--ctl); padding: 0; }
.btn-small { min-height: 32px; padding: 0 10px; font-size: var(--fs-sm); }
.link-btn { font: inherit; font-weight: 600; background: none; border: 0; padding: 4px 0; color: #1D4ED8; text-decoration: underline; cursor: pointer; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.status { font-size: var(--fs-sm); color: var(--muted); min-height: 1.3em; display: block; }
.field-label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; color: var(--ink-2); }
input[type="text"], input[type="number"], select, textarea { font: inherit; font-size: var(--fs-md); color: var(--ink); background: var(--surface); border: 1px solid #8B94A1; border-radius: var(--r-sm); padding: 0 10px; min-height: var(--ctl); }
textarea { width: 100%; padding: 10px; }
input:hover, select:hover { border-color: var(--ink-2); }
.input-quiet { border-color: transparent; background: transparent; font-weight: 600; }
.input-quiet:hover { border-color: var(--line-2); }
.input-quiet:focus { background: var(--surface); border-color: var(--ink-2); }
.select-quiet { min-height: 34px; border-color: var(--line-2); font-size: var(--fs-sm); }
.error { font-size: var(--fs-sm); color: var(--bad); font-weight: 600; margin: 6px 0 0; }
.error::before { content: '✗ '; }
input[aria-invalid="true"] { border-color: var(--bad); }
fieldset { border: 0; padding: 0; margin: 0 0 12px; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; font-size: var(--fs-sm); color: var(--ink-2); }
label > input[type="radio"], label > input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); flex: none; margin: 0; }
fieldset label, .check { display: inline-flex; gap: 8px; align-items: center; min-height: 32px; margin-right: 14px; }
input[type="range"] { accent-color: var(--accent); min-height: 28px; }
.note { background: var(--mid-bg); color: #6B3A06; border-radius: var(--r-sm); padding: 8px 10px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wb-title { font-size: var(--fs-lg); font-weight: 700; margin: 0; }

/* segmented tabs / radios (pill only where semantic) */
.seg-tabs { display: inline-flex; gap: 2px; background: var(--surface-3); padding: 3px; border-radius: 999px; max-width: 100%; overflow-x: auto; }
.seg-tabs [role="tab"] { font: inherit; font-size: var(--fs-md); font-weight: 600; display: inline-flex; gap: 8px; align-items: center; border: 0; background: transparent; padding: 0 16px; border-radius: 999px; min-height: calc(var(--ctl) - 6px); cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.seg-tabs [role="tab"]:hover { color: var(--ink); }
.seg-tabs [role="tab"][aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(17,24,39,.16); }
.seg-tabs [role="tab"][aria-selected="true"] .ic { color: var(--accent); }
.seg { display: flex; flex-wrap: wrap; align-items: center; }
.seg legend { width: 100%; }

/* ---------- App bar ---------- */
.appbar { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.appbar-inner { display: flex; align-items: center; gap: 8px 16px; min-height: 60px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.tool-name { font-weight: 600; }
.brand-sep { color: var(--muted); }
.appbar-project { flex: 1 1 180px; min-width: 140px; max-width: 360px; }
.appbar-project input { width: 100%; }
.appbar-actions { display: flex; align-items: center; gap: 4px 6px; flex-wrap: wrap; margin-left: auto; }
.history { display: inline-flex; gap: 2px; }
.lang-nav ul { display: flex; gap: 2px; list-style: none; margin: 0; padding: 3px; background: var(--surface-3); border-radius: 999px; }
.lang-nav a { display: inline-grid; place-items: center; min-width: 38px; min-height: 32px; padding: 0 8px; border-radius: 999px; text-decoration: none; color: var(--ink-2); font-weight: 600; font-size: var(--fs-sm); }
.lang-nav a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(17,24,39,.16); }
#learn-open[aria-expanded="true"] { background: var(--accent-soft); color: #08525A; }

/* ---------- Page ---------- */
main { padding: 16px 0 40px; min-width: 0; }
main:focus { outline: none; }
.wrap { container-type: inline-size; }
.intro { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; margin: 4px 0 14px; }
.intro h1 { font-size: clamp(1.4rem, 1.05rem + 1vw, 1.9rem); letter-spacing: -.01em; margin: 0; }
.intro p { margin: 0; color: var(--ink-2); }
.moderow { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.scene-pick { display: inline-flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.scene-label { font-size: var(--fs-sm); color: var(--muted); margin-right: 6px; font-weight: 600; }
.scene-pick [role="radio"] { font: inherit; font-size: var(--fs-sm); font-weight: 600; min-height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); cursor: pointer; }
.scene-pick [role="radio"][aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.view { min-width: 0; }

/* ---------- Canvas (user colours only inside .preview) ---------- */
.canvas { margin-bottom: var(--gap); }
.preview { --pv-card: #fff; --pv-heading: #1F2937; --pv-body: #1F2937; --pv-btn: #427CBF; --pv-btn-text: #fff; --pv-icon: #F68626;
  --pa-1: #1F2937; --pa-2: #FFFFFF; --pa-3: #39BCBD; --pa-4: #F68626; --pa-5: #427CBF;
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr); min-height: clamp(300px, 42vh, 520px);
  background: var(--pv-card); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.pv-card { padding: clamp(32px, 5vw, 72px) clamp(20px, 6vw, 88px); display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 22px; min-width: 0; width: 100%; max-width: 1040px; margin: 0 auto; }
.pv-accent { display: none; }
.preview[data-scene="brand"] { grid-template-columns: minmax(0, 1fr) clamp(96px, 22%, 300px); }
.preview[data-scene="brand"] .pv-accent { display: grid; grid-template-rows: 3fr 1fr 2fr 1fr; order: 2; }
.pv-accent span:nth-child(1) { background: var(--pa-3); }
.pv-accent span:nth-child(2) { background: var(--pa-4); }
.pv-accent span:nth-child(3) { background: var(--pa-5); }
.pv-accent span:nth-child(4) { background: var(--pa-1); }
.preview[data-scene="text"] .pv-card { max-width: 1120px; }
.preview[data-scene="brand"] .pv-card { margin: 0; }
.pv-el { font: inherit; color: inherit; background: transparent; border: 0; padding: 6px 8px; margin: -6px -8px; text-align: left; cursor: pointer; border-radius: 10px; position: relative; overflow-wrap: anywhere; max-width: 100%; transition: opacity .15s, box-shadow .15s; }
.pv-el:hover { box-shadow: 0 0 0 1px rgba(127,127,127,.55); }
.pv-el[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--sel); }
.pv-el[aria-pressed="true"]::before { content: attr(data-label); position: absolute; right: 0; top: -21px; font: 600 11px/1 var(--font); color: #fff; background: var(--sel); padding: 4px 7px; border-radius: 4px; white-space: nowrap; pointer-events: none; }
.pv-el:focus-visible { outline: 3px dashed var(--focus); outline-offset: 5px; }
.preview[data-dim="on"] .pv-el[aria-pressed="false"] { opacity: .35; }
.pv-icon { color: var(--pv-icon); line-height: 0; }
.pv-heading { color: var(--pv-heading); font-size: var(--pv-heading-size, 40px); font-weight: var(--pv-heading-weight, 700); line-height: 1.15; letter-spacing: -.01em; max-width: 22ch; }
.preview[data-scene="text"] .pv-heading { max-width: 26ch; }
.pv-body { color: var(--pv-body); font-size: var(--pv-body-size, 18px); font-weight: var(--pv-body-weight, 400); line-height: 1.6; max-width: 62ch; }
.pv-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 4px; }
.pv-button { overflow-wrap: normal; }
.pv-btn-face { display: inline-block; white-space: nowrap; max-width: 100%; background: var(--pv-btn); color: var(--pv-btn-text); font-size: var(--pv-button-size, 18px); font-weight: var(--pv-button-weight, 700); border-radius: 10px; padding: .6em 1.3em; line-height: 1.2; }
.preview[data-scene="brand"] .pv-btn-face { border-radius: 999px; }
.preview[data-markers="on"] .pv-el[data-status="bad"]::after, .preview[data-markers="on"] .pv-el[data-status="warn"]::after { content: '!'; position: absolute; top: -10px; right: -10px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font: 800 12px/1 var(--font); color: #fff; background: var(--bad); border: 2px solid #fff; }
.preview[data-markers="on"] .pv-el[data-status="warn"]::after { background: #B45309; }
.canvas-foot { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; justify-content: space-between; margin-top: 8px; }
.canvas-foot p { margin: 0; }
.view-opts summary { cursor: pointer; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); min-height: 32px; display: inline-flex; align-items: center; }
.view-opts[open] { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: center; }

/* ---------- Workbench (grouped controls under the canvas) ---------- */
.workbench { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); margin-bottom: var(--gap); }
@container (min-width: 760px) { .workbench { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .wb-colors { grid-column: 1 / -1; } }
@container (min-width: 1240px) { .workbench { grid-template-columns: minmax(0, 2.1fr) minmax(200px, .7fr) minmax(260px, 1fr); } .wb-colors { grid-column: auto; } }
.wb { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; min-width: 0; }
.wb-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.wb-head .wb-title span:first-child { color: var(--muted); font-weight: 600; }
.ce-pair { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@container (min-width: 700px) { .ce-pair { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); } }
.ce { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px 12px; margin: 0; min-width: 0; }
.ce legend { font-weight: 700; font-size: var(--fs-md); color: var(--ink); padding: 0 6px; margin: 0; }
.ce-row { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 10px; align-items: end; }
.ce-swatch input[type="color"] { -webkit-appearance: none; appearance: none; width: 56px; height: 56px; padding: 0; border: 1px solid var(--line-2); border-radius: var(--r-md); background: none; cursor: pointer; display: block; }
.ce-swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 3px; }
.ce-swatch input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(0,0,0,.12); border-radius: 9px; }
.ce-swatch input[type="color"]::-moz-color-swatch { border: 1px solid rgba(0,0,0,.12); border-radius: 9px; }
.ce-hex { display: flex; flex-direction: column; min-width: 0; }
.hex-label { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); margin: 0 0 2px; }
.hex-input { width: 100%; font-family: var(--mono); text-transform: uppercase; }
.ce-light { display: grid; grid-template-columns: auto minmax(0, 1fr) 64px; gap: 8px; align-items: center; margin-top: 10px; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.ce-light input[type="range"] { width: 100%; }
.ce-light input[type="number"] { width: 64px; padding: 0 6px; }
.ce-picks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pick { width: 28px; height: 28px; border-radius: 50%; border: 1px solid #6B7280; background: var(--c); cursor: pointer; padding: 0; position: relative; }
.pick[aria-checked="true"] { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--ink); }
@media (pointer: coarse) { .pick { width: 36px; height: 36px; } }
.ce-scope { margin-top: 10px; border-top: 1px dashed var(--line-2); padding-top: 8px; }
.ce-shared { margin: 0 0 6px; color: var(--ink-2); }
.seg-mini { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.seg-mini label { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; font-size: var(--fs-sm); font-weight: 600; }
.swap { align-self: center; display: inline-grid; place-items: center; width: var(--ctl); height: var(--ctl); border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; justify-self: center; }
.swap:hover { background: var(--surface-2); }
.size-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-top: 10px; }
.size-row input[type="range"] { width: 100%; }
.size-num-wrap { display: inline-flex; align-items: center; gap: 4px; }
#size-num { width: 76px; padding: 0 6px; }
.unit { font-size: var(--fs-sm); color: var(--muted); }
.toggle { font: inherit; font-weight: 600; min-height: var(--ctl); padding: 0 14px; margin-top: 10px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; }
.toggle-b { font-weight: 800; font-family: Georgia, serif; }
.toggle[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.size-note { margin: 10px 0 0; }

/* outcome card — app colours, independent of the sample */
.result-head { display: flex; gap: 10px; align-items: flex-start; }
.ri { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-weight: 800; color: #fff; flex: none; }
.result[data-verdict="easy"] .ri { background: var(--ok); }
.result[data-verdict="easy"] .ri::before { content: '✓'; }
.result[data-verdict="largeOnly"] .ri { background: #B45309; }
.result[data-verdict="largeOnly"] .ri::before { content: '!'; }
.result[data-verdict="hard"] .ri { background: var(--bad); }
.result[data-verdict="hard"] .ri::before { content: '✗'; }
.result-title { font-size: var(--fs-xl); margin: 0 0 2px; }
.result[data-verdict="easy"] .result-title { color: var(--ok); }
.result[data-verdict="largeOnly"] .result-title { color: var(--mid); }
.result[data-verdict="hard"] .result-title { color: var(--bad); }
.result-text { margin: 0; color: var(--ink-2); }
.result-size, .result-boundary { margin: 10px 0 0; font-weight: 600; }
.mark.is-pass { color: var(--ok); }
.mark.is-fail { color: var(--bad); }
.wb-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* suggestion panel */
.suggest-panel { margin-bottom: var(--gap); }
.suggest-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); margin-top: 8px; }
@container (min-width: 900px) { .suggest-grid { grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); } }
#suggest-target { width: 100%; margin-bottom: 10px; }
.compare { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cmp { margin: 0; flex: 1 1 160px; min-width: 0; }
.cmp figcaption { font-weight: 700; margin-bottom: 4px; }
.cmp-sample { background: var(--cbg); color: var(--cfg); border: 1px solid var(--line); border-radius: var(--r-md); font-size: 2rem; font-weight: 700; padding: 14px; text-align: center; }
.cmp-hex { font-family: var(--mono); font-size: var(--fs-sm); margin: 6px 0 0; }
.cmp-verdict { font-weight: 600; margin: 2px 0 0; font-size: var(--fs-sm); }
.cmp-arrow { font-size: 1.4rem; font-weight: 700; color: var(--muted); }
.suggest-msg { margin: 10px 0 0; }

/* ---------- Palette row (Thử màu) ---------- */
.palette-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; }
.prow-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.prow-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.chips { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: stretch; border: 1px solid var(--line-2); border-radius: var(--r-md); background: var(--surface); overflow: hidden; }
.chip.is-current { border-color: var(--ink); }
.chip-sel { font: inherit; display: inline-flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 5px 10px 5px 6px; min-height: var(--ctl); cursor: pointer; color: var(--ink); text-align: left; }
.chip-sel[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.chip-sw { width: 28px; height: 28px; border-radius: 8px; background: var(--c); border: 1px solid rgba(0,0,0,.18); flex: none; }
.chip-name { font-weight: 600; font-size: var(--fs-sm); max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-hex { font-family: var(--mono); font-size: var(--fs-xs); color: var(--muted); }
.chip.is-current .chip-name::after { content: ' •'; color: var(--accent); }
.chip-lock { border-left: 1px solid var(--line); border-radius: 0; width: 38px; height: auto; background: var(--surface-2); }
.chip-lock[aria-pressed="true"] { background: var(--ink); color: #fff; }
.btn-icon-sm { width: 36px; height: 36px; display: inline-grid; place-items: center; border: 1px solid transparent; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink); cursor: pointer; padding: 0; }
.btn-icon-sm:hover { border-color: var(--line-2); }
.btn-icon-sm:disabled { opacity: .35; cursor: not-allowed; }
.btn-icon-sm .ic-wrap { line-height: 0; }

/* ---------- Bộ màu ---------- */
.pal-layout { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@container (min-width: 960px) { .pal-layout { grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); align-items: start; } }
.swatches { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.sw { border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sw.is-current { border-color: var(--ink); }
.sw.is-dragging { opacity: .6; border-style: dashed; }
.sw-face { display: block; height: 72px; border-radius: 9px; background: var(--c); border: 1px solid rgba(0,0,0,.14); cursor: pointer; position: relative; }
.sw-face:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.sw-uses { position: absolute; left: 6px; bottom: 6px; right: 6px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink); background: rgba(255,255,255,.94); border-radius: 6px; padding: 1px 6px; width: max-content; max-width: calc(100% - 12px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw-uses:empty { display: none; }
.sw-name, .sw-hex { width: 100%; min-width: 0; min-height: 34px; padding: 0 8px; font-size: var(--fs-sm); }
.sw-name { font-weight: 600; }
.sw-tools { display: flex; justify-content: space-between; gap: 2px; }
.sw-move { cursor: grab; touch-action: none; }
.sw-lock[aria-pressed="true"] { background: var(--ink); color: #fff; }

/* colour wheel */
.mix select { width: 100%; }
.wheel-wrap { margin: 12px 0; }
.wheel { --wheel-l: 50%; position: relative; width: min(100%, 240px); aspect-ratio: 1; margin: 0 auto; border-radius: 50%; cursor: crosshair; touch-action: none; border: 1px solid var(--line);
  background: radial-gradient(circle closest-side, hsl(0 0% var(--wheel-l)), transparent), conic-gradient(from 0deg, hsl(0 100% var(--wheel-l)), hsl(60 100% var(--wheel-l)), hsl(120 100% var(--wheel-l)), hsl(180 100% var(--wheel-l)), hsl(240 100% var(--wheel-l)), hsl(300 100% var(--wheel-l)), hsl(360 100% var(--wheel-l))); }
.wheel-dot, .wheel-handle { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); border-radius: 50%; background: var(--c); }
.wheel-dot { width: 14px; height: 14px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.wheel-dot.is-locked { border-style: dashed; }
.wheel-handle { width: 28px; height: 28px; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--ink), 0 2px 6px rgba(0,0,0,.3); cursor: grab; }
.mix-fields { display: grid; grid-template-columns: auto minmax(0, 1fr) 64px; gap: 6px 8px; align-items: center; font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.mix-fields input[type="range"] { width: 100%; }
.mix-fields input[type="number"] { width: 64px; padding: 0 6px; }
.mix-fields #mix-hex { grid-column: 2 / 4; }
.harmony { margin-top: 12px; display: grid; gap: 6px; }
.harmony .hm { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px; align-items: center; margin: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; }
.harmony .hm:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.harmony .hm span { display: flex; flex-direction: column; }
.harmony .ic { color: var(--accent); width: 24px; height: 24px; }

/* ---------- Các cặp màu ---------- */
.mx-controls { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: flex-end; margin: 12px 0; }
.mx-level p { margin: 4px 0 0; }
.mx-filter { margin: 0; }
.matrix-scroll { overflow: auto; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--r-md); }
.matrix { border-collapse: separate; border-spacing: 0; width: auto; font-size: var(--fs-sm); }
.matrix th { position: sticky; background: var(--surface); z-index: 1; white-space: nowrap; font-weight: 600; border: 0; border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; }
.matrix thead th { top: 0; }
.matrix tbody th { left: 0; border-right: 1px solid var(--line); }
.matrix th .mx-name { display: inline-block; max-width: 9em; overflow: hidden; text-overflow: ellipsis; vertical-align: -3px; margin-left: 4px; }
.matrix td { padding: 3px; border: 0; }
.mx-chip { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c); border: 1px solid #6B7280; vertical-align: -2px; }
.mx-cell { font: inherit; display: grid; gap: 2px; place-items: center; width: 96px; min-height: 68px; border-radius: 10px; border: 1px solid var(--line); background: var(--cbg); color: var(--cfg); cursor: pointer; padding: 4px; position: relative; overflow: hidden; }
.mx-cell.is-fail { background: repeating-linear-gradient(135deg, transparent 0 9px, rgba(127,127,127,.34) 9px 11px), var(--cbg); border-color: #F4A39A; }
.mx-cell[aria-current="true"] { outline: 2px solid var(--sel); outline-offset: 1px; }
.mx-aa { font-weight: 700; font-size: 1.2rem; line-height: 1; }
.mode-large .mx-aa { font-size: 1.6rem; }
.mx-val { font-size: var(--fs-xs); font-weight: 700; background: #fff; color: var(--ink); border-radius: 999px; padding: 1px 6px; }
.mx-cell.is-fail .mx-val { color: var(--bad); }
.mx-cell.is-pass .mx-val { color: var(--ok); }
.mx-diag { background: repeating-linear-gradient(45deg, var(--surface-2) 0 4px, #fff 4px 8px); border-radius: 10px; }

/* ---------- Project row, embed ---------- */
.action-row { margin-top: calc(var(--gap) + 6px); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
.action-row .status, .action-row .muted { margin: 0; }
.file-btn { position: relative; }
.file-btn:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.more-panel { margin-top: 12px; }
.embed-open-full { margin-top: 12px; font-size: var(--fs-sm); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: var(--fs-sm); }
th, td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
thead th { background: var(--surface-2); }
caption { text-align: left; font-weight: 600; padding-bottom: 6px; }
td.is-pass { color: var(--ok); font-weight: 600; }
td.is-fail { color: var(--bad); font-weight: 600; }
td.is-na { color: var(--muted); }
tr[data-current="true"] th { background: var(--accent-soft); }
.sw-dot { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--c); border: 1px solid rgba(0,0,0,.2); vertical-align: -2px; }

/* ---------- Dialogs ---------- */
.dlg { width: min(1120px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 20px 20px; color: var(--ink); box-shadow: 0 20px 50px rgba(17,24,39,.25); }
.dlg::backdrop { background: rgba(17, 24, 39, .5); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: var(--fs-xl); }
.details-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 820px) { .details-grid { grid-template-columns: minmax(240px, .8fr) minmax(0, 1.4fr); } }
.tech-ratio { font-size: 1.15rem; }
.opt-grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .opt-grid { grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); } }
.optset { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.opt-choice { display: flex !important; align-items: flex-start; gap: 8px; margin: 0 0 6px !important; min-height: 0; }
.opt-choice > input { margin-top: 3px !important; }
.opt-choice > span { display: flex; flex-direction: column; }
.opt-pairs { display: flex; flex-direction: column; }
.unlock-list { display: flex; flex-wrap: wrap; gap: 6px; }
.progress { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress-bar { --p: 0%; height: 100%; width: var(--p); background: var(--accent); }
.opt-summary { font-weight: 700; font-size: var(--fs-lg); }
.opt-summary:focus { outline: none; }
.opt-compare { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.opt-compare figure { margin: 0; }
.opt-compare figcaption { font-weight: 700; margin-bottom: 4px; }
.mini-pv { background: var(--m-card); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; display: flex; flex-direction: column; gap: 6px; min-height: 150px; }
.mini-pv .m-icon { width: 18px; height: 18px; border-radius: 4px; border: 3px solid var(--m-icon); }
.mini-pv .m-h { color: var(--m-heading); font-weight: 700; font-size: 1.15rem; line-height: 1.2; }
.mini-pv .m-p { color: var(--m-body); font-size: .8rem; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mini-pv .m-b { align-self: flex-start; background: var(--m-btn); color: var(--m-btn-text); font-weight: 700; font-size: .8rem; border-radius: 8px; padding: 4px 10px; }
.mini-sw { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.m-sw { width: 24px; height: 24px; border-radius: 6px; background: var(--c); border: 1px solid rgba(0,0,0,.2); }
.opt-table td, .opt-table th { white-space: nowrap; }
.export-dialog { padding: 0; }
.export-form { padding: 16px 20px 20px; }
.export-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
@media (min-width: 860px) { .export-grid { grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); } }
.export-options input[type="text"] { width: 100%; }
.export-options fieldset { margin-top: 12px; }
.name-error { background: var(--bad-bg); border: 1px solid #F4A39A; border-radius: var(--r-sm); padding: 10px; margin-top: 8px; }
.name-error p { color: var(--bad); font-weight: 600; margin: 0 0 8px; font-size: var(--fs-sm); }
.export-preview { border: 1px solid var(--line); border-radius: var(--r-md); background: #E5E7EB; padding: 12px; max-height: 62vh; overflow: auto; min-height: 120px; }
.export-preview svg { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.dialog-actions { border-top: 1px solid var(--line); padding-top: 12px; }
.print-root { display: none; }

/* ---------- Learning drawer ---------- */
.learn { background: var(--surface); border-left: 1px solid var(--line); }
.learn-head { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); z-index: 2; }
.learn-head h2 { flex: 1; margin: 0; font-size: var(--fs-xl); }
.learn-head h2:focus { outline: none; }
.btn-close { min-height: 36px; }
.learn-body { padding: 16px; }
.learn-nav ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; counter-reset: t; }
.learn-nav li a { display: block; padding: 12px 14px 12px 50px; border-radius: var(--r-md); background: var(--surface-2); text-decoration: none; color: var(--ink); font-weight: 600; position: relative; counter-increment: t; }
.learn-nav li a:hover { background: var(--surface-3); }
.learn-nav li a::before { content: counter(t); position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: var(--ink); }
.learn-nav li:nth-child(7n+1) a::before { background: var(--yellow); }
.learn-nav li:nth-child(7n+2) a::before { background: var(--teal); }
.learn-nav li:nth-child(7n+3) a::before { background: #F9A47A; }
.learn-nav li:nth-child(7n+4) a::before { background: #9ED7F0; }
.learn-nav li:nth-child(7n+5) a::before { background: #D2DA8C; }
.learn-nav li:nth-child(7n+6) a::before { background: #F6B8A6; }
.learn-nav li:nth-child(7n+7) a::before { background: #B8CBE8; }
.topic h3 { font-size: var(--fs-xl); }
.topic h3:focus { outline: none; }
.demo { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; margin: 12px 0; background: var(--surface-2); }
.demo-label { font-size: var(--fs-xs); font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.demo-switch { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.demo-opt { font: inherit; font-weight: 600; font-size: var(--fs-sm); min-height: 36px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 14px; cursor: pointer; color: var(--ink); }
.demo-opt[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.demo-stage { background: var(--dbg); color: var(--dfg); border-radius: var(--r-md); border: 1px solid var(--line); padding: 16px; }
.demo-text { font-size: var(--dsize); font-weight: var(--dweight); line-height: 1.4; }
.demo-btn { display: inline-block; border: 3px solid var(--dfg); border-radius: 12px; padding: .4em 1em; font-size: var(--dsize); font-weight: var(--dweight); }
.demo-result { font-weight: 600; margin: 8px 0 0; font-size: var(--fs-sm); }
.formula-live { background: var(--accent-soft); border-radius: var(--r-sm); padding: 10px 12px; font-weight: 600; }
.sources { overflow-wrap: anywhere; }
@media (min-width: 900px) {
  body.learn-open .page { display: grid; grid-template-columns: minmax(0, 1fr) min(440px, 36vw); }
  body.learn-open .learn { position: sticky; top: 60px; height: calc(100vh - 60px); overflow: auto; }
}
@media (max-width: 899px) {
  .learn { position: fixed; inset: 0; z-index: 60; overflow: auto; border-left: 0; }
}

.site-footer { border-top: 1px solid var(--line); padding: 20px 0 28px; font-size: var(--fs-sm); background: var(--surface); }
.site-footer p { margin: 0 0 4px; }

/* ---------- Mid widths: compact app bar (labels stay available to assistive tech) ---------- */
@media (max-width: 1279px) {
  .history .btn-icon-label > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .history .btn-icon-label { width: var(--ctl); padding: 0; }
  .appbar-project { flex-basis: 140px; max-width: 280px; }
}
@media (max-height: 820px) and (min-width: 761px) {
  .intro { margin: 0 0 10px; }
  main { padding-top: 10px; }
}

/* ---------- Small screens ---------- */
@media (max-width: 760px) {
  .appbar { position: static; }
  .appbar-inner { gap: 6px 8px; }
  /* phone: row 1 = brand + Download, row 2 = undo/redo/language/learn, row 3 = project name */
  .appbar-actions { display: contents; }
  .appbar-inner > .brand { order: 1; margin-right: auto; }
  #btn-export { order: 2; }
  .history { order: 3; }
  .lang-nav, .lang-select { order: 4; }
  #learn-open, #learn-link-embed { order: 5; }
  .appbar-project { order: 6; flex-basis: 100%; max-width: none; }
  .btn-icon-label > span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .btn-icon-label { width: var(--ctl); padding: 0; }
  #btn-export.btn-icon-label > span, #btn-optimize > span, #btn-board > span, #btn-optimize-2 > span, #btn-board-2 > span, #opt-run > span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  #btn-export.btn-icon-label, #btn-optimize, #btn-board, #btn-optimize-2, #btn-board-2, #opt-run { width: auto; padding: 0 12px; }
  .preview { min-height: 300px; }
  .pv-heading { font-size: min(var(--pv-heading-size, 40px), 11vw); }
  .moderow { flex-direction: column; align-items: stretch; }
  .seg-tabs { width: 100%; }
  .seg-tabs [role="tab"] { flex: 1 1 auto; padding: 0 10px; justify-content: center; }
}
@media (max-width: 420px) {
  .tool-name, .brand-sep { display: none; }
  .seg-tabs [role="tab"] .ic { display: none; }
  .seg-tabs { flex-wrap: wrap; border-radius: var(--r-md); overflow: visible; }
  .seg-tabs [role="tab"] { border-radius: 10px; }
  .panel, .wb, .palette-row { padding: 12px; }
  .preview[data-scene="brand"] { grid-template-columns: minmax(0, 1fr) 56px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
@media (forced-colors: active) { .mark, .pick, .mx-cell, .chip { border: 1px solid CanvasText; } .pv-el[aria-pressed="true"] { outline: 2px solid Highlight; } }

/* ---------- Print ---------- */
@media print {
  /* 1) Report print (button "In"): only #print-root, one A4 page per SVG. */
  html.printing-report body > *:not(#print-root) { display: none !important; }
  html.printing-report .print-root { display: block; }
  html.printing-report body { margin: 0; background: #fff; }
  .print-page { break-after: page; page-break-after: always; overflow: hidden; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-page.landscape { width: 297mm; height: 210mm; }
  .print-page.portrait { width: 210mm; height: 297mm; }
  .print-page svg { display: block; width: 100%; height: 100%; }
  /* 2) Plain browser print of the page (Ctrl+P): the composition + outcome, no app chrome or editor overlays. */
  html:not(.printing-report) .appbar, html:not(.printing-report) .moderow, html:not(.printing-report) .wb-colors,
  html:not(.printing-report) .wb-type, html:not(.printing-report) .site-footer, html:not(.printing-report) .action-row,
  html:not(.printing-report) .skip-link, html:not(.printing-report) dialog, html:not(.printing-report) .learn,
  html:not(.printing-report) .canvas-foot, html:not(.printing-report) .wb-actions, html:not(.printing-report) .prow-actions,
  html:not(.printing-report) .chip-lock, html:not(.printing-report) .more-panel, html:not(.printing-report) .suggest-panel { display: none !important; }
  html:not(.printing-report) .workbench { display: block; }
  html:not(.printing-report) .pv-el { opacity: 1 !important; box-shadow: none !important; transition: none !important; }
  html:not(.printing-report) .pv-el::before, html:not(.printing-report) .pv-el::after { display: none !important; }
  .preview, .chip-sw, .mark { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .preview { break-inside: avoid; }
}
