:root {
  --bg: #f3f4f8;
  --card: #ffffff;
  --ink: #1b1f2a;
  --muted: #687083;
  --line: #e3e6ee;
  --accent: #3d63ff;
  --accent-ink: #ffffff;
  --accent-soft: #e8edff;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --emo: #8a94a6;
  --stage-base: #e9ecf4;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 6px 20px rgba(16, 24, 40, .07);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1117;
    --card: #161a23;
    --ink: #e8ebf2;
    --muted: #949cb0;
    --line: #2a303d;
    --accent: #7090ff;
    --accent-ink: #0b0e14;
    --accent-soft: #1f2a4a;
    --stage-base: #151922;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.5; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 15px; margin: 0; display: inline; }
h2 small { color: var(--muted); font-weight: 500; font-size: 12px; }
h3 { font-size: 12.5px; margin: 14px 0 6px; color: var(--muted); }
small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.muted { color: var(--muted); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
[hidden] { display: none !important; }

/* ── 상단 ── */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { font-size: 28px; color: var(--accent); }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-status { font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 999px; background: var(--line); color: var(--muted); white-space: nowrap; }
.chip-status.on { background: #dcfce7; color: #166534; }
.chip-status.warn { background: #fef3c7; color: #92400e; }
@media (prefers-color-scheme: dark) {
  .chip-status.on { background: #14532d; color: #bbf7d0; }
  .chip-status.warn { background: #713f12; color: #fde68a; }
}

/* ── 레이아웃 ── */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; padding: 16px; max-width: 1600px; margin: 0 auto; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; padding: 12px 16px; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

/* ── 무대 ── */
.stage { padding: 12px; display: grid; gap: 10px; position: sticky; top: 12px; }
@media (max-width: 1000px) { .stage { position: static; } }
.avatar-canvas {
  position: relative; height: min(72vh, 760px); min-height: 380px; border-radius: 14px; overflow: hidden;
  background:
    radial-gradient(60% 55% at 50% 42%, color-mix(in srgb, var(--emo) 38%, transparent) 0%, transparent 70%),
    radial-gradient(120% 90% at 50% 10%, color-mix(in srgb, var(--stage-base) 70%, white 30%) 0%, var(--stage-base) 75%);
  transition: background .6s;
}
@media (prefers-color-scheme: dark) {
  .avatar-canvas { background: radial-gradient(60% 55% at 50% 42%, color-mix(in srgb, var(--emo) 32%, transparent) 0%, transparent 70%), radial-gradient(120% 90% at 50% 10%, #262c3a 0%, var(--stage-base) 75%); }
}
.avatar-canvas canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.avatar-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 16px; white-space: pre-line; }
.busy { position: absolute; top: 12px; right: 12px; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--accent); color: var(--accent-ink); animation: pulse 1s infinite alternate; }
@keyframes pulse { from { opacity: .55 } to { opacity: 1 } }

.emo-panel {
  position: absolute; left: 14px; top: 14px; width: min(300px, calc(100% - 28px)); padding: 12px 14px; border-radius: 16px;
  background: color-mix(in srgb, var(--card) 84%, transparent); backdrop-filter: blur(10px); box-shadow: var(--shadow);
  border: 1px solid var(--line); border-left: 6px solid var(--emo); transition: border-color .4s;
}
.emo-main { display: flex; align-items: center; gap: 12px; }
.emo-emoji { font-size: 46px; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,.15)); }
.emo-label { font-size: 24px; font-weight: 900; letter-spacing: -.5px; }
.emo-conf { font-size: 12px; color: var(--muted); }
.emo-top { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 4px; }
.emo-top:empty { display: none; }
.emo-top li { display: grid; grid-template-columns: 22px 64px 1fr 38px; gap: 6px; align-items: center; font-size: 12px; }
.emo-top .t { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; }
.emo-top .t i { display: block; height: 100%; border-radius: 99px; }
.emo-top .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

.caption {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); max-width: min(560px, calc(100% - 300px));
  padding: 8px 16px; border-radius: 14px; background: color-mix(in srgb, var(--ink) 80%, transparent); color: var(--card);
  font-size: 14px; font-weight: 500; text-align: center; box-shadow: var(--shadow);
}
@media (max-width: 700px) { .caption { max-width: calc(100% - 28px); bottom: auto; top: 50%; } }
.overlay-warn { position: absolute; right: 14px; top: 14px; padding: 6px 12px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 12px; font-weight: 600; }
.pip { position: absolute; right: 14px; bottom: 14px; width: clamp(140px, 24%, 260px); aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); border: 2px solid var(--card); background: #000; }
.pip video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.pip-label, .rec { position: absolute; top: 6px; font-size: 11px; color: #fff; background: rgba(0,0,0,.5); padding: 1px 8px; border-radius: 99px; }
.pip-label { left: 8px; }
.rec { right: 8px; background: rgba(220, 38, 38, .85); }

.hud-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; font-size: 13px; }
.hud-grid > div { background: var(--bg); border-radius: 10px; padding: 7px 10px; display: flex; gap: 6px; min-width: 0; }
.hud-grid span { color: var(--muted); white-space: nowrap; }
.hud-grid b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 560px) { .hud-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; font-size: 12px; color: var(--muted); }
.meter { display: block; height: 8px; border-radius: 99px; background: var(--line); position: relative; overflow: hidden; margin-top: 4px; }
.meter i { position: absolute; top: 0; bottom: 0; left: 0; width: 0; background: var(--accent); border-radius: 99px; transition: all .4s; }
.meter.diverge::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--muted); }

