:root {
  --ink: #f3e7d3;
  --muted: #a99680;
  --paper: #19130f;
  --panel: rgba(38, 29, 22, 0.78);
  --panel-strong: rgba(55, 39, 27, 0.9);
  --line: rgba(232, 181, 112, 0.16);
  --gold: #d99b57;
  --ember: #ff7e38;
  --olive: #6f7b50;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 8%, rgba(223, 127, 59, 0.22), transparent 27rem),
    radial-gradient(circle at 87% 18%, rgba(111, 123, 80, 0.2), transparent 22rem),
    linear-gradient(135deg, #18110d 0%, #2b1e15 48%, #11100d 100%);
  font-family: "Spline Sans", "Noto Serif SC", sans-serif;
  overflow-x: hidden;
}

button,
textarea,
a {
  font: inherit;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: 0.12;
  background-image:
    linear-gradient(115deg, rgba(255, 255, 255, 0.035), transparent 28%),
    repeating-radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

.shell {
  width: min(1500px, calc(100vw - 64px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 18px;
  width: min(1120px, 100%);
  animation: rise 700ms ease both;
}

.private-note {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin: 0;
  padding: 16px 28px;
  color: #fff0d7;
  border: 1px solid rgba(217, 155, 87, 0.36);
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(217, 155, 87, 0.16), rgba(255, 126, 56, 0.06));
  font-family: "Noto Serif SC", serif;
  font-size: clamp(22px, 2.2vw, 32px);
  font-weight: 700;
  letter-spacing: 0.1em;
  white-space: nowrap;
  box-shadow: 0 20px 58px rgba(255, 126, 56, 0.1), inset 0 1px rgba(255, 255, 255, 0.07);
}

.private-note::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--gold);
  box-shadow: 0 0 18px rgba(217, 155, 87, 0.72);
}

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero .eyebrow {
  padding: 12px 20px;
  border: 1px solid rgba(217, 155, 87, 0.2);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  color: #ffc17d;
  font-size: clamp(12px, 1.2vw, 17px);
  white-space: nowrap;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.04);
}

.mini {
  margin-bottom: 6px;
}

h1,
h2 {
  margin: 0;
  font-family: "Fraunces", "Noto Serif SC", serif;
  line-height: 0.95;
  letter-spacing: -0.055em;
}

h1 {
  max-width: 760px;
  font-size: clamp(48px, 8vw, 106px);
  text-shadow: 0 2px 0 rgba(255, 242, 222, 0.08), 0 22px 70px rgba(0, 0, 0, 0.42);
}

h2 {
  font-size: clamp(22px, 2.4vw, 32px);
  letter-spacing: -0.035em;
}

.intro {
  max-width: 640px;
  margin: 22px 0 0;
  color: #c5b39b;
  font-size: 17px;
  line-height: 1.8;
}

.status-card {
  display: flex;
  gap: 14px;
  align-items: center;
  min-height: 112px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(78, 53, 35, 0.86), rgba(30, 22, 17, 0.78));
  box-shadow: 0 24px 70px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.05);
}

.pulse {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: var(--ember);
  box-shadow: 0 0 0 0 rgba(255, 126, 56, 0.7);
  animation: pulse 1.8s infinite;
}

.status-card strong,
.status-card small {
  display: block;
}

.status-card small {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.5;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  grid-template-areas:
    "composer ratios"
    "preview preview";
  gap: 18px;
  width: min(1120px, 100%);
  margin: 0 auto;
}

.panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: var(--panel);
  box-shadow: 0 30px 90px var(--shadow), inset 0 1px rgba(255, 255, 255, 0.045);
  backdrop-filter: blur(22px);
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent 35%, rgba(217, 155, 87, 0.04));
}

.composer {
  grid-area: composer;
  min-height: 354px;
  padding: 24px;
  animation: rise 800ms 80ms ease both;
}

.ratios {
  grid-area: ratios;
  padding: 18px;
  animation: rise 800ms 160ms ease both;
}

.preview {
  grid-area: preview;
  padding: 24px;
  animation: rise 800ms 240ms ease both;
}

