:root {
  color-scheme: light;
  --bg: #f5f6f1;
  --surface: #ffffff;
  --surface-muted: #eef3f6;
  --text: #182027;
  --muted: #63717d;
  --line: #d8e0e5;
  --accent: #1f7a68;
  --accent-dark: #125c4d;
  --danger: #b42318;
  --shadow: 0 18px 48px rgba(24, 32, 39, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 122, 104, 0.12), transparent 42%),
    linear-gradient(315deg, rgba(28, 77, 123, 0.12), transparent 36%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

button:hover {
  background: var(--accent-dark);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.app-shell {
  min-height: 100vh;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

label {
  display: block;
  margin-bottom: 8px;
  color: #2e3b45;
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 260px;
  resize: vertical;
  padding: 14px;
  line-height: 1.6;
}

textarea[readonly] {
  background: var(--surface-muted);
  color: var(--muted);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.16);
}

.workspace {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

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

.topbar h1 {
  font-size: clamp(2rem, 5vw, 4rem);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.ghost-button:hover,
.secondary-button:hover {
  background: var(--surface-muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  align-items: start;
}

.control-panel,
.output-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 12px 32px rgba(24, 32, 39, 0.08);
}

.control-panel {
  padding: 22px;
}

.output-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  position: sticky;
  top: 20px;
}

.field {
  margin-bottom: 18px;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.label-row label {
  margin-bottom: 0;
}

.field-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.mode-row {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.mode-option {
  margin: 0;
  cursor: pointer;
  position: relative;
}

.mode-option input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.mode-option span {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.mode-option input:checked + span {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 4px rgba(24, 32, 39, 0.12);
}

.ssml-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.script-block-editor {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.script-group-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.script-selector-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(3, auto);
  gap: 10px;
  align-items: end;
}

.script-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.script-duration-box {
  min-width: 112px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.script-duration-box span,
.script-block-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.script-duration-box strong {
  display: block;
  margin-top: 4px;
  font-size: 1.2rem;
}

.timeline-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.timeline-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.timeline-head h2 {
  font-size: 1rem;
}

.timeline-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.5;
}

.timeline-scale {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.timeline-waveform {
  overflow-x: auto;
  padding-bottom: 4px;
}

.timeline-track {
  display: flex;
  align-items: stretch;
  width: max-content;
  min-width: 100%;
  min-height: 62px;
  border-radius: 8px;
  background: linear-gradient(to right, rgba(216, 224, 229, 0.7) 1px, transparent 1px);
  background-size: 120px 100%;
  overflow: hidden;
}

.timeline-segment small {
  position: absolute;
  left: 8px;
  bottom: 5px;
  color: var(--muted);
  font-size: 0.72rem;
}

.timeline-speech,
.timeline-pause {
  min-width: 22px;
  min-height: 62px;
  border-radius: 0;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}

.timeline-speech {
  display: flex;
  align-items: end;
  background: rgba(31, 122, 104, 0.14);
  border: 1px solid rgba(31, 122, 104, 0.24);
}

.timeline-speech > span {
  position: absolute;
  left: 8px;
  top: 7px;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 900;
}

.wave-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
  height: 100%;
  padding: 8px 6px 6px;
}

.wave-bars span {
  flex: 1;
  min-width: 2px;
  max-width: 8px;
  border-radius: 999px;
  background: var(--accent);
  opacity: 0.82;
}

.timeline-pause {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.script-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.script-toolbar h2 {
  font-size: 1rem;
}

.script-toolbar p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.script-blocks {
  display: grid;
  gap: 12px;
}

.script-block {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.script-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.script-block-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.script-block-grid {
  display: grid;
  grid-template-columns: 1.2fr repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.script-block textarea {
  min-height: 84px;
}

.ssml-toolbar button,
.mini-button,
.icon-text-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
}

.ssml-toolbar button:hover,
.mini-button:hover,
.icon-text-button:hover {
  background: var(--surface-muted);
}

.icon-text-button:disabled {
  cursor: not-allowed;
}

.hint-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.settings-grid .field {
  margin-bottom: 0;
}

.settings-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.settings-panel h2 {
  font-size: 1rem;
}

.actions {
  display: flex;
  gap: 12px;
}

.actions button {
  flex: 1;
  min-width: 0;
  padding: 0 18px;
}

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

.metric-box {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric-box span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.metric-box strong {
  display: block;
  font-size: 1.5rem;
  line-height: 1;
}

.pricing-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.pricing-note a {
  color: var(--accent-dark);
  font-weight: 800;
}

.panel-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.tab-button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-button:hover,
.tab-button.active {
  background: #fff;
  color: var(--text);
}

.tab-panel {
  display: grid;
  gap: 16px;
}

.status-box {
  min-height: 124px;
  padding: 16px;
  border-radius: 8px;
  background: var(--surface-muted);
}

.status-box h2 {
  margin-bottom: 10px;
  font-size: 1.1rem;
}

.status-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.help-panel {
  color: var(--muted);
  line-height: 1.6;
}

.help-panel section {
  display: grid;
  gap: 8px;
}

.help-panel h2 {
  color: var(--text);
  font-size: 1rem;
}

.help-panel ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.help-panel p {
  margin: 0;
}

.help-panel code {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 1px 5px;
  font-size: 0.86em;
  white-space: normal;
}

audio {
  width: 100%;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.debug-output {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #101820;
  color: #f4f7f9;
  white-space: pre-wrap;
}

@media (max-width: 880px) {
  .content-grid,
  .settings-grid,
  .script-block-grid,
  .script-selector-row {
    grid-template-columns: 1fr;
  }

  .output-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .workspace {
    width: min(100% - 20px, 1180px);
    padding: 18px 0;
  }

  .topbar,
  .actions,
  .script-toolbar,
  .script-toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .label-row,
  .mode-row {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-row {
    display: flex;
  }

  .control-panel,
  .output-panel {
    padding: 18px;
  }
}
