:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f0f3f8;
  --ink: #12151b;
  --muted: #687182;
  --subtle: #9aa3b2;
  --line: #dfe5ef;
  --dark: #171a22;
  --dark-2: #222838;
  --amber: #ff6b35;
  --amber-dark: #d94f20;
  --green: #16835c;
  --red: #ba3d4a;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(1680px, calc(100vw - 32px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 18px 0;
}

.topbar {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-mark {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand-mark span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark strong {
  color: var(--ink);
  font-size: 22px;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.text-action,
.mode-badge,
.quota-badge {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  padding: 0 13px;
  font-size: 13px;
  font-weight: 750;
}

.text-action {
  transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}

.text-action:hover {
  border-color: #c8cac2;
  background: var(--surface);
  color: var(--ink);
}

.mode-badge {
  border-color: rgba(31, 141, 90, 0.18);
  background: rgba(31, 141, 90, 0.09);
  color: var(--green);
}

.studio {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(430px, 1fr) minmax(260px, 330px);
  gap: 16px;
  min-height: calc(100svh - 72px);
}

.composer,
.preview-plane,
.history-panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.composer {
  display: flex;
  flex-direction: column;
  overflow: auto;
  padding: 18px;
}

.composer-section {
  border-bottom: 1px solid var(--line);
  padding: 0 0 18px;
  margin-bottom: 18px;
}

.composer-section:last-of-type {
  border-bottom: 0;
  margin-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title span {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--dark);
  color: #fff;
  font-size: 12px;
  font-weight: 850;
}

.section-title h2 {
  font-size: 17px;
  letter-spacing: 0;
}

.prompt-box,
.product-mini label {
  display: grid;
  gap: 8px;
}

.prompt-box span,
.product-mini label span,
.choice-group p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

input,
textarea {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--ink);
  outline: none;
  padding: 12px 13px;
  transition: background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

textarea {
  min-height: 154px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: rgba(255, 138, 0, 0.42);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(255, 138, 0, 0.12);
}

.product-mini {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  gap: 13px;
  margin-top: 14px;
}

.product-mini img {
  width: 104px;
  aspect-ratio: 1;
  border-radius: 12px;
  background: var(--surface-soft);
  object-fit: cover;
}

.product-mini > div {
  display: grid;
  gap: 12px;
}

.extract-title {
  color: var(--ink);
  font-size: 16px;
  font-weight: 850;
}

.extract-copy {
  max-width: 360px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.prompt-entry .extract-copy {
  margin-top: 12px;
}

.choice-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.choice-group p {
  flex: 0 0 100%;
}

.choice,
.direction-card,
.switch-pill,
.secondary-action {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--ink);
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.choice {
  min-height: 36px;
  padding: 0 12px;
  color: #42443f;
  font-size: 13px;
  font-weight: 780;
}

.choice:hover,
.direction-card:hover,
.switch-pill:hover,
.secondary-action:hover:not([disabled]) {
  transform: translateY(-1px);
  border-color: #c7c9c1;
  background: #fff;
}

.choice.active,
.direction-card.active {
  border-color: var(--dark);
  background: var(--dark);
  color: #fff;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.mode-tab,
.upload-box {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink);
}

.mode-tab {
  min-height: 44px;
  font-size: 14px;
  font-weight: 850;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease;
}

.mode-tab:hover {
  transform: translateY(-1px);
  border-color: #c7c9d2;
  background: #fff;
}

.mode-tab.active {
  border-color: var(--dark);
  background: var(--dark);
  color: #fff;
}

.mode-panel[hidden] {
  display: none;
}

.upload-box {
  display: grid;
  min-height: 92px;
  place-items: center;
  padding: 16px;
  text-align: center;
  transition: border-color 150ms ease, background 150ms ease;
}

.upload-box:hover {
  border-color: #c7c9d2;
  background: #fff;
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-box span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 820;
}

.compact-prompt {
  margin-top: 12px;
}

.direction-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.direction-card {
  display: grid;
  gap: 5px;
  min-height: 70px;
  padding: 13px;
  text-align: left;
}

.direction-card strong {
  font-size: 14px;
}

.direction-card span {
  color: var(--muted);
  font-size: 13px;
}

.direction-card.active span {
  color: rgba(255, 255, 255, 0.72);
}

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

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

.switch-pill {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  font-size: 13px;
  font-weight: 820;
}

.wide-switch {
  width: 100%;
  justify-content: flex-start;
  padding: 0 13px;
}

.switch-pill input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  border: 0;
  background: transparent;
  padding: 0;
  accent-color: var(--amber);
}

.submit-bar {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 14px;
}

.form-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 720;
}

.form-message.error {
  color: var(--red);
}

.primary-action {
  display: inline-flex;
  width: 100%;
  height: 50px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 12px;
  background: var(--amber);
  color: #18130b;
  font-size: 16px;
  font-weight: 900;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.primary-action:hover {
  background: #ff9a22;
  transform: translateY(-1px);
}

.primary-action[disabled] {
  cursor: not-allowed;
  opacity: 0.68;
  transform: none;
}

.preview-plane {
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  gap: 14px;
  overflow: hidden;
  padding: 18px;
}

.preview-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.preview-head p {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.preview-head h1 {
  max-width: 720px;
  font-size: clamp(24px, 3vw, 42px);
  line-height: 1.04;
  letter-spacing: 0;
}

.state-chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 14px;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.state-chip.done {
  background: rgba(31, 141, 90, 0.1);
  color: var(--green);
}

.state-chip.busy {
  background: rgba(255, 138, 0, 0.12);
  color: var(--amber-dark);
}

.stage-wrap {
  display: grid;
  min-height: 0;
  place-items: center;
  border-radius: 14px;
  background: var(--dark);
  padding: 18px;
}

.phone-stage {
  position: relative;
  width: min(380px, 100%);
  max-height: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 28px;
  background: #0d0d0c;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.poster,
.poster img,
.phone-stage video {
  width: 100%;
  height: 100%;
}

.poster {
  position: relative;
  display: block;
}

.poster img {
  display: block;
  object-fit: cover;
  filter: saturate(0.9) contrast(1.02);
}

.poster::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0.08), transparent 40%, rgba(0,0,0,0.76));
}

.poster-copy {
  position: absolute;
  z-index: 1;
  inset: auto 22px 24px;
  color: #fff;
}

.poster-copy span {
  display: inline-flex;
  margin-bottom: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(10px);
}

.poster-copy strong {
  display: block;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0;
}

.poster-copy p {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.82);
  line-height: 1.45;
}

.phone-stage video {
  display: block;
  object-fit: cover;
}

.phone-stage.busy::before {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  background: rgba(10, 10, 9, 0.26);
}

.phone-stage.busy::after {
  content: "";
  position: absolute;
  z-index: 3;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 3px solid rgba(255, 255, 255, 0.24);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 960ms linear infinite;
}

.progress-panel {
  display: grid;
  gap: 12px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--amber);
  transition: width 240ms ease;
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.steps span {
  color: var(--subtle);
  font-size: 12px;
  font-weight: 820;
  text-align: center;
}

.steps span.active {
  color: var(--ink);
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.mobile-action-bar {
  display: none;
}

.secondary-action {
  min-height: 42px;
  padding: 0 10px;
  color: #42443f;
  font-size: 13px;
  font-weight: 820;
}

.secondary-action[disabled] {
  cursor: not-allowed;
  opacity: 0.5;
}

.history-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  padding: 16px;
}

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

.history-head h2 {
  font-size: 17px;
}

.history-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  padding: 8px;
  text-align: left;
}

