:root {
  --bg: #f5f0e8;
  --panel: #fffaf2;
  --ink: #2b241c;
  --muted: #776c60;
  --line: rgba(80, 55, 34, 0.18);
  --accent: #7a4b2a;
  --accent-2: #27635b;
  --danger: #9f3f32;
  --shadow: 0 16px 40px rgba(43, 36, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Georgia, "Times New Roman", serif;
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 250, 242, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(14px);
}

h1 {
  margin: 0;
  font-size: 28px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

.status {
  min-width: 110px;
  text-align: center;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  color: var(--muted);
}

.status.busy {
  color: var(--accent);
}

.status.error {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 520px) minmax(0, 1fr);
  gap: 22px;
  padding: 22px;
  align-items: start;
}

.editor,
.result-shell,
.history {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.editor {
  padding: 18px;
}

form,
label {
  display: grid;
  gap: 8px;
}

form {
  gap: 16px;
}

label span {
  color: var(--muted);
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  padding: 11px 12px;
  border-radius: 6px;
}

textarea {
  resize: vertical;
  line-height: 1.35;
}

.row {
  display: grid;
  gap: 12px;
}

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

.row.three {
  grid-template-columns: repeat(3, 1fr);
}

.filebox {
  border: 1px dashed var(--line);
  padding: 10px;
  background: rgba(255, 255, 255, 0.42);
}

.filebox input {
  padding: 0;
  border: 0;
  background: transparent;
}

.template-preview {
  aspect-ratio: 768 / 1376;
  max-height: 310px;
  justify-self: start;
  background: white;
  border: 1px solid var(--line);
  overflow: hidden;
}

.template-preview img {
  display: block;
  height: 100%;
  width: auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

button {
  border: 1px solid rgba(122, 75, 42, 0.35);
  background: var(--accent);
  color: white;
  padding: 11px 14px;
  border-radius: 6px;
  cursor: pointer;
}

button[type="button"] {
  background: white;
  color: var(--accent);
}

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

.preview {
  display: grid;
  gap: 16px;
}

.result-shell {
  min-height: calc(100vh - 134px);
  display: grid;
  place-items: center;
  padding: 18px;
}

.empty-result {
  color: var(--muted);
}

#resultImage {
  display: none;
  max-width: 100%;
  max-height: calc(100vh - 170px);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.history {
  padding: 14px;
}

.history h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.history button {
  padding: 0;
  border: 1px solid var(--line);
  background: white;
}

.history img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

@media (max-width: 980px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .row.two,
  .row.three {
    grid-template-columns: 1fr;
  }

  .result-shell {
    min-height: 60vh;
  }
}
