:root {
  color-scheme: dark;
  --bg: #0a0b0f;
  --panel: rgba(20, 22, 29, 0.82);
  --panel-2: #1a1d26;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.16);
  --text: #ece8e0;
  --muted: #8b909c;
  --acc: #ff7a1a;
  --acc-2: #ffb347;
  --chakra: #4fb2ff;
  --ok: #5bd68a;
  --warn: #ffc857;
  --err: #ff5d5d;
  --seal-red: #d8342a;
  --jp: "Yuji Syuku", "Noto Serif JP", "Yu Mincho", serif;
  --ui: "Be Vietnam Pro", system-ui, sans-serif;
  --r: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--ui); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }

.bg {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(1100px 600px at 12% -12%, rgba(255, 122, 26, 0.16), transparent 60%),
    radial-gradient(900px 600px at 105% 110%, rgba(79, 178, 255, 0.12), transparent 60%),
    var(--bg);
}
.bg::after {
  content: ''; position: absolute; inset: 0; opacity: 0.07; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- Header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  max-width: 1520px; margin: 0 auto; padding: 18px 28px 6px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%;
  font-family: var(--jp); font-size: 26px; color: #fff;
  background: radial-gradient(circle at 35% 30%, #ff9a45, #c4410a 70%);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08), 0 6px 24px rgba(255, 106, 26, 0.45);
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: 0.02em; }
.brand p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 99px;
  background: var(--panel); border: 1px solid var(--line); font-size: 12.5px; color: var(--muted);
  backdrop-filter: blur(8px);
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #555a66; }
.pill.ok i { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.warn i { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.pill.err i { background: var(--err); box-shadow: 0 0 8px var(--err); }
.pill.load i { background: var(--chakra); animation: pulse 1s ease-in-out infinite; }
.pill.ok, .pill.warn, .pill.err, .pill.load { color: var(--text); }
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 22px; align-items: start;
  max-width: 1520px; margin: 0 auto; padding: 14px 28px 28px;
}
@media (max-width: 1080px) { .layout { grid-template-columns: 1fr; } }

/* ---------- Stage ---------- */
.stage {
  position: relative; aspect-ratio: 4 / 3; border-radius: var(--r); overflow: hidden; isolation: isolate;
  background: #07080b; border: 1px solid var(--line-2);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud-seal {
  position: absolute; top: 16px; left: 16px; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px 8px 8px; border-radius: 99px; z-index: 3;
  background: rgba(8, 9, 12, 0.55); border: 1px solid var(--line-2); backdrop-filter: blur(10px);
}
.hud-seal svg { width: 56px; height: 56px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(255, 255, 255, 0.1); stroke-width: 4; }
.ring { fill: none; stroke: var(--muted); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 176; stroke-dashoffset: 176; transition: stroke-dashoffset 0.12s, stroke 0.2s; }
.hud-seal.hit .ring { stroke: var(--acc); filter: drop-shadow(0 0 4px var(--acc)); }
.hud-k { position: absolute; left: 8px; width: 56px; text-align: center; font-family: var(--jp); font-size: 28px; line-height: 56px; }
.hud-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--muted); }
.hud-name { font-weight: 600; font-size: 15px; }
.hud-prob { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.combo {
  position: absolute; left: 50%; bottom: 11%; transform: translateX(-50%); z-index: 3;
  display: flex; gap: 10px; align-items: center;
}
.tok {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-family: var(--jp); font-size: 24px; color: #fff;
  background: rgba(8, 9, 12, 0.6); border: 1px solid rgba(255, 255, 255, 0.25); backdrop-filter: blur(6px);
}
.combo .tok { box-shadow: 0 0 18px rgba(79, 178, 255, 0.35); border-color: rgba(79, 178, 255, 0.6); }
.combo .tok.new { animation: tokIn 0.35s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes tokIn { from { transform: scale(0.3); opacity: 0; } }

.stamp {
  position: absolute; left: 50%; top: 34%; z-index: 4; pointer-events: none; opacity: 0;
  width: 150px; height: 150px; margin: -75px 0 0 -75px; display: grid; place-items: center;
  font-family: var(--jp); font-size: 104px; line-height: 1; color: var(--seal-red);
  border: 6px solid var(--seal-red); border-radius: 18px;
  background: rgba(255, 244, 228, 0.9);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.stamp.show { animation: stamp 0.9s ease-out; }
@keyframes stamp {
  0% { opacity: 0; transform: scale(2.4) rotate(-14deg); }
  14% { opacity: 1; transform: scale(0.94) rotate(-7deg); }
  22% { transform: scale(1) rotate(-7deg); }
  70% { opacity: 1; transform: scale(1) rotate(-7deg); }
  100% { opacity: 0; transform: scale(1.06) rotate(-7deg); }
}

.title-card {
  --c: var(--acc);
  position: absolute; left: 0; right: 0; bottom: 18%; z-index: 4; pointer-events: none;
  padding: 18px 0 18px 7%; opacity: 0;
}
.tc-band {
  position: absolute; inset: 0 25% 0 0; z-index: -1;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 85%, #000) 0%, color-mix(in srgb, var(--c) 45%, transparent) 55%, transparent 100%);
  clip-path: polygon(0 12%, 100% 0, 92% 100%, 0 88%);
  transform-origin: left;
}
.tc-tag { display: inline-block; font-size: 12px; font-weight: 800; letter-spacing: 0.25em; text-transform: uppercase; color: #111; background: #fff; padding: 3px 10px; border-radius: 4px; }
.tc-jp { font-family: var(--jp); font-size: clamp(36px, 6vw, 76px); line-height: 1.15; color: #fff; text-shadow: 0 0 24px var(--c), 0 4px 10px rgba(0, 0, 0, 0.7); }
.tc-vi { font-size: clamp(14px, 1.6vw, 20px); font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8); }
.title-card.show { animation: tcFade 3.2s ease forwards; }
.title-card.show .tc-band { animation: tcBand 3.2s cubic-bezier(.2, .9, .2, 1) forwards; }
.title-card.show .tc-jp { animation: tcText 0.6s 0.1s cubic-bezier(.2, .9, .2, 1) backwards; }
.title-card.show .tc-vi, .title-card.show .tc-tag { animation: tcText 0.6s 0.25s cubic-bezier(.2, .9, .2, 1) backwards; }
@keyframes tcFade { 0%, 82% { opacity: 1; } 100% { opacity: 0; } }
@keyframes tcBand { 0% { transform: scaleX(0); } 18% { transform: scaleX(1); } }
@keyframes tcText { from { opacity: 0; transform: translateX(-40px); filter: blur(6px); } }

.intro {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
  background: radial-gradient(ellipse at center, rgba(10, 11, 15, 0.55), rgba(5, 6, 8, 0.92));
  transition: opacity 0.4s, visibility 0.4s;
}
.intro.hidden { opacity: 0; visibility: hidden; }
.intro h2 { margin: 6px 0 0; font-size: clamp(20px, 2.4vw, 30px); font-weight: 800; }
.intro p { margin: 0 0 8px; color: var(--muted); max-width: 460px; line-height: 1.55; }
.intro-logo { position: relative; width: 132px; height: 132px; display: grid; place-items: center; }
.intro-logo::before {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--acc), transparent 30%, var(--chakra) 50%, transparent 80%, var(--acc));
  -webkit-mask: radial-gradient(circle, transparent 58%, #000 60%); mask: radial-gradient(circle, transparent 58%, #000 60%);
  animation: spin 6s linear infinite; filter: blur(0.5px);
}
.intro-logo span { font-family: var(--jp); font-size: 68px; text-shadow: 0 0 30px rgba(255, 122, 26, 0.7); }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-primary {
  border: 0; cursor: pointer; padding: 13px 28px; border-radius: 99px; font-weight: 800; font-size: 15px; color: #1a0d03;
  background: linear-gradient(180deg, #ffa552, var(--acc)); box-shadow: 0 8px 28px rgba(255, 122, 26, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 12px 34px rgba(255, 122, 26, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.btn-primary:disabled { opacity: 0.55; cursor: progress; transform: none; }
.btn-ghost { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px 10px; text-decoration: underline; text-underline-offset: 3px; }
.btn-ghost:hover { color: var(--text); }
:focus-visible { outline: 2px solid var(--acc-2); outline-offset: 2px; }

.statusbar { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 4px 0; font-size: 12.5px; color: var(--muted); }
#status.warn { color: var(--warn); } #status.err { color: var(--err); } #status.ok { color: var(--ok); }
code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }

/* ---------- Sidebar ---------- */
.side { display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; backdrop-filter: blur(12px); }
.card > header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.card h2 { margin: 0; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.16em; color: var(--acc-2); }
.hint { font-size: 12px; color: var(--muted); }

.jutsu-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.jutsu {
  --c: var(--acc);
  position: relative; padding: 12px 12px 12px 16px; border-radius: 12px; overflow: hidden;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 12%, transparent), transparent 60%), var(--panel-2);
  border: 1px solid var(--line);
  transition: border-color 0.2s, transform 0.2s;
}
.jutsu::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--c); box-shadow: 0 0 12px var(--c); }
.jutsu.ready { border-color: color-mix(in srgb, var(--c) 60%, transparent); }
.jutsu.fired { animation: fired 0.8s ease; }
@keyframes fired { 30% { transform: scale(1.02); border-color: var(--c); box-shadow: 0 0 30px color-mix(in srgb, var(--c) 40%, transparent); } }
.j-head { display: flex; align-items: center; gap: 10px; }
.j-jp { font-family: var(--jp); font-size: 22px; line-height: 1.2; color: #fff; }
.j-tag { margin-left: auto; font-size: 10.5px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 50%, transparent); padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.j-vi { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.j-seals { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.j-seals .tok { width: 34px; height: 34px; font-size: 17px; background: rgba(255, 255, 255, 0.04); border-color: var(--line-2); transition: all 0.2s; }
.j-seals .tok.on { background: var(--c); color: #111; border-color: var(--c); box-shadow: 0 0 14px color-mix(in srgb, var(--c) 70%, transparent); }
.j-seals .arr { color: #4a4f5c; font-size: 11px; }
.j-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.j-bar { flex: 1; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); overflow: hidden; }
.j-bar i { display: block; height: 100%; width: 0; background: var(--c); box-shadow: 0 0 10px var(--c); transition: width 0.25s; }
.j-play {
  cursor: pointer; padding: 6px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line-2); transition: all 0.15s;
}
.j-play:hover { border-color: var(--c); color: #fff; background: color-mix(in srgb, var(--c) 18%, transparent); }
body.busy .j-play, body.busy .seal { pointer-events: none; opacity: 0.45; }

.seal-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seal {
  cursor: pointer; padding: 10px 4px 8px; border-radius: 12px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); transition: transform 0.12s, border-color 0.15s, background 0.15s;
}
.seal b { display: block; font-family: var(--jp); font-weight: 400; font-size: 26px; line-height: 1.1; color: #fff; }
.seal small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.seal:hover { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 10%, var(--panel-2)); transform: translateY(-2px); }
.seal:active { transform: scale(0.95); }

@media (max-width: 640px) {
  .top { padding: 14px 14px 4px; }
  .layout { padding: 10px 12px 20px; gap: 14px; }
  .intro { gap: 8px; padding: 12px; }
  .intro-logo { width: 72px; height: 72px; }
  .intro-logo span { font-size: 36px; }
  .intro h2 { font-size: 17px; }
  .intro p { display: none; }
  .btn-primary { padding: 10px 22px; font-size: 14px; }
  .hud-seal { top: 8px; left: 8px; transform: scale(0.78); transform-origin: top left; }
  .combo { gap: 6px; bottom: 10%; }
  .combo .tok { width: 34px; height: 34px; font-size: 17px; }
  .stamp { width: 96px; height: 96px; margin: -48px 0 0 -48px; font-size: 64px; border-width: 4px; }
  .title-card { padding: 10px 0 10px 5%; bottom: 14%; }
  .seal-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation-duration: 0.01s !important; transition-duration: 0.01s !important; }
  .title-card.show { animation: tcFade 3.2s steps(1) forwards !important; }
}

/* ---------- Điều hướng ---------- */
.nav { display: flex; gap: 4px; padding: 4px; border-radius: 99px; background: var(--panel); border: 1px solid var(--line); }
.nav a { padding: 7px 16px; border-radius: 99px; color: var(--muted); text-decoration: none; font-size: 13.5px; font-weight: 600; transition: all 0.15s; }
.nav a:hover { color: var(--text); }
.nav a[aria-current="page"] { background: linear-gradient(180deg, #ffa552, var(--acc)); color: #1a0d03; }
.top-right { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.intro-link { color: var(--acc-2); font-size: 13.5px; }

/* ---------- Trang huấn luyện ---------- */
.rec-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
@media (max-width: 1280px) { .rec-wrap { grid-template-columns: 1fr; } }
.rec-stage { aspect-ratio: 1; max-height: 78vh; margin: 0 auto; width: 100%; }
.rec-badge {
  position: absolute; top: 14px; left: 14px; z-index: 3; display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 6px; border-radius: 99px; background: rgba(8, 9, 12, 0.6); border: 1px solid var(--line-2); backdrop-filter: blur(8px); font-weight: 600;
}
.rec-k { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-family: var(--jp); font-size: 22px; background: var(--acc); color: #1a0d03; }
.rec-live {
  position: absolute; top: 18px; right: 18px; z-index: 3; display: none; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 6px; background: rgba(216, 52, 42, 0.92); font-size: 12px; font-weight: 800; letter-spacing: 0.1em;
}
.rec-live i { width: 9px; height: 9px; border-radius: 50%; background: #fff; animation: pulse 0.8s infinite; }
body.capturing .rec-live { display: flex; }
body.recording .rec-stage { box-shadow: 0 0 0 3px var(--seal-red), 0 30px 80px -20px rgba(0, 0, 0, 0.8); }
.countdown {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; pointer-events: none;
  font-size: clamp(90px, 18vw, 200px); font-weight: 800; color: #fff; text-shadow: 0 0 40px var(--acc), 0 6px 20px rgba(0, 0, 0, 0.6);
}
.countdown:empty { display: none; }

.rec-ctrl { display: flex; flex-direction: column; gap: 12px; }
.rec-title { display: flex; align-items: center; gap: 12px; }
.rec-title b { font-size: 17px; }
.rec-big { width: 58px; height: 58px; border-radius: 14px; display: grid; place-items: center; font-family: var(--jp); font-size: 34px; background: var(--panel-2); border: 1px solid var(--line-2); color: #fff; }
.rec-ctrl .j-bar i { background: var(--acc); box-shadow: 0 0 10px var(--acc); }
.tip { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--acc-2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row .btn-primary { flex: 1; }
select {
  font: inherit; font-size: 13.5px; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 9px 10px; cursor: pointer;
}
kbd { font: 600 12px var(--ui); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line-2); background: var(--panel-2); }
.rec-ctrl .hint { margin: 0; line-height: 1.5; }
.thumbs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.thumbs img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.thumbs:empty::before { content: 'Chưa có ảnh nào cho ấn này.'; grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); }
.btn-ghost.danger { color: #c9837f; }
.btn-ghost.danger:hover { color: var(--err); }
a.btn-ghost { font-size: 13.5px; }

.class-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cls {
  position: relative; overflow: hidden; cursor: pointer; padding: 10px 4px 12px; border-radius: 12px; text-align: center;
  background: var(--panel-2); border: 1px solid var(--line); transition: border-color 0.15s, transform 0.12s;
}
.cls b { display: block; font-family: var(--jp); font-weight: 400; font-size: 24px; line-height: 1.1; color: #fff; }
.cls span { display: block; font-size: 10.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cls small { display: block; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; color: var(--muted); }
.cls i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--warn); }
.cls.ok i { background: var(--chakra); } .cls.ok small { color: var(--chakra); }
.cls.done i { background: var(--ok); } .cls.done small { color: var(--ok); }
.cls:hover { transform: translateY(-2px); border-color: var(--line-2); }
.cls.sel { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc), 0 0 18px rgba(255, 122, 26, 0.3); }
body.recording .cls { pointer-events: none; }

.train-prog { margin-top: 12px; }
.train-prog .j-bar { margin-bottom: 6px; }
.train-prog .j-bar i { background: var(--acc); }
#modelInfo { line-height: 1.5; margin: 12px 0 4px; }

.bars { display: flex; flex-direction: column; gap: 5px; }
.bar-row { display: grid; grid-template-columns: 26px 92px 1fr 40px; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.bk { font-family: var(--jp); font-size: 18px; color: #fff; text-align: center; }
.bt { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.bt i { display: block; height: 100%; background: #4a5060; border-radius: 4px; }
.bp { text-align: right; font-variant-numeric: tabular-nums; }
.bar-row.top { color: var(--text); font-weight: 600; }
.bar-row.top .bt i { background: var(--acc); box-shadow: 0 0 8px var(--acc); }
