:root {
  --bg: #0b0d10;
  --surface: #151921;
  --surface-hi: #1f2531;
  --border: #272f3d;
  --ink: #f4f7fb;
  --ink-muted: #98a4b8;
  --primary: #a8c7fa;
  --on-primary: #062e6f;
  --tonal: #1c3456;
  --on-tonal: #d3e3fd;
  --ok: #c4eed0;
  --ok-bg: #111e17;
  --ok-border: #244a35;
  --err: #f2b8b5;
  --err-bg: #2e1315;
  --err-border: #6b262a;
  --radius-card: 22px;
  --radius-btn: 16px;
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: max(16px, env(safe-area-inset-top)) 16px
    max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-icon {
  border-radius: 10px;
  flex-shrink: 0;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.15rem, 3.8vw, 1.35rem);
  font-weight: 700;
  line-height: 1.2;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.btn-install {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--tonal);
  color: var(--on-tonal);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-install:active {
  transform: scale(0.98);
}

/* Selector de pestanas (Foto / Texto manual) */
.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.tab-btn {
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-muted);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.tab-btn.is-active {
  background: var(--tonal);
  color: var(--on-tonal);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 16px;
}

.capture-card,
.manual-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-frame {
  position: relative;
  width: 100%;
  min-height: 220px;
  border-radius: 16px;
  background: #0f1319;
  border: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 140ms ease, background-color 140ms ease;
}

.preview-frame.drag-over {
  border-color: var(--primary);
  background: #141c28;
}

.preview-frame.has-image {
  border-style: solid;
  min-height: 180px;
}

.empty-state {
  padding: 28px 20px;
  text-align: center;
  max-width: 320px;
}

.camera-glyph {
  color: var(--primary);
  margin-bottom: 10px;
}

.empty-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.empty-hint {
  margin: 6px 0 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

.preview-img {
  width: 100%;
  max-height: 46dvh;
  object-fit: contain;
  display: block;
  background: #080a0d;
}

.preview-meta {
  width: 100%;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #11151d;
  border-top: 1px solid var(--border);
}

.meta-pill {
  font-size: 0.82rem;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.btn-clear {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.source-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (max-width: 340px) {
  .source-actions {
    grid-template-columns: 1fr;
  }
}

.btn {
  min-height: 52px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-btn);
  font: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 100ms ease, opacity 120ms ease, background-color 120ms ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

.btn:focus-visible,
.btn-install:focus-visible,
.btn-clear:focus-visible,
.tab-btn:focus-visible,
.manual-textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.btn-tonal {
  background: var(--tonal);
  color: var(--on-tonal);
}

.btn-surface {
  background: var(--surface-hi);
  color: var(--ink);
  border: 1px solid var(--border);
}

.btn-primary {
  width: 100%;
  min-height: 54px;
  border-radius: 999px;
  background: var(--primary);
  color: var(--on-primary);
  font-size: 1.02rem;
  font-weight: 700;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Modo manual */
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.field-label {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink);
}

.manual-textarea {
  width: 100%;
  min-height: 164px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #0f1319;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: vertical;
}

.manual-textarea::placeholder {
  color: #6b7689;
}

.clean-preview {
  border-radius: 14px;
  background: #0f1319;
  border: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clean-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.clean-kicker {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.clean-text {
  margin: 0;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.94rem;
  line-height: 1.45;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

.topic-caption {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.topic-caption code {
  color: var(--on-tonal);
  background: #101824;
  padding: 2px 7px;
  border-radius: 6px;
}

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

.feedback-card.is-ok {
  border-color: var(--ok-border);
  background: var(--ok-bg);
}

.feedback-card.is-err {
  border-color: var(--err-border);
  background: var(--err-bg);
}

.feedback-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.feedback-card.is-ok .feedback-title {
  color: var(--ok);
}

.feedback-card.is-err .feedback-title {
  color: var(--err);
}

.feedback-detail {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  color: var(--ink-muted);
  word-break: break-word;
}

/* Resultado Paso 1 */
.result-card {
  border-color: var(--ok-border);
  background: var(--ok-bg);
}

.result-kicker {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ok);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.result-size {
  margin: 6px 0 14px;
  font-size: clamp(2rem, 8vw, 2.5rem);
  font-weight: 800;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.result-grid {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid #213e2d;
}

.result-grid dt {
  font-size: 0.76rem;
  color: var(--ink-muted);
}

.result-grid dd {
  margin: 4px 0 0;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.result-note {
  margin: 12px 0 0;
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.error-box {
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--err-bg);
  border: 1px solid var(--err-border);
  color: var(--err);
  font-size: 0.9rem;
}

.statusbar {
  margin-top: auto;
  padding-top: 4px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-muted);
}

.status-dot::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  background: var(--ink-muted);
}

.status-dot.ready::before {
  background: var(--ok);
}

@media (min-width: 640px) {
  .app {
    padding-top: 32px;
    padding-bottom: 32px;
    gap: 20px;
  }

  .card {
    padding: 20px;
  }
}
