:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #68756f;
  --line: #dfe8e4;
  --panel: #ffffff;
  --page: #f7faf8;
  --green: #167a4a;
  --green-dark: #0f5f38;
  --green-soft: #eaf6ef;
  --orange: #d97828;
  --blue: #3266c7;
  --danger: #b92f2f;
  --shadow: 0 16px 40px rgba(28, 66, 49, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(103, 214, 154, 0.16), transparent 34%),
    linear-gradient(180deg, #ffffff 0%, var(--page) 38%, #edf5f0 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #9bb0a6;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button.primary {
  color: #fff;
  border-color: var(--green-dark);
  background: linear-gradient(135deg, var(--green), #20a060);
  box-shadow: 0 10px 18px rgba(22, 122, 74, 0.18);
}

.studio {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand img {
  width: 76px;
  height: 50px;
  border-radius: 16px;
  object-fit: cover;
  box-shadow: var(--shadow);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2,
label {
  font-size: 16px;
  font-weight: 700;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.status {
  max-width: 42vw;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.status.error {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(560px, 0.95fr) minmax(620px, 1.05fr);
  gap: 20px;
  align-items: stretch;
}

.editor,
.preview {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor {
  display: grid;
  grid-template-rows: auto minmax(560px, 1fr) auto;
}

.panelHeader {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.compactControls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.compactControls input {
  width: 220px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 560px;
  resize: vertical;
  border: 0;
  outline: none;
  padding: 16px;
  color: var(--ink);
  background: #fbfdfc;
  line-height: 1.55;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  flex: 0 0 auto;
}

.segmented button {
  border: 0;
  border-radius: 0;
  min-width: 118px;
}

.segmented button.active {
  color: #fff;
  background: var(--blue);
}

.preview {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  height: min(820px, calc(100vh - 118px));
  min-height: 680px;
}

#segmentCount {
  color: var(--muted);
  font-size: 14px;
}

.lessonMeta {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.lessonMeta strong {
  line-height: 1.3;
}

.lessonMeta span {
  color: var(--orange);
  font-weight: 700;
}

.playbackPanel {
  display: grid;
  grid-template-columns: minmax(250px, 0.75fr) minmax(360px, 1.25fr);
  gap: 16px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdfc, var(--green-soft));
}

.speedControl,
.voicePanel {
  min-width: 0;
}

.controlLabel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.controlLabel label,
.voiceRow label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

#globalSpeedValue {
  color: var(--green-dark);
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.speedPresets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.speedPresets button {
  min-height: 32px;
  padding: 0 8px;
  font-size: 13px;
}

.speedPresets button.active {
  color: #fff;
  border-color: var(--green-dark);
  background: linear-gradient(135deg, var(--green), #20a060);
  box-shadow: 0 10px 18px rgba(22, 122, 74, 0.18);
}

.voicePanel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.voiceRow {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.voiceRow input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  color: var(--ink);
  background: #fff;
}

.progress {
  height: 5px;
  background: #e8eeee;
}

#progressBar {
  width: 0%;
  height: 100%;
  background: var(--green);
  transition: width 160ms ease;
}

.segmentList {
  overflow: auto;
  padding: 12px;
  background: #fbfdfc;
}

.segment {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 112px;
  align-items: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.segment + .segment {
  margin-top: 8px;
}

.segment.active {
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
  background: #f8fffb;
}

.index {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--green-dark);
  font-size: 13px;
  font-weight: 700;
}

.segmentText {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.segmentText p {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.mini {
  min-height: 32px;
  padding: 0 10px;
  color: var(--blue);
}

.segmentActions {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.segmentActions select {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  color: var(--ink);
  background: #fff;
}

@media (max-width: 1280px) {
  .studio {
    padding: 18px;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .preview {
    height: auto;
    min-height: 620px;
  }
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status {
    max-width: 100%;
    text-align: left;
  }

  .segmented {
    width: 100%;
    margin-left: 0;
  }

  .segmented button {
    min-width: 0;
  }

  .compactControls {
    width: 100%;
  }

  .compactControls input {
    width: 100%;
  }

  .panelHeader {
    align-items: stretch;
    flex-direction: column;
  }

  .playbackPanel {
    grid-template-columns: 1fr;
  }

  .voicePanel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .segment {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .segmentActions {
    grid-column: 2;
    grid-template-columns: 1fr 1fr;
  }

  .voicePanel {
    grid-template-columns: 1fr;
  }
}
