@font-face {
  font-family: Pretendard;
  src: local("Pretendard Variable"), local("Pretendard");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --studio-bg: #080706;
  --studio-panel: #0d0b09;
  --studio-panel-hi: #14110e;
  --studio-line: rgba(232, 199, 128, .16);
  --studio-line-hi: rgba(232, 199, 128, .52);
  --studio-gold: #e3b75b;
  --studio-ink: #eee9df;
  --studio-muted: #887e70;
  --studio-red: #e45449;
  font-family: Pretendard, "Noto Sans KR", sans-serif;
}

* { box-sizing: border-box; }

html,
body { min-height: 100%; }

body {
  margin: 0;
  color: var(--studio-ink);
  background:
    linear-gradient(90deg, rgba(227, 183, 91, .028) 1px, transparent 1px),
    linear-gradient(rgba(227, 183, 91, .022) 1px, transparent 1px),
    var(--studio-bg);
  background-size: 48px 48px;
}

button,
input,
textarea,
select { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button { cursor: pointer; }

[hidden] { display: none !important; }

.studio-head {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  height: 60px;
  padding: 0 20px;
  border-bottom: 1px solid var(--studio-line);
  background: rgba(8, 7, 6, .93);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.studio-head__back {
  justify-self: start;
  color: var(--studio-muted);
  font-size: .76rem;
  font-weight: 700;
  text-decoration: none;
}

.studio-head__back:hover,
.studio-head__back:focus-visible { color: var(--studio-gold); }

.studio-head h1 {
  margin: 0;
  color: #f1dfb7;
  font-family: "Iropke Batang", "Noto Serif KR", Georgia, serif;
  font-size: 1.05rem;
  letter-spacing: -.025em;
}

.studio-head__actions {
  display: flex;
  justify-self: end;
  align-items: center;
  gap: 7px;
}

.studio-head__live {
  margin-right: 5px;
  color: var(--studio-muted);
  font-size: .62rem;
  font-weight: 900;
  letter-spacing: .12em;
}

.studio-head__live.is-live { color: #ff665b; }

.studio-button {
  min-height: 31px;
  padding: 6px 11px;
  border: 1px solid var(--studio-line);
  border-radius: 2px;
  color: var(--studio-ink);
  background: transparent;
  font-size: .72rem;
  font-weight: 750;
}

.studio-button:hover,
.studio-button:focus-visible { border-color: var(--studio-line-hi); outline: 0; }
.studio-button:disabled { opacity: .42; cursor: default; }
.studio-button--air { border-color: rgba(228, 84, 73, .55); color: #ff8c82; }
.studio-button--air:hover,
.studio-button--air:focus-visible { background: rgba(228, 84, 73, .13); }
.studio-button--save { border-color: rgba(227, 183, 91, .6); color: #f1cd7e; background: rgba(227, 183, 91, .08); }
.studio-button--save:hover,
.studio-button--save:focus-visible { background: rgba(227, 183, 91, .15); }
.studio-button--ghost { color: var(--studio-muted); }

.studio {
  display: grid;
  grid-template-columns: minmax(170px, 12vw) minmax(480px, 1fr) minmax(280px, 19vw);
  min-height: calc(100vh - 60px);
}

.deck,
.inspector {
  min-width: 0;
  background: rgba(10, 9, 8, .82);
}

.deck {
  position: sticky;
  top: 60px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: calc(100vh - 60px);
  border-right: 1px solid var(--studio-line);
}

.deck__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 12px 10px;
  color: var(--studio-muted);
  font-size: .62rem;
  letter-spacing: .16em;
}

.deck__head span { font-variant-numeric: tabular-nums; }

.deck__list {
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  scrollbar-width: thin;
  scrollbar-color: var(--studio-line-hi) transparent;
}

.deck__slide {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) 7px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 55px;
  padding: 8px 9px;
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, .045);
  color: var(--studio-muted);
  text-align: left;
  background: transparent;
}

.deck__slide:hover { color: #cfc6b8; background: rgba(255, 255, 255, .025); }
.deck__slide.is-selected { color: var(--studio-ink); background: rgba(227, 183, 91, .065); }
.deck__slide.is-selected::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  content: "";
  background: var(--studio-gold);
}

.deck__number {
  font-size: .63rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  letter-spacing: .08em;
}

.deck__copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.deck__copy b,
.deck__copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck__copy b { font-size: .72rem; font-weight: 680; }
.deck__copy small { color: var(--studio-muted); font-size: .58rem; }
.deck__air { width: 6px; height: 6px; border-radius: 50%; background: transparent; }
.deck__slide.is-live .deck__air { background: #ed5a50; box-shadow: 0 0 9px rgba(237, 90, 80, .75); }

.deck__actions {
  display: grid;
  grid-template-columns: 32px 1fr 32px 32px 1fr;
  gap: 4px;
  padding: 9px;
  border-top: 1px solid var(--studio-line);
}

.deck__actions button {
  min-width: 0;
  min-height: 30px;
  padding: 4px 6px;
  border: 1px solid var(--studio-line);
  border-radius: 2px;
  color: var(--studio-muted);
  background: transparent;
  font-size: .66rem;
  font-weight: 700;
}

.deck__actions button:hover,
.deck__actions button:focus-visible { border-color: var(--studio-line-hi); color: var(--studio-ink); outline: 0; }

/* 알림줄, 무대 자리, 자료 띠 셋이 위에서부터 차례로 선다.
   행을 둘만 적어 두면 셋째가 암묵 행으로 밀리고, 둘째의 1fr 이 남은 높이를 통째로
   먹어 자료 띠가 화면 밖으로 내려간다. 셋 다 제 높이로 두고 남는 자리는 아래에 남긴다. */
.workbench {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  min-width: 0;
  padding: 22px clamp(18px, 2.5vw, 42px) 44px;
}

.preview-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto 11px;
  color: var(--studio-muted);
  font-size: .66rem;
}

.preview-bar > span:first-child {
  color: var(--studio-gold);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  letter-spacing: .1em;
}

.preview-bar strong {
  min-width: 0;
  overflow: hidden;
  color: #aaa092;
  font-size: .68rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#save-state.is-dirty { color: #e99a53; }

.preview {
  position: relative;
  align-self: start;
  /* 방송에 나가는 띠와 같은 1920 대 432 다. 비율이 다르면 편집기에서
     본 것과 다르게 나간다. 아래로 무대가 이어진다는 것을 보이려고
     16 대 9 짜리 무대 자리를 위에 비워 둔다. */
  aspect-ratio: 1920 / 432;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  inset: auto;
  border: 1px solid rgba(255, 255, 255, .04);
  background: #030202;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}

/* 무대 자리. 띠가 방송 화면의 아래 40퍼센트라는 것을 편집기에서도 보인다. */
.preview-stage {
  position: relative;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  aspect-ratio: 1920 / 648;
  border: 1px solid rgba(255, 255, 255, .04);
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  background:
    repeating-linear-gradient(135deg, rgba(255, 255, 255, .012) 0 12px, transparent 12px 24px),
    #050303;
}

.preview-stage::after {
  position: absolute;
  top: 50%;
  left: 50%;
  color: rgba(246, 242, 234, .17);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .22em;
  transform: translate(-50%, -50%);
  content: 무대;
}

.preview .ts-slide { animation: none; }

.inspector {
  min-width: 0;
  border-left: 1px solid var(--studio-line);
  padding: 10px 11px 50px;
}

.inspector fieldset {
  min-width: 0;
  margin: 0;
  padding: 12px 3px 15px;
  border: 0;
  border-bottom: 1px solid var(--studio-line);
}

.inspector legend {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  padding: 0 2px;
  color: var(--studio-gold);
  font-size: .65rem;
  font-weight: 850;
  letter-spacing: .1em;
}

.inspector label {
  display: grid;
  gap: 4px;
  min-width: 0;
  margin-top: 8px;
  color: var(--studio-muted);
  font-size: .61rem;
  font-weight: 700;
}

.inspector input,
.inspector textarea,
.inspector select,
.repeater input {
  min-width: 0;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .095);
  border-radius: 2px;
  outline: 0;
  color: var(--studio-ink);
  background: rgba(0, 0, 0, .28);
  font-size: .72rem;
  line-height: 1.42;
}

.inspector input,
.inspector select,
.repeater input { min-height: 32px; padding: 6px 8px; }
.inspector textarea { resize: vertical; padding: 7px 8px; }
.inspector input:focus,
.inspector textarea:focus,
.inspector select:focus,
.repeater input:focus { border-color: var(--studio-line-hi); }

.inspector__pair {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 7px;
}

.inspector__pair legend { grid-column: 1 / -1; }
.inspector__pair > label:nth-of-type(n + 3) { grid-column: 1 / -1; }

.inspector__add {
  width: 24px;
  height: 23px;
  padding: 0;
  border: 1px solid var(--studio-line);
  border-radius: 2px;
  color: var(--studio-gold);
  background: transparent;
  line-height: 1;
}

.repeater { display: grid; gap: 6px; }

.repeater__row {
  display: grid;
  grid-template-columns: minmax(0, .75fr) minmax(0, .65fr) 25px;
  gap: 4px;
}

/* 한 줄이 품은 글이 넷이다. 이름·값은 윗줄, 값 이름·세부는 아랫줄에 선다. */
.repeater__extra {
  grid-column: 1 / 3;
  display: grid;
  gap: 4px;
  padding: 0;
  border: 0;
}

.repeater__extra > summary {
  color: var(--studio-gold);
  font-size: 11px;
  letter-spacing: .04em;
  cursor: pointer;
  opacity: .72;
}

.repeater__extra > summary:hover { opacity: 1; }
.repeater__extra[open] > summary { margin-bottom: 2px; }
.repeater__extra textarea { resize: vertical; }

.repeater__tone {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--studio-ink);
  font-size: 11px;
}

.repeater__tone input { width: 12px; height: 12px; }

.repeater__remove {
  grid-column: 3;
  grid-row: 1 / span 3;
  border: 1px solid rgba(228, 84, 73, .2);
  border-radius: 2px;
  color: #bd6a63;
  background: transparent;
}

.repeater__remove:hover,
.repeater__remove:focus-visible { border-color: rgba(228, 84, 73, .55); color: #f08c83; outline: 0; }

.studio-gate {
  width: min(360px, calc(100vw - 30px));
  padding: 0;
  border: 1px solid var(--studio-line-hi);
  border-radius: 2px;
  color: var(--studio-ink);
  background: #0e0c0a;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .75);
}

.studio-gate::backdrop { background: rgba(0, 0, 0, .78); backdrop-filter: blur(7px); }
.studio-gate__card { display: grid; gap: 13px; padding: 24px; }
.studio-gate h2 { margin: 0 0 4px; color: #f1dfb7; font-family: "Iropke Batang", "Noto Serif KR", Georgia, serif; font-size: 1.2rem; }
.studio-gate label { display: grid; gap: 6px; color: var(--studio-muted); font-size: .7rem; font-weight: 700; }
.studio-gate input { min-height: 39px; padding: 7px 10px; border: 1px solid var(--studio-line); border-radius: 2px; outline: 0; color: var(--studio-ink); background: #070605; letter-spacing: .12em; text-transform: uppercase; }
.studio-gate input:focus { border-color: var(--studio-line-hi); }
.studio-gate p { margin: 0; color: #e58c84; font-size: .72rem; }
.studio-gate a { justify-self: center; color: var(--studio-muted); font-size: .68rem; text-decoration: none; }

.studio-toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  z-index: 100;
  transform: translateX(-50%);
  padding: 9px 15px;
  border: 1px solid var(--studio-line-hi);
  border-radius: 2px;
  color: var(--studio-ink);
  background: rgba(13, 11, 9, .96);
  box-shadow: 0 12px 34px rgba(0, 0, 0, .55);
  font-size: .72rem;
}

.studio-toast.is-error { border-color: rgba(228, 84, 73, .48); color: #f0a39b; }

@media (max-width: 1120px) {
  .studio { grid-template-columns: 170px minmax(0, 1fr); }
  .inspector { grid-column: 1 / -1; border-top: 1px solid var(--studio-line); border-left: 0; padding: 14px clamp(18px, 5vw, 64px) 50px; }
  .deck { height: calc(100vh - 60px); }
}

@media (max-width: 700px) {
  .studio-head { grid-template-columns: 1fr auto; height: auto; min-height: 56px; padding: 10px 12px; }
  .studio-head h1 { display: none; }
  .studio-head__actions { gap: 4px; }
  .studio-head__live { display: none; }
  .studio-button { padding: 6px 8px; }
  .studio { grid-template-columns: 1fr; }
  .deck { position: static; grid-template-rows: auto auto auto; height: auto; border-right: 0; border-bottom: 1px solid var(--studio-line); }
  .deck__list { display: flex; overflow-x: auto; padding: 0 7px 7px; }
  .deck__slide { grid-template-columns: 24px 132px 7px; flex: 0 0 auto; min-height: 48px; border: 1px solid var(--studio-line); }
  .deck__actions { grid-template-columns: 32px 1fr 32px 32px 1fr; }
  .workbench { padding: 16px 10px 28px; }
  .inspector { grid-column: 1; padding: 10px 12px 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .001ms !important; animation-duration: .001ms !important; }
}

/* 방송 표시등. 상태와 번호를 기호로 잇지 않고 두 칸으로 나눈다.
   상태는 작고 흐린 대문자, 번호는 크고 밝은 숫자. 층위가 눈에 먼저 잡힌다. */
.studio-head__live {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.studio-head__live-label { letter-spacing: .14em; }

.studio-head__live-number {
  color: #f4ece0;
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

/* ── 미리보기에서 바로 고치기 ─────────────────────────────────
   나갈 화면 그 자리에서 글자를 고치고 줄을 끌어 옮긴다. 표시는 평소에 거의
   보이지 않다가 손이 닿는 자리에만 뜬다. 편집 중에도 방송 화면의 판짜임이
   그대로 보여야 하므로 테두리는 판 밖으로 밀어 그린다. */

.preview [data-ts-edit] {
  outline: 1px solid transparent;
  outline-offset: 2px;
  border-radius: 3px;
  cursor: text;
  transition: outline-color 120ms ease, background-color 120ms ease;
}

.preview [data-ts-edit]:hover {
  outline-color: rgba(232, 199, 128, .34);
  background: rgba(232, 199, 128, .05);
}

.preview [data-ts-edit]:focus {
  outline: 2px solid var(--studio-gold);
  background: rgba(232, 199, 128, .09);
}

/* 빈 칸은 잡을 자리가 없어진다. 최소 폭을 남겨 둔다. */
.preview [data-ts-edit]:empty::before {
  content: '비어 있음';
  opacity: .38;
}

/* 끌어 옮기는 손잡이. 줄 왼쪽 바깥에 서서 판짜임을 밀지 않는다. */
.preview [data-ts-index] {
  position: relative;
}

.preview .ts-grip {
  position: absolute;
  z-index: 3;
  top: 50%;
  left: -22px;
  width: 20px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(-50%);
  border-radius: 4px;
  color: rgba(232, 199, 128, .5);
  background: rgba(12, 10, 8, .82);
  font-size: 15px;
  line-height: 1;
  cursor: grab;
  opacity: 0;
  transition: opacity 120ms ease, color 120ms ease;
}

.preview [data-ts-index]:hover .ts-grip,
.preview .ts-grip:focus-visible { opacity: 1; }

.preview .ts-grip:hover { color: #f6dfa8; }
.preview .ts-grip:active { cursor: grabbing; }

.preview [data-ts-index].is-dragging { opacity: .4; }

/* 놓일 자리. 줄과 줄 사이에 금 한 줄을 긋는다. */
.preview .is-drop-before::after,
.preview .is-drop-after::after {
  content: '';
  position: absolute;
  z-index: 4;
  right: -6px;
  left: -26px;
  height: 2px;
  border-radius: 2px;
  background: var(--studio-gold);
  box-shadow: 0 0 10px rgba(227, 183, 91, .7);
}

.preview .is-drop-before::after { top: -1px; }
.preview .is-drop-after::after { bottom: -1px; }

/* 지표 칸은 가로로 서므로 금도 세로로 세운다. */
.preview .ts-slide__metrics .is-drop-before::after,
.preview .ts-slide__metrics .is-drop-after::after {
  top: -4px;
  bottom: -4px;
  right: auto;
  left: auto;
  width: 2px;
  height: auto;
}

.preview .ts-slide__metrics .is-drop-before::after { left: -5px; }
.preview .ts-slide__metrics .is-drop-after::after { right: -5px; }

/* 지표 칸의 손잡이는 칸 위쪽에 눕는다. 왼쪽에는 자리가 없다. */
.preview .ts-metric .ts-grip {
  top: -4px;
  left: 50%;
  width: 26px;
  height: 18px;
  transform: translate(-50%, 0);
}
