:root {
  --bg: #0e0e12;
  --panel: #17171d;
  --line: #2a2a33;
  --text: #f3f3f6;
  --muted: #9a9aa6;
  --accent: #ff5c8a;
  --accent-ink: #fff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: var(--text);
  background: #25252e;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
}
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ── 무대 ── */
#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
#view {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
#view.mirror { transform: scaleX(-1); }

#topbar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
}
#topbar button { background: rgba(0,0,0,.5); backdrop-filter: blur(6px); padding: 6px 10px; font-size: 13px; }
body:not(.editing) #topbar { display: none; }

#faceHint, #status {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.65);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  text-align: center;
  max-width: calc(100% - 32px);
}
#status { top: auto; bottom: 48px; transform: translateX(-50%); z-index: 3; }

#disclaimer {
  position: absolute;
  left: 0; right: 0; bottom: 8px;
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: rgba(255,255,255,.6);
  pointer-events: none;
}
body:not(.editing) #disclaimer { display: none; }

#start {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  text-align: center;
  background: radial-gradient(circle at 50% 30%, #3a1f2b, var(--bg) 70%);
}
#start h1 { font-size: clamp(24px, 6vw, 34px); line-height: 1.3; margin: 0 0 4px; }
#start p { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
#start button { width: min(280px, 100%); padding: 14px; }

/* ── 패널 ── */
#panel {
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
body:not(.editing) #panel { display: none; }

#tabs { display: flex; gap: 6px; overflow-x: auto; }
#tabs button { flex: 1; padding: 8px 10px; border-radius: 999px; white-space: nowrap; }
#tabs button.active { background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600; }

#controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 34dvh;
  overflow-y: auto;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
  font-size: 14px;
}
.slider output { color: var(--accent); font-variant-numeric: tabular-nums; font-size: 13px; }
.slider input { grid-column: 1 / -1; width: 100%; accent-color: var(--accent); margin: 2px 0 4px; }

.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border-radius: 999px; padding: 10px 16px; transition: transform .08s; }
.chip:active { transform: scale(.94); }
.chip.ghost { background: transparent; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

#toast {
  position: absolute;
  left: 50%;
  top: 56px;
  transform: translateX(-50%);
  z-index: 3;
  width: max-content;
  max-width: calc(100% - 32px);
  background: rgba(0,0,0,.72);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  text-align: center;
  pointer-events: none;
}
#toast.show { animation: toast-in .18s ease-out; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -6px); } }
.note { color: var(--muted); font-size: 12px; margin: 4px 0 0; }

#actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }
#actions button { padding: 12px 6px; font-size: 14px; user-select: none; touch-action: none; }
#holdBtn.pressed { background: var(--text); color: var(--bg); }

/* ── 견적 ── */
dialog {
  width: min(420px, calc(100% - 32px));
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog ul { list-style: none; padding: 0; margin: 0; }
dialog li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
dialog li small { color: var(--muted); margin-left: 4px; }
dialog li.empty { color: var(--muted); justify-content: center; }
dialog .total { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 0 4px; }
dialog .total strong { font-size: 20px; color: var(--accent); }
dialog button { width: 100%; margin-top: 8px; }

/* ── 넓은 화면: 패널을 오른쪽으로 ── */
@media (min-width: 900px) {
  #app { flex-direction: row; }
  #panel { width: 360px; border-top: 0; border-left: 1px solid var(--line); padding-top: 16px; }
  #controls { max-height: none; flex: 1; }
}
