:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #5c5c5c;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --error: #b91c1c;
  --error-bg: #fef2f2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

header {
  margin-bottom: 2.5rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.optional {
  font-weight: 400;
  color: var(--text-muted);
}

.field {
  margin-bottom: 1.25rem;
}

textarea,
input[type="text"] {
  width: 100%;
  padding: 0.75rem 1rem;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}

textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

#rough-prompt {
  min-height: 160px;
  resize: vertical;
}

#output-hint,
#passcode {
  font-size: 0.95rem;
}

.passcode-field {
  margin-bottom: 1.5rem;
}

.passcode-hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.actions {
  margin-bottom: 2rem;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  transition: background 0.15s ease, opacity 0.15s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-primary {
  padding: 0.7rem 1.5rem;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary.loading {
  position: relative;
  color: transparent;
}

.btn-primary.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 1.1rem;
  height: 1.1rem;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.result-section {
  display: none;
}

.result-section.visible {
  display: block;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.result-header h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 500;
}

.btn-secondary {
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--accent);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(37, 99, 235, 0.06);
}

#refined-prompt {
  min-height: 200px;
  resize: vertical;
  font-size: 0.95rem;
  line-height: 1.65;
  white-space: pre-wrap;
}

.error {
  display: none;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
}

.error.visible {
  display: block;
}

@media (max-width: 480px) {
  .container {
    padding: 2rem 1rem 3rem;
  }

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