:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --border: rgba(15, 17, 21, 0.08);
  --border-strong: rgba(15, 17, 21, 0.15);
  --text: #0f1115;
  --text-muted: rgba(15, 17, 21, 0.62);
  --text-faint: rgba(15, 17, 21, 0.42);
  --accent: #2c5cff;
  --accent-strong: #1c44d6;
  --accent-on: #ffffff;
  --success: #2c8a4d;
  --danger: #c0392b;
  --shadow-soft: 0 1px 2px rgba(15, 17, 21, 0.04), 0 8px 24px rgba(15, 17, 21, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --gap: clamp(12px, 2.5vw, 18px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #15181f;
    --surface-strong: #1b1f29;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --text: #f3f4f6;
    --text-muted: rgba(243, 244, 246, 0.72);
    --text-faint: rgba(243, 244, 246, 0.45);
    --accent: #6c8bff;
    --accent-strong: #8aa2ff;
    --accent-on: #0e1014;
    --success: #58c585;
    --danger: #ff6f60;
    --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 28px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Inter", "Helvetica Neue", Arial, sans-serif;
  min-height: 100%;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.workspace {
  max-width: 720px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) clamp(14px, 4vw, 28px) max(env(safe-area-inset-bottom), 24px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.workspace__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 6px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand__logo {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background:
    radial-gradient(circle at 30% 30%, var(--accent), var(--accent-strong) 70%);
}

.brand__name {
  font-size: 16px;
}

.workspace__meta {
  font-size: 13px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 18px;
}

.workspace__meta a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.recovery {
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--border));
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 10px;
}

.recovery__text {
  margin: 0;
  font-size: 14px;
  flex: 1;
}

.recovery__close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 8px;
}

.recovery__close:hover {
  background: var(--border);
  color: var(--text);
}

.stage {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(16px, 3vw, 22px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-soft);
}

.stage__title {
  margin: 0;
  font-size: clamp(18px, 2.6vw, 22px);
  font-weight: 600;
  letter-spacing: -0.005em;
}

.stage__preview {
  position: relative;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong);
  background: color-mix(in srgb, var(--surface-strong) 60%, var(--bg));
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage__preview[data-empty="false"] {
  border-style: solid;
}

.stage__file {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.stage__file-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 18px;
  font: inherit;
  cursor: pointer;
}

.stage__file-icon {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  position: relative;
}

.stage__file-icon::before,
.stage__file-icon::after {
  content: "";
  position: absolute;
  background: var(--accent);
  border-radius: 2px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.stage__file-icon::before {
  width: 18px;
  height: 2px;
}

.stage__file-icon::after {
  width: 2px;
  height: 18px;
}

.stage__file-label {
  font-size: 15px;
  font-weight: 600;
}

.stage__file-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.stage__image {
  display: none;
  max-width: 100%;
  max-height: min(60vh, 520px);
  object-fit: contain;
  background: #000;
}

.stage__preview[data-empty="false"] .stage__image {
  display: block;
}

.stage__preview[data-empty="false"] .stage__file-btn {
  display: none;
}

.stage__replace {
  position: absolute;
  right: 10px;
  top: 10px;
  padding: 6px 12px;
  font-size: 12px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.stage__upload-state {
  position: absolute;
  left: 12px;
  bottom: 12px;
  font-size: 12px;
  color: var(--text-muted);
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.stage__upload-state:empty {
  display: none;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.composer__label {
  font-size: 13px;
  color: var(--text-muted);
}

.composer textarea {
  resize: vertical;
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-strong);
  color: var(--text);
  font: inherit;
  min-height: 96px;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.composer__counter {
  align-self: flex-end;
  font-size: 12px;
  color: var(--text-faint);
}

.actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: stretch;
}

.actions__primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--accent);
  color: var(--accent-on);
  border: 0;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
  transition: background 120ms ease, transform 80ms ease;
}

.actions__primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.actions__primary:active:not(:disabled) {
  transform: translateY(1px);
}

.actions__primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.actions__primary-cost {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}

.actions__primary-cost:empty {
  display: none;
}

.actions__secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
  min-height: 48px;
}

.actions__secondary:hover {
  background: var(--surface-strong);
}

.actions__secondary-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.actions__secondary-hint:empty {
  display: none;
}

.actions__secondary-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  min-height: 18px;
}

.status[data-tone="error"] {
  color: var(--danger);
}

.status[data-tone="success"] {
  color: var(--success);
}

.result {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.result__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.result__image {
  width: 100%;
  max-height: min(70vh, 640px);
  object-fit: contain;
  background: #000;
  border-radius: var(--radius-sm);
}

.result__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.result__download {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--accent);
  color: var(--accent-on);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
}

.result__again {
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}

.result__hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--shadow-soft);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  max-width: min(96vw, 520px);
  z-index: 20;
}

.toast__action {
  background: transparent;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  padding: 4px 6px;
}

.workspace[data-state="generating"] .actions__primary {
  background: var(--accent-strong);
  cursor: progress;
}

.workspace[data-state="generating"] .actions__primary-label::after {
  content: "…";
}

@media (max-width: 480px) {
  .actions {
    grid-template-columns: 1fr;
  }
  .actions__secondary {
    justify-content: center;
  }
}