.panel-head,
.preview-top,
.meta-row,
.controls {
  position: relative;
  z-index: 1;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-head small {
  color: var(--muted);
  letter-spacing: 0;
  text-transform: none;
}

textarea {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  min-height: 224px;
  resize: vertical;
  padding: 22px;
  color: var(--ink);
  border: 1px solid rgba(232, 181, 112, 0.18);
  border-radius: 24px;
  outline: none;
  background:
    linear-gradient(180deg, rgba(10, 8, 7, 0.5), rgba(42, 30, 22, 0.36)),
    rgba(15, 12, 10, 0.58);
  font-family: "Noto Serif SC", serif;
  font-size: 18px;
  line-height: 1.85;
  box-shadow: inset 0 18px 45px rgba(0, 0, 0, 0.25);
}

textarea::placeholder {
  color: rgba(169, 150, 128, 0.58);
}

textarea:focus {
  border-color: rgba(255, 167, 92, 0.62);
  box-shadow: 0 0 0 4px rgba(255, 126, 56, 0.1), inset 0 18px 45px rgba(0, 0, 0, 0.25);
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.generate,
.ghost,
.download,
.stop-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 20px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.generate {
  gap: 12px;
  min-width: 190px;
  color: #1c1109;
  border: 0;
  background: linear-gradient(135deg, #ffb267, #ff7e38 55%, #c86f38);
  font-weight: 650;
  box-shadow: 0 16px 42px rgba(255, 126, 56, 0.22);
}

.generate,
.ghost,
.download,
.stop-button {
  min-width: 156px;
  color: #1c1109;
  border: 0;
  background: linear-gradient(135deg, #ffb267, #ff7e38 55%, #c86f38);
  font-weight: 650;
  box-shadow: 0 16px 42px rgba(255, 126, 56, 0.22);
}

.generate i {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #1c1109;
}

.generate:hover,
.ghost:hover,
.download:hover,
.stop-button:hover {
  transform: translateY(-2px);
}

.generate:disabled {
  cursor: wait;
  opacity: 0.72;
  transform: none;
}

.generate.loading i {
  animation: blink 800ms infinite alternate;
}

.download.disabled {
  pointer-events: none;
  opacity: 0.38;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stop-button.hidden {
  display: none;
}

.ratio-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.ratio {
  min-height: 88px;
  padding: 12px 8px 10px;
  color: var(--muted);
  border: 1px solid rgba(232, 181, 112, 0.11);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.018);
  cursor: pointer;
  transition: 180ms ease;
}

.ratio:hover {
  color: var(--ink);
  border-color: rgba(232, 181, 112, 0.34);
  transform: translateY(-2px);
}

.ratio.active {
  color: var(--ink);
  border-color: rgba(255, 161, 86, 0.78);
  background: linear-gradient(145deg, rgba(255, 126, 56, 0.14), rgba(217, 155, 87, 0.05));
  box-shadow: inset 0 0 0 1px rgba(255, 190, 119, 0.16), 0 18px 44px rgba(255, 126, 56, 0.12);
}

.ratio-shape {
  display: grid;
  place-items: center;
  height: 38px;
}

.ratio-icon {
  display: block;
  border: 3px solid currentColor;
  border-radius: 7px;
  opacity: 0.62;
}

.ratio-label {
  display: block;
  margin-top: 6px;
  color: #c8bba8;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.01em;
  text-align: center;
}

.ratio.active .ratio-label {
  color: var(--ink);
}

.preview-top {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: min(100%, 980px);
  min-height: 0;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  border: 1px solid rgba(232, 181, 112, 0.14);
  border-radius: 28px;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 126, 56, 0.13), transparent 34rem),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 42px),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 42px),
    rgba(8, 7, 6, 0.42);
  overflow: hidden;
}

.canvas-wrap[data-ratio="3-4"] {
  aspect-ratio: 3 / 4;
  width: min(100%, 735px);
}

.canvas-wrap[data-ratio="4-3"] {
  aspect-ratio: 4 / 3;
}

.canvas-wrap[data-ratio="16-9"] {
  aspect-ratio: 16 / 9;
}

.canvas-wrap[data-ratio="9-16"] {
  aspect-ratio: 9 / 16;
  width: min(100%, 552px);
}

.canvas-wrap[data-ratio="2-3"] {
  aspect-ratio: 2 / 3;
  width: min(100%, 654px);
}

.canvas-wrap[data-ratio="3-2"] {
  aspect-ratio: 3 / 2;
}

.canvas-wrap[data-ratio="21-9"] {
  aspect-ratio: 21 / 9;
}

.canvas-wrap.loading {
  background:
    linear-gradient(110deg, rgba(255, 126, 56, 0.08), rgba(255, 255, 255, 0.035), rgba(217, 155, 87, 0.09)),
    rgba(8, 7, 6, 0.42);
  animation: breathe 1.6s ease-in-out infinite alternate;
}

.canvas-wrap.loading::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    linear-gradient(105deg, transparent 0%, rgba(255, 215, 168, 0.04) 32%, rgba(255, 215, 168, 0.18) 48%, rgba(255, 126, 56, 0.05) 62%, transparent 100%),
    radial-gradient(circle at 22% 18%, rgba(255, 190, 119, 0.12), transparent 12rem);
  background-size: 220% 100%, auto;
  animation: shimmer 1.9s ease-in-out infinite;
}

.canvas-wrap.loading::after {
  content: "";
  position: absolute;
  inset: 18px;
  z-index: 0;
  border: 1px solid rgba(255, 213, 164, 0.09);
  border-radius: 22px;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.035) 0 1px, transparent 1px 38px),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 38px);
  opacity: 0.42;
}

.empty-state {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 140px;
}

#resultImage {
  position: relative;
  z-index: 1;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 28px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 16px rgba(255, 126, 56, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(255, 126, 56, 0);
  }
}

@keyframes blink {
  to {
    opacity: 0.28;
    transform: scale(1.5);
  }
}

@keyframes breathe {
  from {
    box-shadow: inset 0 0 0 1px rgba(255, 159, 86, 0.08), 0 0 0 rgba(255, 126, 56, 0);
  }
  to {
    box-shadow: inset 0 0 0 1px rgba(255, 159, 86, 0.28), 0 0 54px rgba(255, 126, 56, 0.12);
  }
}

@keyframes shimmer {
  from {
    background-position: 160% 0, center;
    opacity: 0.54;
  }
  50% {
    opacity: 0.96;
  }
  to {
    background-position: -80% 0, center;
    opacity: 0.54;
  }
}

@media (max-width: 860px) {
  .hero,
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "composer"
      "ratios"
      "preview";
  }

  .hero {
    align-items: start;
  }

  .status-card {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 24px;
  }

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

  .panel {
    border-radius: 24px;
  }

  .composer,
  .ratios,
  .preview {
    padding: 16px;
  }

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

  .ratio {
    min-height: 96px;
  }

  .preview-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .canvas-wrap {
    width: 100%;
  }
}
