:root {
  --paper: #eef2f0;
  --ink: #161b19;
  --muted: #66736f;
  --line: #cdd8d4;
  --panel: #fbfcf9;
  --graphite: #222927;
  --green: #176b57;
  --lime: #c8f24a;
  --amber: #b85f27;
  --red: #b23b3b;
  --shadow: 0 18px 60px rgba(36, 36, 36, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(36, 36, 36, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(36, 36, 36, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  font-family: "Microsoft YaHei", "Segoe UI", sans-serif;
}

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

.shell {
  min-height: 100vh;
  padding: 28px;
}

.workbench {
  width: min(1360px, 100%);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(28px, 4vw, 54px);
  line-height: 0.95;
}

h2 {
  font-size: 18px;
}

.status-pill {
  min-width: 112px;
  border: 1px solid var(--graphite);
  background: var(--lime);
  padding: 9px 14px;
  text-align: center;
  font-weight: 800;
  box-shadow: 5px 5px 0 var(--graphite);
}

.status-pill.is-error {
  background: #ffd5d0;
}

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.52fr);
  gap: 16px;
}

.panel {
  border: 1px solid var(--graphite);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.editor-panel {
  min-height: 680px;
}

.control-panel {
  min-height: 520px;
}

.result-panel {
  min-height: 360px;
}

.history-panel {
  min-height: 360px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 15px 16px;
}

.editor-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.history-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.segmented-control {
  display: inline-flex;
  border: 1px solid var(--graphite);
  background: #ffffff;
}

.segmented-button {
  border: 0;
  border-right: 1px solid var(--graphite);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  padding: 5px 10px;
}

.segmented-button:last-child {
  border-right: 0;
}

.segmented-button.is-active {
  background: var(--green);
  color: #ffffff;
}

.file-button,
.ghost-button,
.primary-button,
.download-button {
  border: 1px solid var(--graphite);
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.file-button {
  display: inline-flex;
  align-items: center;
  background: #ffffff;
  padding: 8px 12px;
  font-weight: 800;
}

.file-button input {
  display: none;
}

.ghost-button {
  background: transparent;
  padding: 5px 10px;
}

.primary-button {
  width: 100%;
  margin-top: 12px;
  background: var(--graphite);
  color: #fbfcf9;
  padding: 13px 14px;
  font-weight: 900;
}

.primary-button:disabled {
  cursor: wait;
  background: #5c5a53;
}

.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  background: #ffffff;
  padding: 10px 12px;
  font-weight: 800;
}

.file-button:hover,
.ghost-button:hover,
.primary-button:hover,
.download-button:hover {
  transform: translate(-2px, -2px);
  box-shadow: 4px 4px 0 var(--graphite);
}

.download-button.disabled {
  pointer-events: none;
  color: var(--muted);
  background: #ece6d7;
  border-color: var(--line);
}

textarea {
  width: 100%;
  min-height: 570px;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 18px;
  background: #fbfcf9;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.8;
}

.text-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  color: var(--muted);
}

.is-error {
  color: var(--red) !important;
}

.control-panel {
  padding-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
  padding: 13px 16px 0;
}

.field span {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.provider-toggle {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.provider-toggle label {
  display: grid;
  gap: 3px;
  min-height: 64px;
  border: 1px solid var(--graphite);
  background: #ffffff;
  padding: 8px 9px;
  cursor: pointer;
  transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.provider-toggle label:has(input:checked) {
  background: var(--lime);
  box-shadow: 4px 4px 0 var(--graphite);
}

.provider-toggle label:hover {
  transform: translate(-1px, -1px);
}

.provider-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.provider-toggle b {
  font-size: 13px;
}

.provider-toggle small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.provider-field[hidden] {
  display: none;
}

.delivery-toggle label {
  display: grid;
  gap: 3px;
  min-height: 74px;
  border: 1px solid var(--graphite);
  background: #ffffff;
  padding: 9px 10px;
  cursor: pointer;
  transition: background 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.delivery-toggle label:has(input:checked) {
  background: var(--lime);
  box-shadow: 4px 4px 0 var(--graphite);
}

.delivery-toggle label:hover {
  transform: translate(-1px, -1px);
}

.delivery-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.delivery-toggle b {
  font-size: 13px;
}

.delivery-toggle small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

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

.directive-item {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 10px;
}

.directive-item b {
  font-size: 12px;
}

.directive-grid code {
  display: block;
  overflow-x: auto;
  background: #eef2f0;
  border: 1px solid var(--line);
  padding: 5px 6px;
  font-size: 12px;
  white-space: nowrap;
}

.directive-grid small,
.directive-modal p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.directive-intro {
  margin: 10px 0 0;
}

.directive-rules {
  border-top: 1px solid var(--line);
  margin: 12px 0 0;
  padding-top: 9px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(22, 27, 25, 0.42);
}

.modal-overlay[hidden] {
  display: none;
}

.directive-modal {
  width: min(760px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--graphite);
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--graphite), var(--shadow);
  padding: 18px;
}

.modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

input,
select {
  width: 100%;
  border: 1px solid var(--graphite);
  background: #ffffff;
  padding: 10px 11px;
  outline: 0;
}

input:focus,
select:focus,
textarea:focus {
  box-shadow: inset 0 0 0 2px var(--green);
}

input[type="range"] {
  accent-color: var(--green);
  padding: 0;
}

.primary-button {
  width: calc(100% - 32px);
  margin-left: 16px;
  margin-right: 16px;
}

.run-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  padding: 12px 16px 0;
}

.run-actions .primary-button {
  width: 100%;
  margin: 0;
}

.cancel-button {
  min-width: 78px;
  border-color: var(--red);
  color: var(--red);
  font-weight: 900;
  padding: 0 12px;
}

.cancel-button[hidden] {
  display: none;
}

.progress {
  margin: 15px 16px 0;
  border: 1px solid var(--graphite);
  background: #ffffff;
  padding: 12px;
}

.progress-track {
  height: 10px;
  border: 1px solid var(--graphite);
  background: #ece6d7;
  margin-bottom: 8px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--lime));
  transition: width 220ms ease;
}

.result-panel .panel-head span {
  color: var(--muted);
  font-size: 13px;
}

audio {
  width: calc(100% - 32px);
  margin: 16px;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 16px 16px;
}

pre {
  min-height: 180px;
  max-height: 320px;
  overflow: auto;
  margin: 0;
  border-top: 1px solid var(--line);
  background: #20201e;
  color: #eef2f0;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.6;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(247, 243, 232, 0.92);
  backdrop-filter: blur(6px);
}

.login-overlay[hidden] {
  display: none;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--graphite);
  background: var(--panel);
  box-shadow: 8px 8px 0 var(--graphite), var(--shadow);
  padding: 24px;
}

.login-panel h1 {
  font-size: 34px;
  line-height: 1.1;
  margin-bottom: 18px;
}

.compact-field {
  padding: 0;
}

.login-button {
  width: 100%;
  margin: 16px 0 0;
}

.login-error {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--red);
  font-weight: 800;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
}

.history-open {
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  padding: 0;
}

.history-open strong,
.history-open span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-open strong {
  margin-bottom: 3px;
}

.history-open span {
  color: var(--muted);
  font-size: 12px;
}

.history-links {
  display: flex;
  gap: 8px;
}

.history-links a {
  color: var(--green);
  font-weight: 900;
  text-decoration: none;
}

.history-empty {
  padding: 18px 14px;
  color: var(--muted);
}

@media (max-width: 900px) {
  .shell {
    padding: 14px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .directive-grid {
    grid-template-columns: 1fr;
  }

  .delivery-toggle {
    grid-template-columns: 1fr;
  }

  .provider-toggle {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    min-height: 480px;
  }

  textarea {
    min-height: 390px;
  }
}
