:root {
  --bg: #F3EFE8; --panel: #FFFFFF; --ink: #2B2630; --ink2: #5E5664; --muted: #9A929F; --line: #ECE6DD; --soft: #F7F4EE;
  --accent: #6A5AF0; --accent-2: #8F82FF; --accent-soft: #EEEBFF; --warm: #FF8A65; --ok: #2EAD74;
  --r: 14px; --r-sm: 10px; --shadow: 0 1px 2px rgba(43, 38, 48, .06), 0 6px 24px rgba(43, 38, 48, .06);
  font-family: 'Be Vietnam Pro', system-ui, sans-serif; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; font-size: 13.5px; }
button { font: inherit; color: inherit; }

/* ---------- thanh trên */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand b { font-size: 15px; letter-spacing: -.01em; }
.brand .tag { font-size: 11px; color: var(--muted); background: var(--soft); padding: 3px 8px; border-radius: 99px; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: conic-gradient(from 200deg, #6A5AF0, #FF8A65, #FFD65A, #58C27D, #6A5AF0); box-shadow: inset 0 0 0 5px #fff; outline: 1px solid var(--line); }
.top-mid { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.top-right { display: flex; align-items: center; gap: 8px; }
.sel { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.sel select, .name { font: inherit; border: 1px solid var(--line); background: var(--soft); border-radius: var(--r-sm); padding: 7px 10px; color: var(--ink); }
.name { width: 150px; font-weight: 600; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-sm); padding: 7px 12px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s; }
.btn:hover { background: var(--soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #5B4BE6; }
.btn.ghost { background: transparent; }
.btn.icon { padding: 7px 10px; }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px; width: 290px; z-index: 20; }
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.menu-pop button:hover { background: var(--accent-soft); }

/* ---------- bố cục */
.app { flex: 1; display: grid; grid-template-columns: 380px 1fr 320px; min-height: 0; }
.panel { background: var(--panel); min-height: 0; display: flex; flex-direction: column; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); overflow-y: auto; padding: 6px 0 20px; }
.tabs { display: flex; gap: 2px; padding: 10px 10px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 9px 8px 11px; border-radius: 10px 10px 0 0; cursor: pointer; color: var(--ink2); font-weight: 500; position: relative; white-space: nowrap; }
.tabs button.on { color: var(--accent); }
.tabs button.on::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px; border-radius: 3px; background: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; padding: 14px 16px 30px; }

/* ---------- khối điều khiển */
.sec { margin-bottom: 18px; }
.sec h4, .box h4 { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; display: flex; justify-content: space-between; align-items: baseline; }
.sec h4 small, .box h4 small, .box h3 small { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 400; }
.seg { display: flex; background: var(--soft); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 7px 6px; border-radius: 8px; cursor: pointer; color: var(--ink2); font-weight: 500; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.slider { display: grid; grid-template-columns: 96px 1fr 34px; align-items: center; gap: 8px; margin: 6px 0; color: var(--ink2); }
.slider output { font-variant-numeric: tabular-nums; color: var(--muted); text-align: right; font-size: 12px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sw { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--accent); }
.sw-pick { width: 30px; height: 28px; border: 1px dashed var(--muted); border-radius: 8px; padding: 0; background: none; cursor: pointer; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid.g3 { grid-template-columns: repeat(3, 1fr); }
.grid.g5 { grid-template-columns: repeat(5, 1fr); }
.card { border: 1px solid var(--line); background: var(--soft); border-radius: var(--r-sm); padding: 4px 4px 6px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; transition: border-color .15s, background .15s, transform .1s; min-width: 0; }
.card:hover { border-color: #D8D0F8; background: #FBFAFF; }
.card.on { border-color: var(--accent); background: var(--accent-soft); }
.card svg { width: 100%; height: auto; display: block; }
.card span { font-size: 11px; color: var(--ink2); text-align: center; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 6px 11px; cursor: pointer; font-size: 12.5px; color: var(--ink2); }
.chip:hover { background: var(--soft); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.row-check { display: flex; align-items: center; gap: 8px; margin: 8px 0 0; color: var(--ink2); }
.sub { border-top: 1px dashed var(--line); margin-top: 12px; padding-top: 12px; }
.pill { font-size: 11px; color: var(--muted); }

/* ---------- sân khấu */
.stage-wrap { position: relative; min-width: 0; min-height: 0; display: flex; background: radial-gradient(120% 90% at 50% 38%, #FFFDF8 0%, #EFE9DF 70%); }
.stage { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.stage:active { cursor: grabbing; }
.stage-ui { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.views, .stage-tools { pointer-events: auto; display: flex; gap: 4px; background: rgba(255,255,255,.88); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 99px; padding: 4px; box-shadow: var(--shadow); }
.views button { border: 0; background: transparent; padding: 7px 12px; border-radius: 99px; cursor: pointer; color: var(--ink2); font-weight: 500; }
.views button.on { background: var(--ink); color: #fff; }
.stage-tools { padding: 4px 6px; align-items: center; }
.stage-tools .chip { border: 0; background: transparent; }
.stage-tools .chip.on { background: var(--accent-soft); color: var(--accent); }
.zoom { display: flex; align-items: center; gap: 6px; color: var(--ink2); font-size: 12px; padding: 0 8px; }
.zoom input { width: 110px; }
.hint { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.7); padding: 5px 10px; border-radius: 99px; white-space: nowrap; }

/* ---------- panel phải */
.box { padding: 12px 16px 14px; border-bottom: 1px solid var(--line); }
.box h3 { margin: 0 0 10px; font-size: 14px; display: flex; justify-content: space-between; align-items: baseline; }
.playbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.spd { flex: 1; display: flex; white-space: nowrap; align-items: center; gap: 6px; color: var(--ink2); font-size: 12px; }
.spd output { width: 32px; text-align: right; color: var(--muted); }
.groups { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.groups button { border: 0; background: var(--soft); padding: 5px 9px; border-radius: 99px; cursor: pointer; font-size: 12px; color: var(--ink2); }
.groups button.on { background: var(--ink); color: #fff; }
.cliplist { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-bottom: 12px; }
.cliplist button { text-align: left; border: 1px solid var(--line); background: var(--panel); padding: 7px 9px; border-radius: 9px; cursor: pointer; font-size: 12.5px; display: flex; justify-content: space-between; gap: 4px; }
.cliplist button small { color: var(--muted); font-size: 10.5px; }
.cliplist button:hover { border-color: #D8D0F8; }
.cliplist button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.exprs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.exprs button { border: 1px solid var(--line); background: var(--panel); padding: 7px 4px; border-radius: 9px; cursor: pointer; font-size: 12px; }
.exprs button.on { border-color: var(--warm); background: #FFF1EC; color: #D35430; font-weight: 600; }
.say { display: flex; gap: 6px; }
.say input { flex: 1; min-width: 0; font: inherit; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 8px 10px; background: var(--soft); }
.visemes { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.visemes button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 4px 7px; font-size: 11.5px; cursor: pointer; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 13px; z-index: 50; }

@media (max-width: 1500px) {
  .brand .tag { display: none; }
  .name { width: 120px; }
  .top { gap: 10px; }
}
@media (max-width: 1180px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .top-mid { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 2px; }
  .top-right { margin-left: auto; }
  .sel span { display: none; }
  .app { grid-template-columns: 330px 1fr; }
  .panel.right { display: none; }
}
@media (max-width: 760px) {
  .top-right { flex-wrap: wrap; margin-left: 0; }
  .top-right a.btn { display: none; }
  .stage-tools { flex-wrap: wrap; justify-content: center; border-radius: 16px; }
  .zoom input { width: 80px; }
  .views button { padding: 7px 9px; }
  body { overflow: auto; }
  .app { grid-template-columns: 1fr; grid-template-rows: 60vh auto; }
  .panel.left { order: 2; }
  .top { flex-wrap: wrap; }
  .brand .tag, .hint { display: none; }
}

/* ---------- thư viện */
.gallery { position: fixed; inset: 0; background: rgba(43, 38, 48, .35); display: flex; align-items: center; justify-content: center; z-index: 40; }
.gallery[hidden] { display: none; }
.gal-box { background: var(--panel); border-radius: 18px; width: min(1100px, 94vw); max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.gal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.gal-head .btn { margin-left: auto; }
.gal-grid { overflow-y: auto; padding: 16px 18px 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.gal-card { border: 1px solid var(--line); border-radius: 14px; background: var(--soft); padding: 8px 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.gal-card .pic { background: radial-gradient(120% 90% at 50% 35%, #FFFDF8, #EFE9DF 80%); border-radius: 10px; cursor: pointer; }
.gal-card .pic svg { width: 100%; height: 200px; display: block; }
.gal-card b { font-size: 13px; }
.gal-card small { color: var(--muted); font-size: 11px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em; }
.gal-card .acts { display: flex; gap: 6px; }
.gal-card .acts button { flex: 1; font-size: 12px; padding: 5px 6px; }

.narrow-only { display: none; }
@media (max-width: 1180px) {
  .narrow-only { display: inline-block; }
  body.show-anim .panel.right { display: flex; flex-direction: column; position: fixed; right: 0; top: 0; bottom: 0; width: min(340px, 92vw); z-index: 30; box-shadow: -12px 0 40px rgba(0,0,0,.15); }
  body.show-anim::after { content: ""; position: fixed; inset: 0; background: rgba(43,38,48,.25); z-index: 29; }
}

/* ---------- ảnh AI */
.ai-body { display: grid; grid-template-columns: 340px 1fr; gap: 18px; padding: 16px 18px 20px; overflow-y: auto; }
.ai-left { display: flex; flex-direction: column; gap: 10px; }
.ai-pic { background: radial-gradient(120% 90% at 50% 35%, #FFFDF8, #EFE9DF 80%); border-radius: 12px; border: 1px solid var(--line); display: flex; justify-content: center; min-height: 300px; }
.ai-pic img { height: 300px; display: block; }
.ai-lab { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink2); }
.ai-lab textarea, .ai-lab input { font: inherit; font-size: 12.5px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--soft); resize: vertical; }
.ai-act { display: flex; gap: 8px; }
.ai-status { font-size: 12.5px; color: var(--ink2); min-height: 1.4em; }
.ai-status.err { color: #C0392B; }
.ai-status details { color: var(--muted); font-size: 11px; margin-top: 4px; }
.ai-right h4 { margin: 0 0 8px; font-size: 12px; color: var(--ink2); text-transform: uppercase; letter-spacing: .04em; }
.ai-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.ai-grid a { display: block; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; text-decoration: none; color: var(--ink2); font-size: 11px; }
.ai-grid img { width: 100%; height: 260px; object-fit: contain; display: block; background: #fff; }
.ai-grid span { display: block; padding: 6px 8px; }
.ai-empty { color: var(--muted); font-size: 13px; padding: 20px 0; }
@media (max-width: 900px) { .ai-body { grid-template-columns: 1fr; } }
