/* nguoc.vn — studio màn hình nền */
.studio-body {
  background: #efede6;
  color: var(--ink);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
.st-head {
  flex: 0 0 auto;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.st-back {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.st-back:hover { background: var(--olive-050); color: var(--olive-700); }

.st-brand { display: flex; flex-direction: column; line-height: 1; padding-right: 14px; border-right: 1px solid var(--line); }
.st-brand__name { font-family: var(--font-script); font-size: 22px; }
.st-brand__sub { font-size: 8px; letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink-faint); margin-top: 2px; }

.st-title { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.st-title b { font-size: 14px; font-weight: 600; }
.st-title span { font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.st-head__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.st-save { font-size: 11.5px; color: var(--olive-700); background: var(--olive-050); padding: 5px 10px; border-radius: 999px; }

/* ---------- body ---------- */
.st-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 72px 340px minmax(0, 1fr);
}

.st-rail {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.st-tab {
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 9px 2px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.st-tab svg { width: 20px; height: 20px; }
.st-tab:hover { background: #f4f3ee; color: var(--ink); }
.st-tab.is-active { background: var(--olive-050); color: var(--olive-700); }

.st-panel {
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.st-pane { display: none; padding: 18px 18px 40px; }
.st-pane.is-active { display: block; }

.st-pane__head { margin-bottom: 16px; }
.st-pane__head h2 { font-size: 17px; letter-spacing: -0.01em; }
.st-pane__head p { margin: 6px 0 0; font-size: 12.5px; color: var(--ink-soft); line-height: 1.55; }

.st-group { margin-bottom: 16px; }
.st-group--row { display: flex; align-items: center; }
.st-label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 7px; }
.st-hint { font-weight: 400; color: var(--ink-faint); font-size: 11px; }

.st-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
}
.st-input:focus { border-color: rgba(105, 123, 85, 0.6); box-shadow: 0 0 0 3px rgba(105, 123, 85, 0.12); outline: none; }
.st-input--mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; }
textarea.st-input { resize: vertical; line-height: 1.5; }

.st-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.st-two + .st-range { margin-top: 12px; }

.st-range { display: block; margin: 0 0 14px; }
.st-range span { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; }
.st-range b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.st-range input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.st-range input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: #e2e0d8; }
.st-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: var(--olive);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
.st-range input[type="range"]::-moz-range-track { height: 4px; border-radius: 999px; background: #e2e0d8; }
.st-range input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--olive); border: 2px solid #fff; }

.st-seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.st-seg button {
  text-align: left;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.st-seg button b { display: block; font-size: 12.5px; font-weight: 600; }
.st-seg button span { display: block; font-size: 11px; color: var(--ink-faint); line-height: 1.4; margin-top: 3px; }
.st-seg button.is-active { border-color: var(--olive); background: var(--olive-050); }
.st-seg button.is-active span { color: var(--olive-700); }

.st-switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.st-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.st-switch__track {
  position: relative;
  flex: 0 0 auto;
  width: 38px; height: 22px;
  border-radius: 999px;
  background: #dcdad2;
  transition: background 0.18s ease;
  margin-top: 1px;
}
.st-switch__track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s ease;
}
.st-switch input:checked + .st-switch__track { background: var(--olive); }
.st-switch input:checked + .st-switch__track::after { transform: translateX(16px); }
.st-switch input:focus-visible + .st-switch__track { box-shadow: var(--ring); }
.st-switch__label { font-size: 12.5px; font-weight: 600; }
.st-switch__label small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-faint); margin-top: 2px; line-height: 1.4; }

.st-swatches { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.st-swatches button {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 10.5px;
  color: var(--ink-soft);
  cursor: pointer;
}
.st-swatches button i {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08) inset;
}
.st-swatches button.is-active { border-color: var(--olive); background: var(--olive-050); color: var(--olive-700); font-weight: 600; }

.st-ratios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.st-ratios button {
  padding: 9px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.st-ratios button small { display: block; font-size: 10px; font-weight: 400; color: var(--ink-faint); margin-top: 2px; }
.st-ratios button.is-active { border-color: var(--olive); background: var(--olive-050); color: var(--olive-700); }

.st-note { font-size: 11.5px; color: var(--ink-faint); line-height: 1.5; margin: 10px 0 0; }

.st-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* template grid */
.st-filters { display: grid; gap: 8px; margin-bottom: 12px; }
.chips--sm .chip { padding: 6px 11px; font-size: 11.5px; }
.search--sm { min-width: 0; }
.search--sm input { padding: 8px 12px 8px 34px; font-size: 12.5px; }

.st-tplgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tplcard {
  position: relative;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #f4f2ec;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.tplcard:hover { transform: translateY(-2px); border-color: rgba(105, 123, 85, 0.5); }
.tplcard img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; display: block; }
.tplcard b { display: block; font-size: 11px; font-weight: 600; padding: 6px 7px 7px; line-height: 1.3; }
.tplcard.is-active { border-color: var(--olive); box-shadow: 0 0 0 2px rgba(105, 123, 85, 0.25); }
.tplcard.is-active::after {
  content: "✓";
  position: absolute;
  top: 5px; right: 5px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--olive);
  color: #fff;
  font-size: 11px;
  display: grid;
  place-items: center;
}

.st-qr { display: flex; gap: 14px; align-items: center; }
.st-qr__box { flex: 0 0 auto; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
.st-qr__box canvas, .st-qr__box img { display: block; width: 118px; height: 118px; }

/* per-line typography */
.st-styles { display: grid; gap: 8px; }
.st-style {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 6px 8px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fcfbf7;
}
.st-style b { font-size: 11.5px; font-weight: 600; grid-row: span 2; }
.st-input--sm { padding: 6px 9px; font-size: 12px; border-radius: 9px; }
.st-style input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 16px; background: transparent; }
.st-style input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 999px; background: #e2e0d8; }
.st-style input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 13px; height: 13px; margin-top: -5px; border-radius: 50%; background: var(--olive); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); }

