:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --panel: #ffffff;
  --soft: #f8faf9;
  --text: #17211d;
  --muted: #66736d;
  --line: #d8e0dc;
  --accent: #0d7a61;
  --accent-strong: #075d49;
  --ink: #202a26;
  --danger: #b42318;
  --success: #167647;
  --working: #9a5b05;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: 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;
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px;
}

.workspace {
  order: 2;
}

.results {
  order: 1;
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 10px;
}

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

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

h1 {
  font-size: 1.75rem;
}

h2 {
  font-size: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(23, 33, 29, 0.05);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.template-bar .field,
.button-row {
  margin-bottom: 0;
}

label,
summary {
  color: #33413b;
  font-size: 0.86rem;
  font-weight: 800;
}

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

textarea {
  min-height: 92px;
  resize: vertical;
}

input[type="file"] {
  padding: 9px;
  background: var(--soft);
  font-size: 0.9rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 122, 97, 0.14);
}

.split,
.template-bar,
.upload-row,
.task-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

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

.section-head button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: #eef1ef;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  padding: 7px 10px;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.history-list.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.history-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  padding: 10px;
}

.history-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.history-title {
  overflow: hidden;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

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

.history-actions button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 850;
}

.history-check {
  background: var(--accent);
  color: white;
}

.history-load {
  background: var(--ink);
  color: white;
}

.template-bar {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  background: var(--soft);
}

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

.toggles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 2px 0 14px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--soft);
  font-weight: 700;
}

.toggles input {
  width: auto;
}

.primary,
.icon-button,
.task-row button,
.button-row button,
.upload-row button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 850;
  white-space: nowrap;
}

.primary {
  position: sticky;
  bottom: 10px;
  z-index: 3;
  width: 100%;
  background: var(--accent);
  color: white;
  padding: 13px 16px;
  box-shadow: 0 10px 26px rgba(13, 122, 97, 0.22);
}

.icon-button,
.task-row button,
.button-row button,
.upload-row button {
  background: var(--ink);
  color: white;
  padding: 10px 13px;
}

.primary:hover,
.task-row button:hover,
.icon-button:hover,
.button-row button:hover,
.upload-row button:hover {
  background: var(--accent-strong);
}

.status {
  margin: 12px 0;
  border-radius: 8px;
  background: #eef1ef;
  color: #33413b;
  padding: 11px;
  font-size: 0.92rem;
}

.status[data-tone="success"] {
  background: #ecfdf3;
  color: var(--success);
}

.status[data-tone="error"] {
  background: #fef3f2;
  color: var(--danger);
}

.status[data-tone="working"] {
  background: #fff7ed;
  color: var(--working);
}

.preview-panel {
  min-height: 0;
}

.preview {
  display: grid;
  place-items: center;
  min-height: 190px;
  overflow: hidden;
  border: 1px dashed #cbd5d0;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  text-align: center;
  font-size: 0.92rem;
}

.preview img,
.preview video {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #111827;
}

.preview a {
  justify-self: start;
  margin: 10px;
  color: var(--accent);
  font-weight: 800;
}

.raw {
  max-height: 170px;
  overflow: auto;
  margin: 12px 0 0;
  white-space: pre-wrap;
  color: #374151;
  font-size: 0.76rem;
}

@media (min-width: 480px) {
  .history-item {
    grid-template-columns: minmax(0, 1fr) 150px;
    align-items: center;
  }
}

.hidden {
  display: none;
}

@media (min-width: 640px) {
  .app {
    padding: 18px;
  }

  h1 {
    font-size: 2.4rem;
  }

  .panel {
    padding: 18px;
  }

  .split,
  .upload-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .template-bar {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 0.7fr);
  }

  .template-bar .button-row {
    grid-column: 1 / -1;
  }

  .toggles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1.12fr) minmax(360px, 0.88fr);
    gap: 24px;
    padding: 28px 18px;
  }

  .workspace {
    order: 1;
  }

  .results {
    order: 2;
    align-content: start;
    position: sticky;
    top: 20px;
  }

  h1 {
    font-size: 3.6rem;
  }

  .template-bar {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 0.65fr) auto;
    align-items: end;
  }

  .template-bar .button-row {
    grid-column: auto;
  }

  .primary {
    position: static;
    box-shadow: none;
  }

  .preview {
    min-height: 260px;
  }

  .preview-panel {
    min-height: 420px;
  }
}
