:root {
  color-scheme: light;
  --ink: #27302d;
  --ink-soft: #5f6863;
  --paper: #f4efe5;
  --paper-deep: #e8dfd0;
  --canvas: #d9d4ca;
  --panel: rgba(251, 249, 244, 0.92);
  --line: rgba(45, 54, 50, 0.16);
  --line-strong: rgba(45, 54, 50, 0.28);
  --accent: #bd695d;
  --accent-dark: #8c4c45;
  --shadow: 0 22px 60px rgba(48, 43, 35, 0.14);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: #d8d4cc;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.56), transparent 32%),
    linear-gradient(135deg, #ddd9d1 0%, #d2cdc4 100%);
}

button,
input,
select {
  font: inherit;
}

button,
label,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.dropzone:focus-within {
  outline: 2px solid rgba(189, 105, 93, 0.58);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 76px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 241, 234, 0.84);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 39px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--ink);
  font-family: Georgia, serif;
  font-size: 19px;
  background: #f7f2e8;
  box-shadow: 4px 4px 0 rgba(39, 48, 45, 0.09);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  letter-spacing: 0.02em;
}

.brand small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions,
.export-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.48);
  font-size: 12px;
}

.status-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d3a83f;
  box-shadow: 0 0 0 4px rgba(211, 168, 63, 0.14);
}

.status-pill.connected i {
  background: #5f8a6b;
  box-shadow: 0 0 0 4px rgba(95, 138, 107, 0.14);
}

