:root {
  color-scheme: light;
  --ink: #17202b;
  --muted: #657182;
  --faint: #8a95a5;
  --page: #f4f6f3;
  --paper: #fffefa;
  --panel: #ffffff;
  --line: #dce2dc;
  --line-strong: #c4cec7;
  --green: #1f7a64;
  --green-dark: #105644;
  --blue: #2f5f9f;
  --coral: #d9644a;
  --amber: #dfa234;
  --danger: #a83224;
  --shadow: 0 24px 70px rgba(29, 39, 49, 0.14);
  --soft-shadow: 0 14px 42px rgba(29, 39, 49, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(23, 32, 43, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 32, 43, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #f7f3ea 0%, #eef5f0 46%, #f5f7fb 100%);
  background-size: 56px 56px, 56px 56px, auto;
  color: var(--ink);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.72), transparent 42%),
    linear-gradient(300deg, rgba(31, 122, 100, 0.1), transparent 52%);
  content: "";
}

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

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(47, 95, 159, 0.26);
  outline-offset: 2px;
}

.app-shell {
  width: min(1280px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

.topbar {
  display: grid;
  min-height: 58px;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  margin-bottom: 16px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid rgba(23, 32, 43, 0.12);
  border-radius: 8px;
  background: #17202b;
  color: #fffefa;
  font-weight: 900;
}

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

.brand strong {
  font-size: 17px;
  letter-spacing: 0;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topnav {
  display: inline-flex;
  justify-self: center;
  border: 1px solid rgba(23, 32, 43, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  padding: 4px;
  box-shadow: 0 8px 24px rgba(29, 39, 49, 0.06);
}

.topnav a {
  display: inline-grid;
  min-height: 32px;
  place-items: center;
  border-radius: 6px;
  padding: 0 12px;
  color: #374151;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.topnav a:hover {
  background: rgba(255, 255, 255, 0.86);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  max-width: min(490px, 38vw);
  justify-self: end;
  gap: 9px;
  overflow: hidden;
  border: 1px solid rgba(31, 122, 100, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  padding: 0 13px;
  color: var(--green-dark);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: 0 12px 34px rgba(31, 122, 100, 0.08);
}

.status-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(31, 122, 100, 0.12);
}

.workbench {
  display: grid;
  grid-template-columns: minmax(350px, 430px) minmax(0, 1fr);
  min-height: calc(100vh - 116px);
  overflow: hidden;
  border: 1px solid rgba(23, 32, 43, 0.12);
  border-radius: 8px;
  background: rgba(255, 254, 250, 0.9);
  box-shadow: var(--shadow);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.98), rgba(247, 249, 244, 0.96)),
    var(--paper);
  padding: 28px;
}

.intro {
  display: grid;
  gap: 9px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 9em;
  font-size: 38px;
  line-height: 1.04;
  letter-spacing: 0;
}

h2 {
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

.intro p:last-child {
  max-width: 31em;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}

.quota-card {
  display: grid;
  gap: 10px;
  border: 1px solid rgba(31, 122, 100, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(31, 122, 100, 0.09), transparent 58%),
    rgba(255, 255, 255, 0.74);
  padding: 14px;
}

.quota-head,
.quota-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quota-head span,
.quota-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.quota-head strong {
  color: var(--green-dark);
  font-size: 13px;
}

.quota-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 32, 43, 0.09);
}

.quota-track span {
  display: block;
  width: 14%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber));
  transition: width 0.32s ease;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 8px;
}

