:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --text: #22201c;
  --muted: #77716a;
  --border: #ddd7ce;
  --accent: #b08a3a;
  --stage-bg: #111216;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --panel: #212228;
    --text: #ecebe8;
    --muted: #9b978f;
    --border: #36373f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Noto Sans KR", "Malgun Gothic", sans-serif;
}

/* 페이지 전체는 창 높이에 딱 맞추고 스크롤하지 않는다. 스크롤은 설정판 안에서만 한다. */
html, body { height: 100%; }
body { overflow: hidden; }
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
  align-content: center; /* 창이 그림보다 키가 크면 위아래 여백을 반씩 */
  min-height: 100%;
  gap: 16px;
  padding: 16px;
}

/* 무대 그림은 비율 그대로 칸 너비·창 높이 안에서 가장 크게 그리고(크기는 app.js의 sizeStage),
   설정판 높이를 그 그림 높이에 맞춘다. 그래서 둘의 위아래가 나란하고 빈 띠가 없다. */
.stage-wrap {
  position: relative;
  min-width: 0;
  display: flex;
  justify-content: center;
}

#stage {
  display: block;
  border-radius: 8px;
}

.stage-wrap:fullscreen { cursor: pointer; background: #000; }
.stage-wrap:fullscreen { align-items: center; }
.stage-wrap:fullscreen #stage { border-radius: 0; width: 100% !important; height: 100% !important; object-fit: contain; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 16px 16px;
  overflow-y: auto;
  min-height: 0;
  /* 얇고 둥근 스크롤바 */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  scrollbar-gutter: stable;
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-track { background: transparent; margin: 8px 0; }
.panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; border: 3px solid var(--panel); }
.panel::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* 재생 · 처음으로 · 전체 화면은 설정판을 내려도 늘 위에 */
.panel-top {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 -16px;
  padding: 16px 16px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.panel-top .row { margin: 0; }

.panel h2 { font-size: 15px; margin: 20px 0 8px; }
.panel h3.sub { font-size: 13px; margin: 14px 0 4px; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.buttons button { flex: 1; }

button {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
}
#play { background: var(--accent); border-color: var(--accent); color: #fff; }

.hint { color: var(--muted); font-size: 12px; margin: 4px 0 0; }
.status { margin: 8px 0 0; font-weight: 600; }
.warn { margin: 6px 0 0; color: #c0392b; font-size: 12px; font-weight: 600; }
.panel select { max-width: 100%; }
button:disabled { opacity: 0.5; cursor: default; }

/* sticky도 녹화 중 표시(absolute)의 기준이 된다 */
.recording {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

.line { border: 1px solid var(--border); border-radius: 6px; margin: 0 0 10px; padding: 8px 10px; }
.line textarea { width: 100%; resize: vertical; font: inherit; }
.line select { flex: 1; }

input[type="number"] { width: 58px; }
.seal-text { width: 44px; text-align: center; }
#sealRow[hidden] { display: none; }
input[type="color"] { width: 36px; height: 28px; padding: 0; border: none; background: none; }

/* ?t= 캡처 모드에서는 무대만 보이게 한다 */
body.capture .layout { display: block; padding: 0; height: auto; }
body.capture .panel { display: none; }
body.capture .stage-wrap { border-radius: 0; }
body.capture #stage { width: 100% !important; height: auto !important; border-radius: 0; }

@media (max-width: 860px) {
  /* 좁은 화면에서는 위아래로 쌓고 페이지가 스크롤한다 */
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .panel { overflow: visible; height: auto !important; }
}

/* 연출 시간 슬라이더: 이름 · 슬라이더 · 지금 값 한 줄 */
.slider { display: grid; grid-template-columns: 112px 1fr 44px; align-items: center; gap: 8px; margin: 6px 0; }
.slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.seg { gap: 4px; }
.seg-label { width: 112px; color: var(--text); }
.seg label { flex: 1; position: relative; } /* 숨긴 선택 칸이 이 안에 머물게(밖 기준이면 페이지가 늘어난다) */
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span:not(.seg-label) { color: var(--text); display: block; text-align: center; padding: 6px 0; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); cursor: pointer; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.slider output { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* 설명은 툴팁(title)으로만 둔다. 제목 옆 「?」는 마우스를 올리면 설명이 뜬다는 표시 */
[title] { cursor: help; }
button[title], select[title], input[title] { cursor: pointer; }
.tip { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--border); color: var(--muted); font-size: 11px; font-weight: 600; margin-left: 4px; vertical-align: 1px; }
.muted { color: var(--muted); font-size: 12px; }
.note { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

/* 배경 투명을 켜면 무대 밑에 바둑판 무늬를 깔아 투명한 자리를 보여 준다 */
.stage-wrap.transparent #stage {
  background-color: #ffffff;
  background-image: linear-gradient(45deg, #d9d9d9 25%, transparent 25%), linear-gradient(-45deg, #d9d9d9 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d9d9d9 75%), linear-gradient(-45deg, transparent 75%, #d9d9d9 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
.stage-wrap.transparent:fullscreen #stage { background: none; }

/* hidden 속성이 display 규칙에 밀리지 않게 */
[hidden] { display: none !important; }

/* 수상자 목록 */
.roster { width: 100%; resize: vertical; font: inherit; }
.roster-nav { justify-content: space-between; }
.roster-nav button { width: 44px; }
.winner-now { flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.three button { flex: 1; padding-left: 4px; padding-right: 4px; }
.roster.dragover { outline: 2px dashed var(--accent); outline-offset: 2px; }

/* 봉투 고르기 — 미리 만든 봉투를 그림으로 보여 주는 가로 넘김 */
.carousel { display: flex; align-items: center; gap: 4px; margin: 6px 0 0; }
.car-track { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scroll-behavior: smooth; scrollbar-width: none; flex: 1; padding: 4px 2px; }
.car-track::-webkit-scrollbar { display: none; }
.car-nav { flex: 0 0 28px; height: 56px; padding: 0; font-size: 20px; line-height: 1; }
.preset-card { flex: 0 0 calc(50% - 4px); scroll-snap-align: start; display: flex; flex-direction: column; gap: 4px; padding: 4px; border: 2px solid transparent; border-radius: 8px; background: var(--bg); color: var(--text); cursor: pointer; }
.preset-card canvas { width: 100%; height: auto; border-radius: 5px; display: block; }
.preset-card span { font-size: 11px; line-height: 1.3; text-align: center; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 2.6em; }
.preset-card.selected { border-color: var(--accent); }
.preset-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.preset-name { margin: 2px 0 6px; text-align: center; }
