:root {
  --bg: #07050d;
  --glass: rgba(14, 10, 26, .74);
  --line: rgba(255, 255, 255, .13);
  --ink: #f4ecff;
  --dim: #b3a6cc;
  --pink: #ff2e88;
  --cyan: #27e6ff;
  --amber: #ffd23d;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --zh: "PingFang HK", "Hiragino Sans", "Noto Sans CJK TC", "Microsoft JhengHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink); overflow: hidden;
  font: 13px/1.3 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none;
}
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#stage canvas:active { cursor: grabbing; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ── top ── */
.top {
  position: fixed; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: flex-start;
  padding: max(14px, env(safe-area-inset-top)) 16px 0; pointer-events: none; z-index: 5;
}
.top > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 12px; text-shadow: 0 2px 14px rgba(0,0,0,.7); }
.brand-zh {
  font: 800 38px/1 var(--zh); color: #ffe3ef; letter-spacing: 2px;
  text-shadow: 0 0 6px var(--pink), 0 0 18px var(--pink), 0 0 36px rgba(255, 46, 136, .6);
}
.brand-en { display: grid; gap: 2px; }
.brand-en b { font: 800 14px/1 var(--mono); letter-spacing: .22em; }
.brand-en i { font-style: normal; color: var(--dim); font-size: 12px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.pill {
  padding: 8px 14px; border-radius: 999px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  font: 600 12px/1 var(--mono); letter-spacing: .03em; white-space: nowrap; transition: border-color .15s, background .15s, transform .1s;
}
.pill:hover { border-color: rgba(255,255,255,.35); }
.pill:active { transform: translateY(1px); }
.pill[aria-pressed="true"] { border-color: var(--cyan); color: var(--cyan); background: rgba(39, 230, 255, .1); }
.pill.rec { color: #ff8aa8; }
.pill.rec.live { background: #ff2e4d; color: #fff; border-color: #ff2e4d; animation: blink 1s steps(2) infinite; }
.pill.bell { color: var(--amber); }
@keyframes blink { 50% { opacity: .65; } }

/* ── dock ── */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 0 12px max(14px, env(safe-area-inset-bottom));
  display: grid; justify-items: center; gap: 10px; z-index: 5; pointer-events: none;
}
.dock > * { pointer-events: auto; }
.styles {
  display: flex; gap: 6px; padding: 6px; background: var(--glass); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.styles::-webkit-scrollbar { display: none; }
.chip {
  display: grid; justify-items: center; gap: 5px; padding: 8px 12px 7px; border-radius: 11px; min-width: 84px; flex: 0 0 auto;
  border: 1px solid transparent; transition: background .15s, border-color .15s;
}
.chip:hover { background: rgba(255,255,255,.06); }
.chip .sw { display: flex; width: 100%; height: 6px; border-radius: 3px; overflow: hidden; opacity: .9; }
.chip .sw i { flex: 1; }
.chip .nm { font: 700 11px/1 var(--mono); letter-spacing: .02em; white-space: nowrap; }
.chip .no { color: var(--dim); font-weight: 500; margin-right: 5px; }
.chip.on { background: rgba(255, 46, 136, .14); border-color: var(--pink); box-shadow: 0 0 20px rgba(255, 46, 136, .25); }
.chip.left { background: rgba(255, 46, 136, .14); border-color: var(--pink); }
.chip.right { background: rgba(39, 230, 255, .12); border-color: var(--cyan); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.seg { display: inline-flex; border-radius: 999px; background: var(--glass); border: 1px solid var(--line); padding: 3px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.seg button { padding: 6px 12px; border-radius: 999px; font: 600 12px/1 var(--mono); color: var(--dim); }
.seg button.on { background: rgba(255,255,255,.14); color: var(--ink); }
.hint { margin: 0; color: var(--dim); font: 11px/1.2 var(--mono); text-shadow: 0 1px 8px #000; text-align: center; }

/* ── split compare ── */
.handle {
  position: fixed; top: 0; bottom: 0; width: 44px; margin-left: -22px; z-index: 4; cursor: ew-resize; touch-action: none;
}
.handle span {
  position: absolute; top: 50%; left: 50%; width: 38px; height: 38px; margin: -19px 0 0 -19px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 4px rgba(255,255,255,.25), 0 6px 22px rgba(0,0,0,.5);
}
.handle span::before, .handle span::after {
  content: ""; position: absolute; top: 13px; border: 6px solid transparent;
}
.handle span::before { left: 3px; border-right-color: #1a1030; }
.handle span::after { right: 3px; border-left-color: #1a1030; }
.split-tags { position: fixed; top: 84px; left: 0; right: 0; display: flex; justify-content: space-between; padding: 0 20px; z-index: 3; pointer-events: none; }
.split-tags span { padding: 6px 10px; border-radius: 6px; background: rgba(0,0,0,.6); font: 700 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase; }
.split-tags #tag-l { color: var(--pink); }
.split-tags #tag-r { color: var(--cyan); }

/* ── bell onomatopoeia ── */
.sfx {
  position: fixed; left: 50%; top: 32%; z-index: 4; pointer-events: none; opacity: 0; transform: translate(-50%, -50%) rotate(-6deg) scale(.7);
  font: 900 clamp(34px, 8vw, 96px)/1 Impact, "Arial Black", sans-serif; letter-spacing: .03em; white-space: nowrap;
  color: var(--amber); -webkit-text-stroke: 3px #1a0b2e; paint-order: stroke fill; text-shadow: 4px 5px 0 #1a0b2e;
}
.sfx.pop { animation: pop 1.1s cubic-bezier(.2, 1.4, .4, 1) both; }
@keyframes pop {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-12deg) scale(.4); }
  14% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1.08); }
  70% { opacity: 1; transform: translate(-50%, -50%) rotate(-6deg) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -58%) rotate(-4deg) scale(1.02); }
}
body[data-style="real"] .sfx { font-family: var(--zh); font-weight: 800; color: #ffe3ef; -webkit-text-stroke: 0; text-shadow: 0 0 10px var(--pink), 0 0 30px var(--pink); }
body[data-style="blueprint"] .sfx, body[data-style="thermal"] .sfx, body[data-style="gameboy"] .sfx, body[data-style="dither"] .sfx { display: none; }
body[data-style="ukiyo"] .sfx { color: #c8321f; -webkit-text-stroke: 2px #1d1020; text-shadow: none; font-family: var(--zh); }

/* ── style overlays ── */
.ov { position: fixed; inset: 0; pointer-events: none; z-index: 2; display: none; }
body.split .ov { display: none !important; }
body[data-style="ukiyo"] .ov-ukiyo, body[data-style="blueprint"] .ov-blueprint,
body[data-style="thermal"] .ov-thermal, body[data-style="gameboy"] .ov-gameboy { display: block; }

.ov-ukiyo .seal {
  position: absolute; right: 22px; top: 90px; width: 52px; padding: 7px 0; text-align: center;
  background: #c8321f; color: #f6e8d0; font: 800 22px/1.1 var(--zh); border-radius: 3px; transform: rotate(3deg);
  box-shadow: 0 0 0 2px #7a1c10 inset;
}
.ov-ukiyo .cartouche {
  position: absolute; left: 22px; top: 96px; padding: 12px 9px; background: #efe3c6; color: #22181c;
  font: 800 20px/1.25 var(--zh); writing-mode: vertical-rl; letter-spacing: .2em; border: 3px solid #22181c;
  box-shadow: 4px 4px 0 rgba(0,0,0,.35);
}
.cartouche br { display: none; }
.ov-blueprint .dim { position: absolute; left: 50%; top: 82px; width: min(40vw, 420px); transform: translateX(-50%); height: 56px; }
.ov-blueprint .dim path { fill: none; stroke: #cfe6ff; stroke-width: 1.4; vector-effect: non-scaling-stroke; }
.ov-blueprint .dim text { fill: #cfe6ff; font: 14px var(--mono); }
.ov-blueprint .titleblock {
  position: absolute; right: 18px; bottom: 150px; padding: 10px 14px; border: 1.5px solid #cfe6ff; color: #dcecff; background: rgba(5, 30, 80, .55);
  font: 11px/1.5 var(--mono); display: grid; letter-spacing: .06em;
}
.ov-blueprint .titleblock b { font-size: 13px; letter-spacing: .14em; border-bottom: 1px solid #cfe6ff; margin-bottom: 4px; padding-bottom: 4px; }
.ov-thermal .cross { position: absolute; left: 50%; top: 50%; width: 120px; height: 120px; margin: -60px 0 0 -60px; border: 1.5px solid rgba(255,255,255,.75); border-radius: 50%; }
.ov-thermal .cross::before, .ov-thermal .cross::after { content: ""; position: absolute; background: rgba(255,255,255,.75); }
.ov-thermal .cross::before { left: 50%; top: -14px; width: 1.5px; height: 148px; }
.ov-thermal .cross::after { top: 50%; left: -14px; height: 1.5px; width: 148px; }
.ov-thermal .read { position: absolute; right: 20px; top: 88px; display: grid; justify-items: end; gap: 4px; font: 700 13px/1 var(--mono); color: #fff; text-shadow: 0 0 6px #000; }
.ov-thermal .read em { font-style: normal; color: #ff4b4b; animation: blink 1s steps(2) infinite; }
.ov-gameboy .gbtag { position: absolute; left: 20px; top: 96px; font: 800 12px/1 var(--mono); letter-spacing: .3em; color: #0f380f; background: #9bbc0f; padding: 6px 8px; }

/* ── loading / error ── */
.loading { position: fixed; inset: 0; z-index: 20; display: grid; place-content: center; justify-items: center; gap: 8px; background: var(--bg);
  font: 800 72px/1 var(--zh); color: #ffe3ef; text-shadow: 0 0 10px var(--pink), 0 0 40px var(--pink); transition: opacity .6s; }
.loading small { font: 12px var(--mono); color: var(--dim); text-shadow: none; letter-spacing: .1em; }
.loading.done { opacity: 0; pointer-events: none; }
.error { position: fixed; inset: auto 20px 120px; z-index: 30; padding: 14px 16px; background: #3a0c18; border: 1px solid #ff2e4d; border-radius: 10px; font: 12px/1.5 var(--mono); }

@media (max-width: 720px) {
  .brand-zh { font-size: 30px; }
  .brand-en i { display: none; }
  .top-actions .pill { padding: 7px 10px; }
  #btn-rec { display: none; }
  .hint { display: none; }
  .chip { min-width: 72px; padding: 7px 8px 6px; }
  .ov-blueprint .titleblock { bottom: 190px; right: 10px; font-size: 10px; }
  .ov-ukiyo .cartouche { display: none; }
}
@media (prefers-reduced-motion: reduce) { .sfx.pop { animation-duration: .01s; } }