.status-pill.error i {
  background: #b55f55;
  box-shadow: 0 0 0 4px rgba(181, 95, 85, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(350px, 420px) minmax(720px, 1fr);
  min-height: calc(100vh - 76px);
}

.control-panel {
  overflow-y: auto;
  padding: 34px 34px 70px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.panel-section {
  padding: 27px 0;
  border-bottom: 1px solid var(--line);
}

.panel-section:first-child {
  padding-top: 4px;
}

.panel-section:last-child {
  border-bottom: 0;
}

.eyebrow {
  margin: 0 0 11px;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.intro-block h1 {
  max-width: 360px;
  margin: 0;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: clamp(27px, 2.3vw, 35px);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.02em;
}

.intro-block > p:last-child {
  max-width: 370px;
  margin: 16px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.75;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-bottom: 17px;
}

.section-heading.compact {
  margin-bottom: 15px;
}

.step-index {
  display: grid;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: var(--accent-dark);
  font-family: Georgia, serif;
  font-size: 11px;
}

.section-heading h2 {
  margin: 1px 0 3px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.section-heading p {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11px;
}

.dropzone {
  position: relative;
  display: flex;
  min-height: 104px;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border: 1px dashed rgba(45, 54, 50, 0.33);
  cursor: pointer;
  background:
    linear-gradient(90deg, transparent 49%, rgba(255, 255, 255, 0.32) 50%, transparent 51%),
    rgba(239, 234, 224, 0.48);
  transition: 160ms ease;
}

.dropzone:hover,
.dropzone.dragging {
  border-color: var(--accent);
  background-color: rgba(189, 105, 93, 0.06);
  transform: translateY(-1px);
}

.dropzone.has-file {
  border-style: solid;
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.dropzone-icon {
  display: grid;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  background: #fbf8f1;
  box-shadow: inset 0 0 0 1px var(--line);
}

.dropzone-icon svg {
  width: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.5;
}

.dropzone-copy strong,
.dropzone-copy small {
  display: block;
}

.dropzone-copy strong {
  font-size: 13px;
}

.dropzone-copy small {
  margin-top: 5px;
  color: var(--ink-soft);
  font-size: 10px;
}

.dropzone-file {
  overflow: hidden;
  margin-left: auto;
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.42);
}

.analysis-state {
  display: flex;
  align-items: center;
  gap: 11px;
}

.analysis-state strong,
.analysis-state p {
  display: block;
  margin: 0;
}

.analysis-state strong {
  font-size: 12px;
}

.analysis-state p {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 10px;
  line-height: 1.5;
}

.analysis-orb {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 35%, #e3afa7 0 13%, transparent 14%),
    conic-gradient(from 40deg, #d9c194, #6f7b73, #d8a4a4, #d9c194);
  box-shadow: inset 0 0 0 5px #f6f1e7;
}

.analysis-card.ready .analysis-orb {
  animation: settle 520ms ease-out;
}

.analysis-card.working .analysis-orb {
  animation: analyze-spin 1.8s linear infinite;
}

.analysis-card.fallback .analysis-orb {
  filter: saturate(0.25);
}

@keyframes analyze-spin {
  to { transform: rotate(360deg); }
}

@keyframes settle {
  from { transform: rotate(-30deg) scale(0.72); opacity: 0; }
  to { transform: rotate(0) scale(1); opacity: 1; }
}

.text-button {
  padding: 4px 0;
  border: 0;
  color: var(--accent-dark);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.text-button:disabled {
  color: #a8aaa6;
  cursor: not-allowed;
}

.notice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 10px;
  padding: 10px 11px;
  color: #6b6358;
  background: rgba(211, 168, 63, 0.1);
  font-size: 10px;
  line-height: 1.55;
}

.notice svg {
  flex: 0 0 auto;
  width: 15px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
}

.notice code {
  font-size: 9px;
}

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

.field-wide {
  grid-column: 1 / -1;
}

.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.field input,
.field select {
  width: 100%;
  height: 39px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.56);
  font-size: 12px;
}

.field input::placeholder {
  color: #aaa69d;
}

.toggle-list {
  margin-top: 16px;
  border-top: 1px solid var(--line);
}

.toggle-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

.toggle-row strong,
.toggle-row small {
  display: block;
}

.toggle-row strong {
  font-size: 11px;
}

.toggle-row small {
  margin-top: 3px;
  color: var(--ink-soft);
  font-size: 9px;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
}

.toggle-row i {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 19px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  background: #d9d7d1;
  transition: 160ms ease;
}

.toggle-row i::after {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
  content: "";
  transition: 160ms ease;
}

.toggle-row input:checked + i {
  border-color: var(--accent-dark);
  background: var(--accent);
}

.toggle-row input:checked + i::after {
  transform: translateX(15px);
}

.palette-controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.color-control {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  padding: 7px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.44);
}

.color-control input {
  width: 30px;
  height: 30px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
}

.color-control input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-control input::-webkit-color-swatch {
  border: 0;
}

.color-control span {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  text-overflow: ellipsis;
  text-transform: uppercase;
}

.preview-panel {
  position: sticky;
  top: 76px;
  display: grid;
  height: calc(100vh - 76px);
  min-height: 650px;
  grid-template-rows: 58px minmax(0, 1fr) 86px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255,255,255,0.7), transparent 42%),
    #d5d1c9;
}

.preview-toolbar,
.export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 242, 235, 0.7);
  backdrop-filter: blur(12px);
}

.spread-heading span,
.spread-heading strong {
  display: block;
}

.spread-heading span {
  color: var(--accent-dark);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.spread-heading strong {
  margin-top: 3px;
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 13px;
  font-weight: 500;
}

.preview-meta {
  display: flex;
  align-items: center;
  gap: 15px;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9px;
  letter-spacing: 0.06em;
}

.canvas-stage {
  position: relative;
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: auto;
  padding: 24px 26px 28px;
}

.canvas-stage::before {
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image: radial-gradient(rgba(59, 55, 48, 0.36) 0.55px, transparent 0.55px);
  background-size: 5px 5px;
  content: "";
  pointer-events: none;
}

.postcard-pair {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  max-width: 1100px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(16px, 2vw, 30px);
  align-items: start;
}

.postcard-side {
  display: grid;
  width: min(100%, calc((100vh - 290px) * 2 / 3));
  min-width: 0;
  justify-self: center;
  gap: 9px;
  margin: 0;
}

.postcard-side figcaption {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--ink-soft);
}

