:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --line: #d7dee7;
  --line-strong: #b7c3cf;
  --text: #16212b;
  --muted: #637282;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --blue: #2457c5;
  --amber: #b7791f;
  --danger: #b42318;
  --shadow: 0 14px 32px rgba(22, 33, 43, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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,
textarea,
select,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.workspace,
.results-panel {
  min-width: 0;
}

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

.brand,
.top-actions,
.meta-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #17324c;
  border-radius: 8px;
  background: #17324c;
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.08;
}

h2 {
  font-size: 18px;
}

.meta-row {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.meta-row span {
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.top-actions {
  justify-content: flex-end;
  gap: 10px;
}

.token-field {
  display: grid;
  grid-template-columns: auto 150px;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.token-field input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.status-pill {
  display: grid;
  place-items: center;
  min-width: 110px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 650;
}

.status-pill.busy {
  border-color: #f1c66a;
  color: #7a560d;
  background: #fff8e6;
}

.status-pill.error {
  border-color: #f1b9b5;
  color: var(--danger);
  background: #fff4f2;
}

.mode-strip {
  display: inline-grid;
  grid-template-columns: repeat(2, 112px);
  gap: 6px;
  padding: 4px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8edf2;
}

.mode-button {
  height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.mode-button.active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(22, 33, 43, 0.14);
}

.tool-surface,
.results-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tool-surface {
  display: grid;
  gap: 18px;
  padding: 18px;
}

.field {
  display: grid;
  gap: 8px;
}

label,
.label-row {
  font-weight: 700;
}

.label-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.label-row span,
.panel-header p {
  color: var(--muted);
  font-weight: 500;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 176px;
  padding: 14px;
  line-height: 1.5;
}

textarea:focus,
select:focus,
.token-field:focus-within {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 118, 110, 0.14);
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 16px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f5;
}

.count-control {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.segmented span {
  display: grid;
  place-items: center;
  height: 36px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--accent-strong);
  box-shadow: 0 1px 4px rgba(22, 33, 43, 0.14);
}

input[type="file"] {
  display: none;
}

.dropzone {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 128px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

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

.dropzone.dragover {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
}

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

.thumb {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  aspect-ratio: 1;
  background: #f1f4f6;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb span {
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: 6px;
  overflow: hidden;
  padding: 3px 5px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.88);
  color: var(--text);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-thumb {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-color: rgba(22, 33, 43, 0.18);
  background: rgba(255, 255, 255, 0.92);
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.secondary-button,
#clearBtn {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 650;
}

#generateBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 148px;
  min-height: 44px;
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

#generateBtn:not(:disabled):hover {
  background: var(--accent-strong);
}

.button-icon {
  position: relative;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 4px;
}

.button-icon::before,
.button-icon::after {
  position: absolute;
  content: "";
  background: #ffffff;
}

.button-icon::before {
  top: 6px;
  right: 3px;
  left: 3px;
  height: 1px;
}

.button-icon::after {
  top: 3px;
  bottom: 3px;
  left: 6px;
  width: 1px;
}

.results-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.panel-header p {
  margin-top: 4px;
  font-size: 13px;
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-height: 260px;
  padding: 14px;
  overflow: auto;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  min-height: 230px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
}

.empty-preview {
  width: 112px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, transparent 0 48%, rgba(36, 87, 197, 0.22) 48% 52%, transparent 52%),
    linear-gradient(45deg, rgba(15, 118, 110, 0.12), rgba(183, 121, 31, 0.14));
}

.result-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.result-card img {
  display: block;
  width: 100%;
  height: auto;
}

.result-meta {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.result-meta code {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.download-link {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  border-radius: 8px;
  background: #1f2937;
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
}

.log-shell {
  border-top: 1px solid var(--line);
}

.log-shell summary {
  min-height: 42px;
  padding: 11px 14px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.log {
  min-height: 150px;
  max-height: 300px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  background: #111827;
  color: #d1fae5;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

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

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

@media (max-width: 620px) {
  .app-shell {
    padding: 12px;
  }

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

  .top-actions,
  .status-pill,
  .token-field,
  .mode-strip {
    width: 100%;
  }

  .token-field {
    grid-template-columns: 64px minmax(0, 1fr);
  }

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

  .controls-grid {
    gap: 14px;
  }

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

  .actions {
    flex-direction: column-reverse;
  }

  #generateBtn,
  .secondary-button {
    width: 100%;
  }
}