.history-item img {
  width: 58px;
  aspect-ratio: 9 / 12;
  border-radius: 9px;
  object-fit: cover;
}

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

.history-item strong {
  font-size: 13px;
}

.history-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.history-item small {
  margin-top: 7px;
  color: var(--green);
  font-size: 12px;
  font-weight: 850;
}

.empty-history {
  display: grid;
  min-height: 140px;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  text-align: center;
}

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

@media (max-width: 1180px) {
  .studio {
    grid-template-columns: minmax(340px, 420px) minmax(0, 1fr);
  }

  .history-panel {
    grid-column: 1 / -1;
    min-height: 220px;
  }

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

@media (max-width: 820px) {
  body {
    background: #f2f5fa;
  }

  .app-shell {
    width: 100%;
    padding: 0 10px 92px;
  }

  .topbar {
    position: sticky;
    z-index: 10;
    top: 0;
    align-items: flex-start;
    gap: 8px;
    margin: 0 -10px 10px;
    border-bottom: 1px solid rgba(223, 229, 239, 0.78);
    background: rgba(245, 247, 251, 0.92);
    padding: 10px;
    backdrop-filter: blur(16px);
  }

  .brand-mark {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .brand-mark strong {
    font-size: 24px;
    line-height: 1.08;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .studio {
    grid-template-columns: 1fr;
    min-height: auto;
    gap: 10px;
  }

  .preview-plane {
    grid-row: 2;
    gap: 12px;
    padding: 14px;
  }

  .composer {
    grid-row: 1;
    margin-bottom: 72px;
    overflow: visible;
    padding: 14px;
  }

  .composer-section {
    margin-bottom: 14px;
    padding-bottom: 14px;
  }

  .section-title {
    margin-bottom: 11px;
  }

  .history-panel {
    grid-row: 3;
    min-height: 220px;
  }

  .preview-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .preview-head h1 {
    font-size: 25px;
    line-height: 1.08;
  }

  .stage-wrap {
    min-height: auto;
    padding: 12px;
  }

  .phone-stage {
    width: min(292px, 88vw);
    border-radius: 22px;
  }

  .poster-copy {
    inset: auto 18px 20px;
  }

  .poster-copy strong {
    font-size: 22px;
  }

  textarea {
    min-height: 108px;
  }

  input,
  textarea {
    border-radius: 12px;
    font-size: 16px;
  }

  .choice {
    min-height: 42px;
    padding: 0 14px;
    font-size: 14px;
  }

  .switch-pill {
    min-height: 44px;
    justify-content: flex-start;
  }

  .submit-bar .primary-action {
    display: none;
  }

  .form-message {
    min-height: 18px;
  }

  .prompt-entry .extract-copy {
    margin-top: 8px;
  }

  .mobile-action-bar {
    position: fixed;
    z-index: 20;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    border: 1px solid rgba(223, 229, 239, 0.92);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.94);
    padding: 8px;
    box-shadow: 0 16px 50px rgba(23, 26, 34, 0.16);
    backdrop-filter: blur(18px);
  }

  .mobile-action-bar span {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-action-bar span.error {
    color: var(--red);
  }

  .mobile-submit {
    width: auto;
    min-width: 118px;
    height: 42px;
    border-radius: 12px;
    padding: 0 16px;
    font-size: 14px;
  }

  .product-mini,
  .two-column,
  .switch-grid,
  .result-actions,
  .history-list {
    grid-template-columns: 1fr;
  }

  .product-mini img {
    width: 100%;
    max-height: 180px;
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 390px) {
  .choice-group {
    gap: 7px;
  }

  .choice {
    padding: 0 12px;
  }

  .phone-stage {
    width: min(270px, 86vw);
  }

  .steps span {
    font-size: 11px;
  }
}
