:root {
  --bg: #171814;
  --panel: #23251f;
  --panel-2: #2d3028;
  --line: #45483d;
  --text: #f4f0e5;
  --muted: #b8b29f;
  --accent: #f4b85a;
  --blue: #81a8ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button,
.file-button,
.download-link {
  border: 1px solid var(--line);
  background: #303329;
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  text-decoration: none;
}

button:hover,
.file-button:hover,
.download-link:hover {
  border-color: var(--accent);
}

button.active {
  background: #4a3820;
  border-color: var(--accent);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: 100vh;
}

.stage-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 18px;
}

.top-bar {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 15px;
}

.file-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.file-button input {
  display: none;
}

.download-link {
  display: none;
}

.download-link.ready {
  display: inline-flex;
}

.preview-frame {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 420px;
  border: 1px solid var(--line);
  background:
    linear-gradient(45deg, #20221c 25%, transparent 25%),
    linear-gradient(-45deg, #20221c 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #20221c 75%),
    linear-gradient(-45deg, transparent 75%, #20221c 75%);
  background-size: 28px 28px;
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
  border-radius: 8px;
  overflow: hidden;
}

#previewCanvas {
  width: min(100%, calc((100vh - 150px) * 16 / 9));
  max-height: calc(100vh - 150px);
  aspect-ratio: 16 / 9;
  background: #0d0e0b;
}

#sourceVideo {
  display: none;
}

.transport {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-top: 12px;
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.control-panel {
  height: 100vh;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
  padding: 16px;
}

.panel-section {
  padding: 14px;
  margin-bottom: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

label {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

input[type="number"],
input[type="password"],
input[type="text"],
input[type="url"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191b16;
  color: var(--text);
  padding: 8px 9px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.45;
}

input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #191b16;
}

#applySegmentButton {
  width: 100%;
  margin-top: 12px;
}

#aiAnalyzeButton {
  width: 100%;
  margin-top: 12px;
}

#aiAnalyzeButton:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ai-result {
  min-height: 42px;
  max-height: 220px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid #57513f;
  border-radius: 6px;
  background: #171914;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.cue-info {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #57513f;
  border-radius: 6px;
  background: #1b1d18;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.cue-info strong {
  color: var(--accent);
  font-size: 13px;
}

.segment-card {
  display: grid;
  gap: 4px;
  padding: 9px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #1b1d18;
  color: var(--muted);
  font-size: 12px;
  text-align: left;
}

.segment-card strong {
  color: var(--text);
}

.segment-card small {
  line-height: 1.45;
}

.segment-card.active-segment {
  border-color: var(--accent);
  background: #312719;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-panel {
    height: auto;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .top-bar,
  .file-controls {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .top-bar {
    flex-direction: column;
  }
}
