:root {
  color-scheme: dark;
  --bg: #101113;
  --ink: #f4f0e8;
  --muted: #a7a095;
  --line: #303237;
  --panel: #191b1f;
  --panel-soft: #202328;
  --accent: #f0c35a;
  --accent-ink: #201604;
  --cyan: #7bd7d0;
  --red: #ff7b6e;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.36);
  font-family: "Aptos", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(123, 215, 208, 0.08), transparent 32rem),
    radial-gradient(circle at 88% 6%, rgba(240, 195, 90, 0.14), transparent 18rem),
    var(--bg);
}

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

button {
  min-height: 44px;
}

.app-shell {
  width: min(1240px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 16px;
  background: linear-gradient(180deg, rgba(16, 17, 19, 0.98), rgba(16, 17, 19, 0.7) 72%, transparent);
  backdrop-filter: blur(16px);
}

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

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

h1 {
  font-size: clamp(1.55rem, 6vw, 3rem);
}

h2 {
  font-size: 1.15rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(330px, 0.95fr);
  gap: 14px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(25, 27, 31, 0.94);
  box-shadow: var(--shadow);
  padding: 14px;
}

.compose-panel,
.config-panel {
  grid-column: 1;
}

.output-panel,
.history-panel {
  grid-column: 2;
}

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

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #111317;
}

.mode-btn {
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
}

.mode-btn.active {
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 800;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field > span,
.row-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

textarea,
input,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #111317;
  outline: 0;
}

textarea {
  resize: vertical;
  min-height: 164px;
  padding: 13px;
  line-height: 1.55;
}

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

textarea:focus,
input:focus,
select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(123, 215, 208, 0.14);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

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

.row-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  margin-bottom: 7px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 180px;
  border: 1px dashed #55585f;
  border-radius: 8px;
  background: #121418;
  color: var(--muted);
  text-align: center;
  overflow: hidden;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: rgba(240, 195, 90, 0.08);
}

.drop-zone input,
.file-action input {
  display: none;
}

.drop-zone img {
  width: 100%;
  max-height: 300px;
  object-fit: contain;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.file-action,
.text-button {
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.primary-button {
  flex: 1 1 180px;
  min-height: 50px;
  color: var(--accent-ink);
  background: var(--accent);
  font-weight: 900;
}

.secondary-button,
.file-action {
  min-height: 44px;
  padding: 0 14px;
  color: var(--ink);
  background: var(--panel-soft);
  border-color: var(--line);
}

.danger-button {
  min-height: 44px;
  padding: 0 14px;
  color: #240704;
  background: var(--red);
  font-weight: 800;
}

.small {
  min-height: 38px;
  padding: 0 10px;
}

.icon-button {
  width: 44px;
  height: 44px;
  color: var(--accent-ink);
  background: var(--accent);
  font-size: 1.5rem;
  font-weight: 900;
}

.text-button {
  min-height: 30px;
  color: var(--cyan);
  background: transparent;
  border-color: transparent;
  padding: 0;
}

button:hover,
.file-action:hover {
  transform: translateY(-1px);
}

button:active,
.file-action:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.status-line {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 10px;
}

.progress {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #0d0f12;
  margin-bottom: 12px;
}

.progress span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  transition: width 180ms ease;
}

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

.image-card {
  position: relative;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111317;
  padding: 8px;
}

.image-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 6px;
  background: #08090b;
}

.select-mark {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.62);
  font-size: 0.78rem;
}

.select-mark input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.image-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.image-actions button {
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.history-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111317;
  padding: 8px;
}

.history-item img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: #08090b;
}

.history-copy {
  min-width: 0;
}

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

.history-copy strong {
  font-size: 0.92rem;
}

.history-copy span {
  color: var(--muted);
  font-size: 0.8rem;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.history-actions button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .compose-panel,
  .config-panel,
  .output-panel,
  .history-panel {
    grid-column: 1;
  }

  .output-panel {
    order: 2;
  }

  .config-panel {
    order: 3;
  }

  .history-panel {
    order: 4;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .panel {
    padding: 12px;
  }

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

  .mode-switch {
    width: 100%;
  }

  .settings-grid,
  .config-grid,
  .output-grid {
    grid-template-columns: 1fr 1fr;
  }

  .config-grid .field:first-child,
  .config-grid .field:nth-child(2),
  .config-grid .field:nth-child(4),
  .config-grid .field:nth-child(5) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 390px) {
  .settings-grid,
  .output-grid {
    grid-template-columns: 1fr;
  }
}