.field > span,
.field-head {
  color: #303946;
  font-size: 13px;
  font-weight: 850;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#char-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

textarea,
input:not([type="radio"]):not([type="checkbox"]),
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

textarea {
  min-height: 198px;
  max-height: 360px;
  resize: vertical;
  padding: 15px;
  line-height: 1.64;
}

input:not([type="radio"]):not([type="checkbox"]) {
  height: 44px;
  padding: 0 13px;
}

textarea::placeholder,
input::placeholder {
  color: #929aa7;
}

select {
  height: 46px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #687181 50%),
    linear-gradient(135deg, #687181 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 20px,
    calc(100% - 13px) 20px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding: 0 36px 0 13px;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--green);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(31, 122, 100, 0.13);
}

.prompt-tools {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.prompt-actions {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 8px;
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-chips button,
.segmented span,
.ghost-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: #404956;
  cursor: pointer;
  transition: border-color 0.16s ease, color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.prompt-chips button,
.ghost-button {
  padding: 0 12px;
  font-size: 13px;
  font-weight: 800;
}

.ghost-button {
  flex: 0 0 auto;
  color: var(--muted);
}

.compact-field {
  gap: 7px;
}

.idea-panel {
  display: grid;
  gap: 9px;
  border: 1px solid rgba(23, 32, 43, 0.08);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.56);
  padding: 12px;
}

.idea-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.idea-head span {
  color: #303946;
  font-size: 13px;
  font-weight: 850;
}

.idea-list {
  display: grid;
  gap: 8px;
}

.idea-card {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  padding: 10px 11px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.idea-card:hover {
  border-color: rgba(31, 122, 100, 0.3);
  background: #fff;
  transform: translateY(-1px);
}

.idea-card strong {
  font-size: 13px;
  line-height: 1.25;
}

.idea-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.range-field {
  gap: 10px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--green);
}

.prompt-chips button:hover,
.segmented label:hover span,
.ghost-button:hover {
  border-color: var(--line-strong);
  background: #fff;
  transform: translateY(-1px);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  border: 0;
  padding: 0;
}

.segmented legend {
  grid-column: 1 / -1;
  margin-bottom: 1px;
  color: #303946;
  font-size: 13px;
  font-weight: 850;
}

.segmented label {
  min-width: 0;
}

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

.segmented span {
  display: grid;
  width: 100%;
  place-items: center;
  padding: 0 5px;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.segmented input:checked + span {
  border-color: rgba(31, 122, 100, 0.36);
  background: #e8f3ee;
  color: var(--green-dark);
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.generate-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 52px;
  border-radius: 8px;
  background: var(--green);
  color: white;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 14px 28px rgba(31, 122, 100, 0.23);
  transition: background 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.generate-button:hover {
  background: var(--green-dark);
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(31, 122, 100, 0.28);
}

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

.canvas-panel {
  display: grid;
  min-width: 0;
  min-height: 640px;
  grid-template-rows: auto minmax(0, 1fr);
  background:
    linear-gradient(135deg, rgba(47, 95, 159, 0.11), transparent 42%),
    linear-gradient(315deg, rgba(223, 162, 52, 0.14), transparent 36%),
    #f7f8f3;
}

.canvas-toolbar {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid rgba(23, 32, 43, 0.1);
  padding: 0 26px;
}

.canvas-toolbar div:first-child {
  display: grid;
  gap: 3px;
}

.toolbar-label {
  color: var(--blue);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.canvas-toolbar strong {
  font-size: 18px;
}

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

.size-badge {
  display: inline-grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid rgba(23, 32, 43, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
  padding: 0 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid rgba(23, 32, 43, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease, opacity 0.16s ease;
}

.icon-button:not(:disabled):hover {
  border-color: var(--line-strong);
  background: #fff;
  transform: translateY(-1px);
}

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

.stage {
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 30px;
}

.placeholder,
.loading,
.error,
.result {
  width: min(100%, 760px);
}

.placeholder,
.loading {
  display: grid;
  gap: 18px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.idle-preview {
  width: min(64vw, 660px);
  max-width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid rgba(23, 32, 43, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.46);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), var(--soft-shadow);
}

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

.placeholder p,
.loading p {
  color: #596575;
  font-weight: 800;
}

.loader {
  display: inline-grid;
  grid-template-columns: repeat(3, 12px);
  gap: 8px;
}

.loader span {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--green);
  animation: pulse 0.9s ease-in-out infinite;
}

.loader span:nth-child(2) {
  animation-delay: 0.12s;
  background: var(--amber);
}

.loader span:nth-child(3) {
  animation-delay: 0.24s;
  background: var(--coral);
}

@keyframes pulse {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }

  50% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

.error {
  border: 1px solid rgba(168, 50, 36, 0.25);
  border-radius: 8px;
  background: rgba(255, 246, 242, 0.9);
  color: var(--danger);
  padding: 16px 18px;
  font-weight: 800;
  line-height: 1.6;
  box-shadow: 0 16px 40px rgba(95, 31, 22, 0.09);
}

.result {
  margin: 0;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 14px;
  align-items: center;
}

.result img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 226px);
  margin: 0 auto;
  border: 1px solid rgba(23, 32, 43, 0.11);
  border-radius: 8px;
  background: white;
  box-shadow: 0 26px 70px rgba(29, 39, 49, 0.22);
}

.result-grid:has(img:nth-child(2)) img {
  max-height: calc((100vh - 246px) / 2);
}

figcaption {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  color: #596575;
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
}

figcaption:empty {
  display: none;
}

.text-button {
  justify-self: center;
  min-height: 32px;
  border: 1px solid rgba(23, 32, 43, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  padding: 0 12px;
  color: var(--blue);
  cursor: pointer;
  font-size: 12px;
  font-weight: 850;
}

.text-button:hover {
  background: #fff;
}

.template-section {
  padding: 38px 0 18px;
}

.section-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  margin-top: 5px;
}

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

.template-card {
  display: grid;
  min-width: 0;
  gap: 8px;
  border: 1px solid rgba(23, 32, 43, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.74);
  padding: 10px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  box-shadow: 0 10px 28px rgba(29, 39, 49, 0.07);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.template-card:hover {
  border-color: rgba(31, 122, 100, 0.28);
  background: #fff;
  box-shadow: 0 18px 42px rgba(29, 39, 49, 0.12);
  transform: translateY(-3px);
}

.template-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 6px;
  object-fit: cover;
}

.template-card span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
}

.template-card strong {
  font-size: 17px;
  line-height: 1.18;
}

.template-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.48;
}

.rules-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid rgba(23, 32, 43, 0.1);
  border-radius: 8px;
  background: rgba(23, 32, 43, 0.12);
  box-shadow: 0 12px 34px rgba(29, 39, 49, 0.07);
}

.rules-band article {
  display: grid;
  gap: 6px;
  background: rgba(255, 255, 255, 0.72);
  padding: 18px;
}

.rules-band strong {
  font-size: 14px;
}

.rules-band span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.58;
}