.postcard-side figcaption strong {
  color: var(--ink);
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 12px;
  font-weight: 500;
}

.postcard-side figcaption span {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 8px;
  letter-spacing: 0.16em;
}

.postcard-side canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 2 / 3;
  background: var(--paper);
  box-shadow: var(--shadow), 0 0 0 1px rgba(40, 45, 43, 0.16);
  animation: canvas-in 280ms ease-out;
}

@keyframes canvas-in {
  from { opacity: 0; transform: translateY(9px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.empty-preview {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  text-align: center;
}

.empty-preview strong {
  margin-top: 18px;
  color: var(--ink);
  font-family: Georgia, "Noto Serif SC", serif;
  font-size: 17px;
  font-weight: 500;
}

.empty-preview p {
  margin: 7px 0 0;
  font-size: 11px;
}

.empty-card {
  position: relative;
  display: block;
  width: 116px;
  height: 154px;
  border: 1px solid rgba(45, 54, 50, 0.34);
  background: rgba(245, 240, 229, 0.68);
  box-shadow: 8px 10px 0 rgba(45, 54, 50, 0.05);
}

.empty-card i {
  position: absolute;
  display: block;
  background: rgba(45, 54, 50, 0.16);
}

.empty-card i:first-child {
  top: 13px;
  left: 13px;
  width: 90px;
  height: 57px;
}

.empty-card i:nth-child(2) {
  bottom: 28px;
  left: 13px;
  width: 37px;
  height: 3px;
}

.empty-card i:last-child {
  right: 13px;
  bottom: 17px;
  width: 38px;
  height: 38px;
  border-radius: 50% 48% 42% 56%;
}

.export-bar {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.export-bar strong,
.export-bar span {
  display: block;
}

.export-bar strong {
  font-size: 11px;
}

.export-bar span {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 9px;
}

.button {
  min-height: 37px;
  padding: 0 16px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  transition: 140ms ease;
}

.button:not(:disabled):hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.44;
}

.button-ghost {
  border-color: var(--line);
  color: var(--ink);
  background: transparent;
}

.button-secondary {
  border-color: var(--line-strong);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.3);
}

.button-primary {
  color: #fffaf3;
  background: var(--ink);
}

.toast {
  position: fixed;
  z-index: 50;
  right: 26px;
  bottom: 25px;
  max-width: 320px;
  padding: 12px 15px;
  opacity: 0;
  color: #fffaf3;
  background: rgba(39, 48, 45, 0.94);
  box-shadow: 0 12px 34px rgba(20, 22, 21, 0.2);
  font-size: 11px;
  pointer-events: none;
  transform: translateY(8px);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

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

  .control-panel {
    border-right: 0;
  }

  .preview-panel {
    position: relative;
    top: 0;
    height: 900px;
  }

  .postcard-side {
    width: min(100%, 480px);
  }
}

@media (max-width: 620px) {
  .topbar {
    height: 66px;
    padding: 0 16px;
  }

  .status-pill {
    display: none;
  }

  .brand small {
    display: none;
  }

  .control-panel {
    padding: 25px 20px 50px;
  }

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

  .field-wide {
    grid-column: auto;
  }

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

  .preview-panel {
    grid-template-rows: 54px minmax(0, 1fr) auto;
    height: 760px;
    min-height: 620px;
  }

  .preview-toolbar,
  .export-bar {
    padding: 0 16px;
  }

  .preview-meta {
    display: none;
  }

  .canvas-stage {
    justify-content: start;
    padding: 20px;
  }

  .postcard-pair {
    width: 650px;
    max-width: none;
    gap: 18px;
  }

  .postcard-side {
    width: 316px;
  }

  .export-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .export-actions button {
    flex: 1 1 30%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
