:root {
  --ink: #1d211d;
  --muted: #72776f;
  --paper: #f4f1ea;
  --card: #fbfaf6;
  --line: #dedbd2;
  --green: #245c48;
  --green-soft: #dbe8dd;
  --orange: #f09a5b;
  --shadow: 0 1px 1px rgb(29 33 29 / 4%), 0 12px 36px rgb(29 33 29 / 5%);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 4%, rgb(255 255 255 / 66%), transparent 24rem),
    var(--paper);
}

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

button, a, input[type="range"], input[type="checkbox"] { -webkit-tap-highlight-color: transparent; }

.topbar {
  height: 74px;
  padding: 0 clamp(22px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgb(29 33 29 / 8%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  letter-spacing: -.02em;
}

.brand-mark {
  position: relative;
  width: 30px;
  height: 30px;
  display: inline-block;
  transform: rotate(45deg);
}

.brand-mark i {
  position: absolute;
  inset: 2px 14px 14px 2px;
  border-radius: 100% 0 0;
  background: var(--green);
}

.brand-mark i:last-child { inset: 14px 2px 2px 14px; background: var(--orange); }

.top-actions, .connection { display: flex; align-items: center; }
.top-actions { gap: 16px; }
.connection { gap: 8px; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: .02em; }
.connection i, .live-pill i { width: 7px; height: 7px; border-radius: 50%; background: #c19242; box-shadow: 0 0 0 3px rgb(193 146 66 / 12%); }
.connection.online i, .live-pill:not(.waiting) i { background: #4b9b68; box-shadow: 0 0 0 3px rgb(75 155 104 / 12%); }
.connection.offline i { background: #ba554d; }

.icon-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  font: 600 13px Georgia, serif;
}

.workspace {
  max-width: 1480px;
  margin: 0 auto;
  padding: clamp(30px, 4vw, 64px);
  display: grid;
  grid-template-columns: minmax(480px, 1.45fr) minmax(390px, .82fr);
  gap: clamp(30px, 4vw, 68px);
  align-items: start;
}

.editor-panel { position: sticky; top: 30px; min-width: 0; }
.panel-heading { display: flex; justify-content: space-between; gap: 24px; align-items: end; margin-bottom: 22px; }
.eyebrow { margin: 0 0 7px; text-transform: uppercase; color: var(--green); font-size: 10px; font-weight: 750; letter-spacing: .16em; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; letter-spacing: -.035em; margin: 0; }
h1 { font-size: clamp(36px, 4vw, 58px); line-height: .98; }
h2 { font-size: 24px; }
.script-meta { display: flex; gap: 14px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.script-meta span + span::before { content: "·"; margin-right: 14px; }

.editor-shell {
  position: relative;
  min-height: 600px;
  height: calc(100vh - 245px);
  max-height: 850px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 4px 20px 20px 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-shell::before {
  content: "";
  position: absolute;
  left: 0;
  top: 38px;
  bottom: 38px;
  width: 3px;
  background: var(--orange);
  border-radius: 0 3px 3px 0;
  z-index: 1;
}

textarea {
  width: 100%;
  height: 100%;
  padding: 44px clamp(34px, 5vw, 68px) 72px;
  border: 0;
  outline: 0;
  resize: none;
  color: #292c28;
  background: transparent;
  font: 400 clamp(20px, 2vw, 27px)/1.62 Georgia, "Times New Roman", serif;
  caret-color: var(--orange);
}

textarea::placeholder { color: #aaa99f; }
.save-status { position: absolute; right: 20px; bottom: 16px; font-size: 11px; color: var(--muted); opacity: 0; transition: opacity .2s; }
.save-status.show { opacity: 1; }
.preview-panel { position: absolute; inset: 0; display: none; overflow: hidden; border-radius: inherit; background: radial-gradient(circle at 50% 42%, #343530, #191b18 72%); }
.preview-device { position: absolute; inset: 0; overflow: hidden; border-radius: inherit; background: #050505; }
.preview-device iframe { width: 100%; height: 100%; display: block; border: 0; pointer-events: none; }
.preview-caption { position: absolute; z-index: 2; left: 50%; bottom: 14px; transform: translateX(-50%); color: rgb(255 255 255 / 48%); font-size: 8px; font-weight: 750; letter-spacing: .14em; text-transform: uppercase; }
.editor-panel.previewing .preview-panel { display: block; }
.editor-panel.previewing textarea, .editor-panel.previewing .save-status { visibility: hidden; }
.editor-panel.previewing .editor-actions { visibility: hidden; }
.editor-footer { min-height: 42px; padding: 9px 4px; display: flex; justify-content: space-between; align-items: center; gap: 20px; color: var(--muted); font-size: 11px; }
.editor-actions { display: flex; align-items: center; gap: 7px; }
.editor-actions > span { width: 1px; height: 16px; margin: 0 3px; background: var(--line); }
.text-button { border: 0; padding: 0; background: transparent; color: var(--green); font-size: 11px; font-weight: 700; cursor: pointer; }
.format-button { height: 27px; padding: 0 9px; border: 1px solid var(--line); border-radius: 6px; color: #5d625b; background: #f7f5ef; font-size: 9px; font-weight: 700; cursor: pointer; }
.format-button:hover { color: var(--green); border-color: #bbcbbf; background: #f0f4ef; }
.emphasis-button { width: 28px; padding: 0; font: 700 12px Georgia, serif; }
.view-toggle { display: flex; padding: 3px; border-radius: 8px; background: #e8e5dd; }
.view-toggle button { min-width: 65px; padding: 6px 10px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; font-size: 9px; font-weight: 700; cursor: pointer; }
.view-toggle button.active { color: var(--ink); background: var(--card); box-shadow: 0 1px 4px rgb(29 33 29 / 12%); }

.control-panel { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; min-width: 0; }
.card { min-width: 0; max-width: 100%; padding: 26px; background: rgb(251 250 246 / 82%); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.card-title-row, .settings-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.live-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid #d9e5da; border-radius: 999px; color: var(--green); background: #f3f8f3; font-size: 9px; font-weight: 750; text-transform: uppercase; letter-spacing: .1em; }
.live-pill.waiting { color: #80642d; border-color: #e8dcc4; background: #fbf6ea; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.6; }
.share-grid { display: grid; grid-template-columns: 104px 1fr; gap: 15px; align-items: center; margin: 17px 0; }
.qr-code { width: 104px; height: 104px; display: grid; place-items: center; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.qr-code:empty::before { content: "Preparing…"; color: var(--muted); font-size: 9px; }
.qr-code svg { width: 100%; height: 100%; display: block; }
.share-copy strong, .share-copy span { display: block; }
.share-copy strong { margin-bottom: 6px; color: var(--ink); font-size: 11px; }
.share-copy span { color: var(--muted); font-size: 10px; line-height: 1.55; }
.url-box { display: flex; align-items: center; margin: 18px 0 13px; border: 1px solid var(--line); border-radius: 9px; background: #f1efe8; overflow: hidden; }
.url-box code { flex: 1; min-width: 0; padding: 13px 14px; color: #41453f; font: 600 12px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.url-box button { flex: 0 0 45px; height: 42px; border: 0; border-left: 1px solid var(--line); background: transparent; cursor: pointer; }
.url-box svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.open-link { color: var(--green); font-size: 11px; font-weight: 700; text-decoration: none; }
.open-link span { display: inline-block; margin-left: 3px; }
.share-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

.transport { padding: 28px 28px 24px; }
.transport-top { display: flex; justify-content: center; align-items: center; gap: clamp(8px, 2vw, 15px); }
.round-control, .play-control, .stepper { display: grid; place-items: center; border-radius: 50%; cursor: pointer; }
.round-control { width: 42px; height: 42px; border: 1px solid var(--line); background: transparent; }
.round-control:hover, .stepper:hover { background: #f0eee7; }
.round-control svg { width: 17px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.play-control { width: 66px; height: 66px; border: 0; color: white; background: var(--green); box-shadow: 0 8px 20px rgb(36 92 72 / 22%); }
.play-control:hover { background: #194d3a; }
.play-control svg { width: 25px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.play-control .play-icon { fill: currentColor; stroke: none; margin-left: 3px; }
.pause-icon, .is-playing .play-icon { display: none; }
.is-playing .pause-icon { display: block; }

.progress-wrap { margin-top: 27px; }
.progress-labels, .range-labels { display: flex; justify-content: space-between; margin-top: 7px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .09em; }
input[type="range"] { --value: 0%; width: 100%; height: 3px; display: block; margin: 0; border-radius: 999px; appearance: none; background: linear-gradient(to right, var(--green) var(--value), #d8d6cf var(--value)); cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { width: 14px; height: 14px; border: 3px solid var(--card); border-radius: 50%; appearance: none; background: var(--green); box-shadow: 0 0 0 1px var(--green); }
input[type="range"]::-moz-range-thumb { width: 10px; height: 10px; border: 3px solid var(--card); border-radius: 50%; background: var(--green); box-shadow: 0 0 0 1px var(--green); }

.speed-block { margin-top: 27px; padding-top: 23px; border-top: 1px solid var(--line); }
.setting-label { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 15px; color: #474b45; font-size: 11px; font-weight: 650; }
.setting-label strong { color: var(--green); font: 500 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.stepper-row { display: flex; align-items: center; gap: 12px; }
.stepper { flex: 0 0 29px; height: 29px; border: 1px solid var(--line); background: transparent; font-size: 17px; }

.settings { display: grid; gap: 25px; }
.control-group { display: block; }
.segmented-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.small-label { display: block; margin-bottom: 9px; color: var(--muted); font-size: 10px; font-weight: 650; }
.segmented { display: flex; padding: 3px; border-radius: 8px; background: #edebe4; }
.segmented button { flex: 1; padding: 8px 6px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 10px; cursor: pointer; }
.segmented button.active { color: var(--ink); background: var(--card); box-shadow: 0 1px 4px rgb(29 33 29 / 10%); }
.toggle-list { border-top: 1px solid var(--line); }
.orientation-tip { margin: 16px 0 2px; padding: 10px 12px; border-radius: 8px; color: #666c64; background: #f0eee7; font-size: 9px; line-height: 1.5; }
.toggle-list label { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle-list label:last-child { border-bottom: 0; padding-bottom: 0; }
.toggle-list strong, .toggle-list small { display: block; }
.toggle-list strong { font-size: 11px; }
.toggle-list small { margin-top: 4px; color: var(--muted); font-size: 9px; }
input[type="checkbox"] { position: relative; width: 34px; height: 19px; flex: 0 0 auto; appearance: none; border-radius: 999px; background: #cccac3; cursor: pointer; transition: background .2s; }
input[type="checkbox"]::after { content: ""; position: absolute; width: 15px; height: 15px; left: 2px; top: 2px; border-radius: 50%; background: white; box-shadow: 0 1px 3px rgb(0 0 0 / 20%); transition: transform .2s; }
input[type="checkbox"]:checked { background: var(--green); }
input[type="checkbox"]:checked::after { transform: translateX(15px); }

dialog { width: min(420px, calc(100vw - 32px)); padding: 34px; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); background: var(--card); box-shadow: 0 28px 80px rgb(29 33 29 / 25%); }
dialog::backdrop { background: rgb(29 33 29 / 36%); backdrop-filter: blur(3px); }
.dialog-close { position: absolute; right: 18px; top: 14px; border: 0; background: transparent; font: 300 25px/1 sans-serif; cursor: pointer; }
dialog dl { margin: 25px 0 0; }
dialog dl div { display: flex; justify-content: space-between; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
dialog dd { margin: 0; padding: 3px 8px; border: 1px solid var(--line); border-radius: 5px; background: #efede6; font: 600 10px ui-monospace, monospace; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; padding: 11px 17px; border-radius: 999px; color: white; background: var(--ink); font-size: 11px; box-shadow: 0 10px 30px rgb(0 0 0 / 18%); opacity: 0; transform: translate(-50%, 10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .editor-panel { position: static; }
  .editor-shell { min-height: 520px; height: 65vh; }
}

@media (max-width: 560px) {
  .topbar { height: 62px; padding: 0 18px; }
  .workspace { padding: 28px 16px 48px; gap: 26px; }
  .panel-heading { align-items: start; flex-direction: column; }
  h1 { font-size: 40px; }
  .editor-shell { min-height: 440px; }
  textarea { padding: 30px 27px 60px; font-size: 20px; }
  .editor-footer { align-items: stretch; flex-direction: column; gap: 10px; }
  .editor-footer > span { display: none; }
  .editor-actions { flex-wrap: wrap; }
  .view-toggle { align-self: stretch; }
  .view-toggle button { flex: 1; }
  .card { padding: 22px; }
  .transport-top { gap: 7px; }
  .round-control { width: 38px; height: 38px; }
  .play-control { width: 58px; height: 58px; }
  .segmented-row { grid-template-columns: 1fr; }
}
