/* ============================================================
   Prompt Studio - Apple-level Prompt Optimizer
   Inspired by aojiang.space visual language
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #050505;
  --bg-1: #0a0a0a;
  --bg-2: #111111;
  --bg-glass: rgba(255,255,255,0.05);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.20);
  --text-1: rgba(255,255,255,0.92);
  --text-2: rgba(255,255,255,0.56);
  --text-3: rgba(255,255,255,0.30);
  --accent: #f5f5f7;
  --accent-ink: #050505;
  --accent-soft: rgba(150, 170, 255, 0.20);
  --success: #34d399;
  --danger: #fb7185;
  --nav-bg: rgba(5,5,5,0.78);
  --card-bg: rgba(255,255,255,0.028);
  --shadow: rgba(0,0,0,0.56);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 0.28s;
  --t-base: 0.62s;
  --t-slow: 1s;
}

[data-theme="light"] {
  --bg: #f4f3f1;
  --bg-1: #faf9f7;
  --bg-2: #efeeeb;
  --bg-glass: rgba(255,255,255,0.70);
  --border: rgba(0,0,0,0.08);
  --border-hover: rgba(0,0,0,0.22);
  --text-1: rgba(0,0,0,0.88);
  --text-2: rgba(0,0,0,0.54);
  --text-3: rgba(0,0,0,0.30);
  --accent: #141414;
  --accent-ink: #ffffff;
  --accent-soft: rgba(80, 110, 230, 0.14);
  --nav-bg: rgba(244,243,241,0.82);
  --card-bg: rgba(255,255,255,0.54);
  --shadow: rgba(0,0,0,0.10);
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.055), transparent 34%),
    linear-gradient(225deg, rgba(120,150,255,0.10), transparent 30%),
    var(--bg);
  color: var(--text-1);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  overflow-x: hidden;
  transition: background var(--t-fast) var(--ease-out), color var(--t-fast) var(--ease-out);
}

[data-theme="light"] body {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.95), transparent 36%),
    linear-gradient(225deg, rgba(120,140,255,0.13), transparent 32%),
    var(--bg);
}

button, textarea { font: inherit; }
button { border: 0; background: none; color: inherit; cursor: pointer; }
button:disabled { cursor: wait; }
a { color: inherit; text-decoration: none; }
::selection { background: rgba(255,255,255,0.16); }
[data-theme="light"] ::selection { background: rgba(0,0,0,0.12); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.45), transparent 68%);
  z-index: -1;
}

.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: 64px;
  display: flex;
  align-items: center;
  padding: 0 48px;
  background: transparent;
  border-bottom: 1px solid transparent;
  transition: background var(--t-fast) var(--ease-out),
              border-color var(--t-fast) var(--ease-out),
              backdrop-filter var(--t-fast) var(--ease-out);
}

.navbar.scrolled {
  background: var(--nav-bg);
  border-color: var(--border);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.nav-logo {
  flex: 1;
  font-size: 18px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text-1);
}

.nav-links {
  display: flex;
  gap: 32px;
}

.nav-links a {
  color: var(--text-2);
  font-size: 14px;
  font-weight: 460;
  transition: color var(--t-fast);
}

.nav-links a:hover { color: var(--text-1); }

.nav-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 28px;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  border: 1px solid transparent;
  transition: color var(--t-fast), background var(--t-fast), border-color var(--t-fast), transform var(--t-fast);
}

.icon-button svg { width: 18px; height: 18px; stroke-width: 1.8; }
.icon-button:hover {
  color: var(--text-1);
  background: var(--bg-glass);
  border-color: var(--border);
}

.icon-button.small {
  width: 34px;
  height: 34px;
}

.hero-shell {
  width: min(1180px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 128px 0 72px;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.38fr);
  gap: 28px;
  align-items: center;
}

.hero-copy {
  padding: 24px 0;
}

.eyebrow,
.panel-kicker {
  display: inline-flex;
  color: var(--text-3);
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

h1 {
  color: var(--text-1);
  font-size: clamp(42px, 5.6vw, 72px);
  line-height: 1.06;
  letter-spacing: -0.03em;
  font-weight: 760;
  max-width: 600px;
}

.subtitle {
  color: var(--text-2);
  font-size: clamp(16px, 1.5vw, 19px);
  line-height: 1.72;
  max-width: 480px;
  margin-top: 24px;
}

.workspace,
.result-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--card-bg), rgba(255,255,255,0.014));
  box-shadow: 0 22px 80px var(--shadow);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 1px;
  overflow: hidden;
  border-radius: 28px;
}

.input-panel,
.status-panel {
  min-width: 0;
  background: rgba(255,255,255,0.018);
}

[data-theme="light"] .input-panel,
[data-theme="light"] .status-panel {
  background: rgba(255,255,255,0.34);
}

.input-panel {
  padding: 28px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-head h2 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--text-1);
}

.soft-pill {
  flex-shrink: 0;
  border: 1px solid var(--border);
  color: var(--text-3);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

textarea {
  width: 100%;
  min-height: 306px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 18px;
  outline: 0;
  background: rgba(0,0,0,0.20);
  color: var(--text-1);
  padding: 20px;
  font-size: 16px;
  line-height: 1.72;
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}

[data-theme="light"] textarea { background: rgba(255,255,255,0.62); }
textarea::placeholder { color: var(--text-3); }
textarea:focus {
  border-color: var(--border-hover);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin: 16px 0 22px;
}

.chip,
.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.chip {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--text-2);
  font-size: 13px;
  transition: color var(--t-fast), border-color var(--t-fast), transform var(--t-fast), background var(--t-fast);
}

.chip:hover {
  color: var(--text-1);
  border-color: var(--border-hover);
  background: var(--bg-glass);
  transform: translateY(-1px);
}

.action-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  gap: 8px;
  height: 46px;
  border-radius: 999px;
  padding: 0 22px;
  font-size: 14px;
  font-weight: 560;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast), opacity var(--t-fast), border-color var(--t-fast);
}

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

.primary-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px var(--accent-soft);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.ghost-button {
  border: 1px solid var(--border);
  color: var(--text-2);
}

.ghost-button:hover {
  border-color: var(--border-hover);
  color: var(--text-1);
  transform: translateY(-2px);
}

.primary-button svg,
.ghost-button svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.9;
}

.status-panel {
  padding: 22px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}

.stage {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 12px;
  padding: 14px 0;
  opacity: 0.42;
  transition: opacity var(--t-fast), transform var(--t-fast);
}

.stage strong {
  display: block;
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.2;
  margin-bottom: 4px;
}

.stage p {
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.48;
}

.stage-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-top: 4px;
  background: var(--border-hover);
  box-shadow: 0 0 0 5px rgba(255,255,255,0.035);
}

.stage.active,
.stage.complete {
  opacity: 1;
}

.stage.active .stage-dot {
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.stage.complete .stage-dot {
  background: var(--success);
  box-shadow: 0 0 18px rgba(52,211,153,0.28);
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.72; }
  50% { transform: scale(1.34); opacity: 1; }
}

.result-section {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 12px 0 34px;
}

.question-section,
.history-section {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto 18px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, var(--card-bg), rgba(255,255,255,0.012));
  box-shadow: 0 18px 64px var(--shadow);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
}

.question-section.is-hidden {
  display: none;
}

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

.section-head h2 {
  color: var(--text-1);
  font-size: clamp(22px, 2.6vw, 30px);
  line-height: 1.16;
  letter-spacing: -0.02em;
  font-weight: 720;
}

.question-list {
  display: grid;
  gap: 12px;
}

.question-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background: rgba(255,255,255,0.018);
}

[data-theme="light"] .question-card {
  background: rgba(255,255,255,0.46);
}

.question-card-head {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.question-index {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.question-card h3 {
  color: var(--text-1);
  font-size: 16px;
  line-height: 1.45;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.question-card p {
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.55;
  margin-top: 4px;
}

.option-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px 56px;
}

.option-chip {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 13px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.35;
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}

.option-chip:hover,
.option-chip.selected {
  color: var(--text-1);
  border-color: var(--border-hover);
  background: var(--bg-glass);
  transform: translateY(-1px);
}

.answer-input {
  min-height: 76px;
  resize: vertical;
  border-radius: 14px;
  padding: 14px;
  font-size: 14px;
  line-height: 1.6;
}

.answer-input.invalid {
  border-color: rgba(251,113,133,0.72);
  box-shadow: 0 0 0 4px rgba(251,113,133,0.12);
}

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

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
}

.result-card {
  border-radius: 22px;
  padding: 24px;
  min-width: 0;
}

.final-card {
  background: linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0.016));
}

.button-cluster {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-height: 320px;
  max-height: 520px;
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(0,0,0,0.22);
  color: var(--text-2);
  font-family: "SF Mono", "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.72;
}

[data-theme="light"] pre { background: rgba(255,255,255,0.56); }

.refine-box {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 10px;
}

.refine-box label {
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.5;
}

.refine-box textarea {
  min-height: 94px;
  max-height: 180px;
  border-radius: 16px;
  padding: 15px;
  font-size: 14px;
  line-height: 1.65;
}

.refine-box .ghost-button {
  justify-self: start;
}

.history-section {
  margin-bottom: 18px;
}

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

.history-item {
  min-width: 0;
  min-height: 86px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 15px;
  background: rgba(255,255,255,0.018);
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: border-color var(--t-fast), background var(--t-fast), transform var(--t-fast);
}

.history-item:hover {
  border-color: var(--border-hover);
  background: var(--bg-glass);
  transform: translateY(-2px);
}

.history-title {
  color: var(--text-1);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.history-date {
  color: var(--text-3);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.empty-state {
  grid-column: 1 / -1;
  color: var(--text-3);
  font-size: 14px;
  padding: 18px 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 40;
  min-width: 150px;
  max-width: calc(100% - 32px);
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--nav-bg);
  color: var(--text-1);
  backdrop-filter: blur(22px) saturate(180%);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  box-shadow: 0 16px 50px var(--shadow);
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
  transition: opacity var(--t-fast), transform var(--t-fast);
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

.more-tools {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto 78px;
  padding: 24px 26px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: linear-gradient(180deg, var(--card-bg), rgba(255,255,255,0.012));
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.more-tools h2 {
  color: var(--text-1);
  font-size: clamp(22px, 2.6vw, 30px);
  line-height: 1.16;
  letter-spacing: -0.02em;
  font-weight: 720;
}

.more-tools-link {
  min-height: 46px;
  border-radius: 999px;
  padding: 0 20px;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 560;
  white-space: nowrap;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-fast);
}

.more-tools-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 36px var(--accent-soft);
}

.more-tools-link svg {
  width: 17px;
  height: 17px;
  stroke-width: 1.9;
}

.reveal-item {
  opacity: 0;
  transform: translateY(18px);
  filter: blur(6px);
  animation: revealIn var(--t-slow) var(--ease-out) forwards;
}

.reveal-item:nth-child(2) { animation-delay: 0.12s; }

@keyframes revealIn {
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}

@media (max-width: 980px) {
  .hero-shell {
    grid-template-columns: 1fr;
    padding-top: 104px;
    gap: 22px;
  }

  .hero-copy {
    padding-bottom: 0;
  }

  h1 { max-width: 760px; }
  .subtitle { max-width: 620px; }

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

  .history-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .navbar {
    height: 58px;
    padding: 0 20px;
  }

  .nav-links { display: none; }
  .nav-controls { margin-left: 12px; }

  .hero-shell,
  .result-section,
  .question-section,
  .history-section {
    width: min(100% - 28px, 1180px);
  }

  .hero-shell {
    min-height: auto;
    padding: 92px 0 38px;
  }

  h1 {
    font-size: clamp(38px, 12vw, 54px);
  }

  .subtitle {
    margin-top: 18px;
    font-size: 16px;
  }

  .workspace {
    grid-template-columns: 1fr;
    border-radius: 22px;
  }

  .input-panel {
    padding: 20px;
  }

  .status-panel {
    border-left: 0;
    border-top: 1px solid var(--border);
    padding: 14px 20px 18px;
  }

  .stage {
    padding: 10px 0;
  }

  textarea {
    min-height: 238px;
    border-radius: 16px;
    padding: 16px;
  }

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

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .result-section {
    padding-bottom: 54px;
  }

  .question-section,
  .history-section {
    padding: 18px;
    border-radius: 20px;
  }

  .section-head {
    flex-direction: column;
    gap: 8px;
  }

  .question-card {
    padding: 16px;
  }

  .question-card-head {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .question-index {
    width: auto;
    height: 26px;
    border-radius: 999px;
    padding: 0 10px;
    justify-self: start;
  }

  .option-row {
    margin-left: 0;
  }

  .question-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .question-actions .primary-button,
  .question-actions .ghost-button,
  .refine-box .ghost-button {
    width: 100%;
  }

  .more-tools {
    width: min(100% - 28px, 1180px);
    margin-bottom: 42px;
    padding: 20px;
    border-radius: 20px;
    align-items: stretch;
    flex-direction: column;
  }

  .more-tools-link {
    width: 100%;
  }

  .result-card {
    padding: 18px;
    border-radius: 20px;
  }

  pre {
    min-height: 240px;
    max-height: 440px;
  }
}

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