/* ── 패널 ── */
.panel { display: grid; gap: 12px; min-width: 0; }
.block { padding: 14px 16px; display: grid; gap: 10px; }
.block-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
details.block summary { cursor: pointer; list-style: none; }
details.block summary::-webkit-details-marker { display: none; }
details.block summary h2::after { content: " ▾"; color: var(--muted); }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary[aria-pressed="true"] { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.level { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: var(--good); transition: width .06s; }

.switch { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; cursor: pointer; font-size: 13.5px; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch > span { width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; margin-top: 1px; }
.switch > span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-row { display: flex; gap: 8px 14px; flex-wrap: wrap; align-items: center; }
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; cursor: pointer; }

.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.seg-btn { flex: 1; border: none; background: transparent; color: var(--muted); padding: 6px 10px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 600; font-size: 13px; }
.seg-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

.text-form { display: flex; gap: 8px; }
.text-form input { flex: 1; min-width: 0; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.text-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.slider { display: grid; gap: 2px; font-size: 12.5px; color: var(--muted); }
.slider output { color: var(--ink); font-weight: 700; }
input[type=range] { width: 100%; accent-color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 4px 10px; border-radius: 999px; font: inherit; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.emotion-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 6px; }
.emotion-grid button {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 7px 2px 6px; cursor: pointer; font: inherit; font-size: 12px;
  color: var(--ink); display: grid; justify-items: center; gap: 1px; border-bottom: 3px solid var(--c); transition: transform .1s;
}
.emotion-grid button:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--c) 12%, var(--card)); }
.emotion-grid button.active { background: color-mix(in srgb, var(--c) 22%, var(--card)); border-color: var(--c); }
.emotion-grid .e { font-size: 24px; line-height: 1.15; }

.bars { display: grid; gap: 3px; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 38px; gap: 8px; align-items: center; font-size: 11.5px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-row .track { height: 7px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; }
.log { list-style: none; padding: 0; margin: 0; display: grid; gap: 5px; max-height: 240px; overflow: auto; }
.log li { display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: var(--bg); border-radius: 10px; font-size: 12px; }
.log .e { font-size: 18px; }

.lat-badge { position: absolute; right: 12px; top: 46px; padding: 5px 12px; border-radius: 999px; font-size: 13px;
  background: color-mix(in srgb, var(--card) 85%, transparent); border: 1px solid var(--line); box-shadow: var(--shadow); font-variant-numeric: tabular-nums; }
.lat-badge b { font-size: 15px; }
.lat-badge span { color: var(--muted); font-size: 12px; }
.danger-btn { border-color: #dc2626; color: #dc2626; text-decoration: none; }
.danger-btn:hover { background: #dc2626; color: #fff; }

/* ── 모드 선택 / 안내 / 글쓰기 ── */
.mode-switch { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 14px; border: 1px solid var(--line); }
.mode-btn { display: flex; align-items: center; gap: 10px; border: none; background: transparent; color: var(--muted); padding: 8px 14px; border-radius: 11px; cursor: pointer; font: inherit; text-align: left; }
.mode-btn b { color: inherit; font-size: 14px; }
.mode-btn small { font-size: 11.5px; }
.mode-btn.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); outline: 2px solid var(--accent); }
.mi { font-size: 26px; line-height: 1; }
@media (max-width: 760px) { .mode-switch { width: 100%; } .mode-btn { flex: 1; padding: 8px; } .mode-btn small { display: none; } }

.steps { list-style: none; margin: 0 auto; padding: 10px 16px 0; max-width: 1600px; display: flex; gap: 8px 20px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.steps li { display: flex; align-items: center; gap: 6px; }
.steps b { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: 12px; }
.kbd { font-weight: 700; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }

.stage .avatar-canvas { height: min(62vh, 680px); }
.type-box { display: grid; gap: 6px; }
.type-box label { font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.type-box label small { display: inline; }
.type-box textarea {
  width: 100%; resize: vertical; font: inherit; font-size: 16px; line-height: 1.5; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.type-box textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.type-meta { display: flex; justify-content: space-between; font-size: 12px; }

.mode-card { gap: 12px; }
.mode-now { display: flex; gap: 12px; align-items: center; }
.mode-now b { font-size: 16px; }
.btn.big { width: 100%; padding: 13px; font-size: 16px; border-radius: 12px; }
.status-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.status-list li { display: flex; align-items: center; gap: 8px; }
.status-list small { display: inline; margin-left: auto; }
.status-list .level { flex: 1; margin-left: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 25%, transparent); }
.dot.busy { background: var(--accent); animation: pulse .8s infinite alternate; }
.dot.warn { background: var(--warn); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(560px, calc(100% - 32px)); background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 10; font-size: 13px; }
.toast.error { background: var(--bad); color: #fff; }