/* ---------- stage ---------- */
.st-stagewrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #e7e5dd;
  padding: 16px 16px 0;
  overflow: hidden;
}
.st-stage {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.st-canvas {
  position: relative;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 16 / 9;
  max-width: calc(100% - 8px);
  border-radius: 12px;
  overflow: hidden;
  background: #0b0d09;
  box-shadow: 0 24px 60px -30px rgba(20, 24, 16, 0.65);
  transform-origin: center;
}
.st-canvas canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.st-txt { pointer-events: none; z-index: 2; }
.st-tint { position: absolute; inset: 0; pointer-events: none; opacity: 0; mix-blend-mode: soft-light; z-index: 1; }
.st-fx { z-index: 0; }
.st-fallback[hidden] { display: none !important; }
.st-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #111;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  text-align: center;
  padding: 20px;
}
.st-fallback img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0.45; }
.st-fallback span { position: relative; z-index: 1; max-width: 240px; line-height: 1.5; }

.st-stagebar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px 12px;
  color: var(--ink-soft);
  font-size: 12px;
}
.st-stagebar__left, .st-stagebar__right { display: flex; align-items: center; gap: 10px; }
.st-iconbtn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(36, 39, 31, 0.12);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.st-iconbtn:hover { background: var(--olive-050); color: var(--olive-700); }
.st-iconbtn svg { width: 15px; height: 15px; }
.st-ratio-pill { font-size: 11.5px; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* fullscreen */
.st-stagewrap:fullscreen { background: #000; padding: 0; }
.st-stagewrap:fullscreen .st-canvas { border-radius: 0; max-width: none; width: 100% !important; height: 100% !important; aspect-ratio: auto; }
.st-stagewrap:fullscreen .st-stagebar { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.45); padding: 6px 10px; border-radius: 999px; color: #fff; opacity: 0; transition: opacity 0.2s; }
.st-stagewrap:fullscreen:hover .st-stagebar { opacity: 1; }
.st-stagewrap:fullscreen .st-iconbtn { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: rgba(255, 255, 255, 0.2); }

/* play mode (link trình chiếu) */
body.is-play .st-head,
body.is-play .st-rail,
body.is-play .st-panel,
body.is-play .st-stagebar { display: none; }
body.is-play .st-body { grid-template-columns: 1fr; }
body.is-play .st-stagewrap { padding: 0; background: #000; }
body.is-play .st-canvas { border-radius: 0; max-width: none; width: 100vw !important; height: 100vh !important; aspect-ratio: auto; box-shadow: none; }

/* toast + modal */
.st-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  background: #24271f;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 12.5px;
  z-index: 80;
  box-shadow: 0 16px 40px -20px rgba(0, 0, 0, 0.6);
}
.st-modal[hidden] { display: none; }
.st-toast[hidden] { display: none; }
.st-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 23, 17, 0.55);
  backdrop-filter: blur(6px);
}
.st-modal__box {
  position: relative;
  width: min(520px, 100%);
  background: #fff;
  border-radius: 22px;
  padding: 26px 22px 22px;
  box-shadow: 0 40px 80px -40px rgba(0, 0, 0, 0.6);
}
.st-modal__box h3 { font-size: 18px; margin-bottom: 6px; }
.st-modal__box p { font-size: 13px; margin: 0 0 14px; }
.st-modal__close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  display: grid; place-items: center;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .st-body { grid-template-columns: 64px 300px minmax(0, 1fr); }
  .st-save { display: none; }
}
@media (max-width: 860px) {
  .st-head { gap: 8px; padding: 0 10px; height: 54px; }
  .st-title { display: none; }
  .st-brand { padding-right: 8px; }
  .st-brand__name { font-size: 19px; }
  .st-head__actions .btn--ghost { display: none; }
  .st-head__actions .btn--sm { padding: 9px 14px; font-size: 12.5px; }
  .st-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }
  .st-rail {
    order: 1;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 6px;
  }
  .st-tab { min-width: 64px; padding: 7px 2px; }
  .st-stagewrap { order: 2; padding: 8px 8px 0; }
  .st-panel {
    order: 3;
    position: static;
    max-height: 44dvh;
    overflow-y: auto;
    border-right: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -10px 24px -24px rgba(0, 0, 0, 0.5);
  }
  .st-pane { padding: 14px 14px 28px; }
  .st-tplgrid { grid-template-columns: repeat(3, 1fr); }
  .st-stagebar { padding: 8px 2px 10px; }
}

/* ---------- font picker (thư viện nhiều font) ---------- */
.fp { position: relative; }
.fp > select { display: none; }
.fp-btn {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 30px 9px 11px;
  font: inherit;
  font-size: 14px;
  color: inherit;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fp-btn::after {
  content: '';
  position: absolute;
  right: 11px;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -5px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  opacity: 0.5;
}
.fp-panel {
  position: fixed;
  z-index: 40;
  left: 0;
  right: 0;
  top: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 18px 40px -18px rgba(28, 34, 22, 0.4);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
}
.fp-panel[hidden] { display: none; }
.fp-search {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
}
.fp-list {
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: -2px;
  padding: 2px;
}
.fp-row {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 9px;
  font-size: 16px;
  line-height: 1.25;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-row:hover { background: #f4f2e9; }
.fp-row.is-active { background: #eae7d8; font-weight: 600; }
.fp-row[hidden] { display: none; }
@media (max-width: 900px) {
  .fp-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 12px;
    max-height: 60dvh;
  }
}
