:root {
  --bg: #0b0d12;
  --panel: #151922;
  --panel2: #1d2330;
  --line: #2a3142;
  --fg: #e8ecf4;
  --muted: #8b93a7;
  --accent: #39ff14;
  --danger: #ff4d6d;
  --c: #39ff14;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}
button:active { transform: scale(.97); }
button.primary { background: var(--accent); color: #031a00; border-color: var(--accent); font-weight: 700; }
button.ghost { background: transparent; }
button.danger { color: var(--danger); border-color: var(--danger); }
button.block { width: 100%; margin-top: 10px; border-style: dashed; }
input[type=text], select {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  min-width: 0;
}
input[type=color] { width: 56px; height: 40px; padding: 2px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; }
input[type=range] { flex: 1; min-width: 0; accent-color: var(--accent); height: 32px; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; gap: 10px;
}
.top h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 10px; }
.top h1 small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.logo { border-radius: 8px; flex: none; }
.top-actions { display: flex; gap: 8px; flex: none; }
.top-actions button { white-space: nowrap; }
.top h1 { min-width: 0; }
.top h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout { flex: 1; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); min-height: 0; }
.stage-wrap { padding: 0 14px 12px; }

/* ===== 전광판 ===== */
.stage {
  position: relative;
  height: clamp(170px, 32dvh, 340px);
  background: #000;
  border-radius: 16px;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.text {
  position: absolute; left: 0; top: 0;
  line-height: 1.15;
  white-space: nowrap;
  will-change: transform, opacity;
  font-family: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  pointer-events: none;
}
.board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.frame, .sparkle { position: absolute; inset: 0; pointer-events: none; }
.dots {
  display: none;
  background-image: radial-gradient(circle at center, transparent 0 38%, var(--stage-bg, #000) 62%);
  background-size: 7px 7px;
  opacity: .28;
}
.stage.has-dots .dots { display: block; }
.frame { display: none; margin: 6px; border: 7px dotted var(--c); border-radius: 12px; opacity: .9; filter: drop-shadow(0 0 6px var(--c)); }
.stage.has-frame .frame { display: block; }
.sparkle { display: none; }
.stage.has-sparkle .sparkle {
  display: block;
  background-image:
    radial-gradient(2px 2px at 10% 20%, #fff, transparent),
    radial-gradient(2px 2px at 30% 70%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 55% 35%, #fff, transparent),
    radial-gradient(2px 2px at 75% 80%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 90% 15%, #fff, transparent),
    radial-gradient(2px 2px at 45% 90%, #fff, transparent);
  animation: twinkle 1.6s ease-in-out infinite alternate;
}
@keyframes twinkle { from { opacity: .15; } to { opacity: .9; } }

.stage.live {
  position: fixed; inset: 0; z-index: 100;
  height: auto; border-radius: 0;
}
.live-bar {
  position: absolute; left: 0; right: 0; top: 0;
  display: flex; flex-direction: column; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 16px;
  background: linear-gradient(rgba(0,0,0,.8), transparent);
  z-index: 5;
}
.live-row { display: flex; gap: 8px; align-items: center; }
.live-row .spacer { flex: 1; }
.live-timer { color: #ddd; font-size: 13px; font-variant-numeric: tabular-nums; }
.live-row.sliders label { flex: 1; display: flex; gap: 8px; align-items: center; font-size: 12px; color: #ddd; min-width: 0; }
.live-row.sliders input { flex: 1; min-width: 0; }
.stage.live.rot90 { inset: auto; top: 0; left: 100%; transform-origin: 0 0; transform: rotate(90deg); }
.live-bar[hidden], .toast[hidden] { display: none; }
.live-bar button { background: rgba(30,30,30,.85); }

/* ===== 패널 ===== */
.panel {
  background: var(--panel);
  border-top-left-radius: 20px; border-top-right-radius: 20px;
  display: flex; flex-direction: column; min-height: 0; min-width: 0;
}
.tabs { display: flex; padding: 8px; gap: 6px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: transparent; border: 0; padding: 10px 4px; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--accent); font-weight: 700; }
.pane { display: none; padding: 14px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.pane.active { display: block; }
h3 { font-size: 13px; color: var(--muted); margin: 16px 0 8px; font-weight: 600; }
h3:first-child { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row > input[type=text] { flex: 1; }
.row.check { gap: 12px; min-height: 44px; }
.row.range output { width: 36px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; margin: 10px 0 0; line-height: 1.5; }

.emoji-bar { scrollbar-width: none; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.emoji-bar button { flex: none; font-size: 22px; padding: 4px 8px; min-height: 44px; min-width: 44px; background: transparent; border-color: transparent; }
.emoji-bar .tok { font-size: 20px; }
.emoji-bar .dot-icon { color: var(--accent); font-size: 20px; }
.row.between { justify-content: space-between; margin: 4px 0 8px; }
.item-wrap { display: flex; flex-direction: column; gap: 6px; }
.item-opts { padding-left: 44px; }
.item-opts[hidden] { display: none; }
.item-opts { display: flex; flex-direction: column; gap: 6px; }
.item-opts select, .item-opts input { width: 100%; }
.item .mini.on { border-color: var(--accent); color: var(--accent); }
.tpl-bar button.mine { border-color: var(--accent); color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled { opacity: .45; cursor: default; }
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; gap: 6px; align-items: center; }
.item input[type=text] { flex: 1; }
.item .dot { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 3px solid var(--panel2); position: relative; }
.item { gap: 4px; }
.item input[type=color] { width: 40px; flex: none; }
.item .mini { min-width: 34px; padding: 8px 0; flex: none; }

.tpl-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: none; }
.tpl-bar button { flex: none; white-space: nowrap; border-radius: 20px; padding: 8px 14px; }
.lang-sel { min-height: 44px; padding: 8px 10px; }
.modal { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 18px; text-align: center; max-width: 320px; width: 100%; }
.modal-card h2 { font-size: 16px; margin: 0 0 12px; }
.modal-card canvas { background: #fff; padding: 8px; border-radius: 8px; width: 240px; height: 240px; image-rendering: pixelated; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; padding: 0; border: 3px solid var(--panel2); }
.swatch.sel { border-color: #fff; }
.effect-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-bottom: 8px; }
.effect-grid button { text-align: center; line-height: 1.3; }
.effect-grid button.sel { border-color: var(--accent); color: var(--accent); background: rgba(57,255,20,.08); }
.effect-grid .ico { display: block; font-size: 20px; }
.preset-list { display: flex; flex-direction: column; gap: 6px; }
.preset { display: flex; gap: 6px; align-items: center; }
.preset .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.foot {
  flex: none;
  min-height: 52px;
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 11px;
  line-height: 1.6;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 20px; z-index: 200; font-size: 14px;
}

/* ===== 태블릿 / 가로 ===== */
@media (min-width: 768px) {
  .layout { grid-template-rows: none; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); height: calc(100dvh - 64px - 52px); }
  .stage-wrap { padding: 0 8px 14px 14px; display: flex; }
  .stage { flex: 1; height: auto; min-height: 170px; }
  .panel { border-radius: 20px 0 0 0; margin: 0 0 0 6px; }
  .top h1 { font-size: 20px; }
}
@media (max-height: 480px) and (orientation: landscape) and (max-width: 767px) {
  .layout { grid-template-rows: none; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); height: calc(100dvh - 60px - 52px); }
  .stage-wrap { display: flex; padding-bottom: 8px; }
  .stage { flex: 1; height: auto; min-height: 120px; }
}

/* 좁은 휴대폰 화면: 상단 바를 한 줄로 유지 */
@media (max-width: 420px) {
  .top { padding: 8px 10px; gap: 6px; }
  .top h1 { font-size: 16px; gap: 6px; }
  .top h1 .logo { width: 26px; height: 26px; }
  .top-actions { gap: 6px; }
  .top-actions button, .lang-sel { padding: 8px 10px; font-size: 14px; }
  .lang-sel { padding-right: 4px; }
}
@media (max-width: 340px) {
  .top h1 span { display: none; }
}