.hidden {
  display: none;
}

@media (max-width: 1060px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topnav {
    display: none;
  }

  .status-pill {
    max-width: 46vw;
  }

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

  .composer {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  h1 {
    max-width: none;
    font-size: 34px;
  }

  .canvas-panel {
    min-height: 560px;
  }

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

@media (max-width: 840px) {
  .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: 100%;
    padding: 0 0 24px;
  }

  .topbar {
    grid-template-columns: 1fr;
    margin: 0;
    padding: 14px 16px;
  }

  .status-pill {
    width: 100%;
    max-width: none;
    justify-self: stretch;
  }

  .workbench {
    min-height: 0;
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .composer {
    padding: 22px 16px;
  }

  h1 {
    font-size: 30px;
  }

  .prompt-tools {
    flex-direction: column;
  }

  .prompt-actions {
    width: 100%;
  }

  .prompt-actions .ghost-button {
    width: auto;
    flex: 1 1 0;
  }

  .ghost-button {
    width: 100%;
  }

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

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

  textarea {
    min-height: 186px;
  }

  .canvas-toolbar {
    min-height: 64px;
    padding: 0 16px;
  }

  .stage {
    padding: 18px 14px 24px;
  }

  .idle-preview {
    width: min(100%, 460px);
  }

  .template-section {
    padding: 28px 16px 10px;
  }

  .section-head {
    display: block;
  }

  .template-grid,
  .rules-band {
    grid-template-columns: 1fr;
  }

  .rules-band {
    margin: 14px 16px 0;
  }
}

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