:root {
  --bg: #f4f7f6;
  --bg-elev: #ffffff;
  --surface: #ffffff;
  --surface-2: #f0f4f3;
  --text: #16211f;
  --text-soft: #5c6b68;
  --text-faint: #8a9794;
  --border: #e2e9e7;
  --accent: #0f766e;
  --accent-soft: #d6efe9;
  --accent-ink: #0b5850;
  --buy: #b45309;
  --buy-soft: #fde6cf;
  --skip: #15803d;
  --skip-soft: #d8f0df;
  --danger: #b91c1c;
  --shadow: 0 6px 24px rgba(16, 43, 39, 0.08);
  --shadow-lg: 0 12px 40px rgba(16, 43, 39, 0.18);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1413;
    --bg-elev: #121e1c;
    --surface: #142220;
    --surface-2: #1b2b28;
    --text: #e7efed;
    --text-soft: #a7b5b2;
    --text-faint: #7a8885;
    --border: #24352f;
    --accent: #2dd4bf;
    --accent-soft: #12332f;
    --accent-ink: #7ff0e2;
    --buy: #fbbf24;
    --buy-soft: #34281a;
    --skip: #4ade80;
    --skip-soft: #17301f;
    --danger: #f87171;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.55);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

button {
  font: inherit;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface-2);
  transition:
    transform 0.06s ease,
    filter 0.15s ease,
    background 0.15s ease;
}
.btn:active {
  transform: translateY(1px) scale(0.995);
}
.btn-block {
  width: 100%;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  filter: brightness(1.05);
}
.btn-buy {
  background: var(--buy-soft);
  color: var(--buy);
  border-color: transparent;
}
.btn-skip {
  background: var(--skip-soft);
  color: var(--skip);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-soft);
}
.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  padding: 0.4rem 0.2rem;
}
.text-btn.danger {
  color: var(--danger);
  width: 100%;
  margin-top: 0.75rem;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 1.1rem;
  text-decoration: none;
}
.icon-btn:active {
  transform: scale(0.94);
}

/* ---------- Login ---------- */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  padding-top: calc(1.5rem + var(--safe-top));
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.brand h1 {
  font-size: 1.5rem;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 1.1rem;
}
.login-tagline {
  color: var(--text-soft);
  margin: 1rem 0 1.5rem;
}
.login-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 0.4rem;
}
.login-card input {
  width: 100%;
  margin-bottom: 1rem;
}

/* ---------- Inputs ---------- */
input,
textarea,
select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.85rem;
  width: 100%;
}
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}
textarea {
  resize: vertical;
}
.input-prefix {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding-left: 0.75rem;
}
.input-prefix span {
  color: var(--text-faint);
}
.input-prefix input {
  border: none;
  background: transparent;
  padding-left: 0.2rem;
}
.input-prefix input:focus {
  outline: none;
}
.input-prefix:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 0.75rem 0 0;
}

/* ---------- App shell ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}
.app-header-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand-sm {
  font-weight: 650;
  font-size: 1.05rem;
}
.brand-sm .brand-mark {
  width: 1.9rem;
  height: 1.9rem;
  font-size: 0.95rem;
}
.header-actions {
  display: flex;
  gap: 0.5rem;
}
.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1rem calc(6rem + var(--safe-bottom));
}

/* ---------- Metrics ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}
.metric.metric-wide {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.metric-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 600;
}
.metric-value {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 0.15rem;
}
.metric-sub {
  font-size: 0.78rem;
  color: var(--text-soft);
}
.metric.accent .metric-value {
  color: var(--accent);
}
.metric.save .metric-value {
  color: var(--skip);
}

/* ---------- Sections ---------- */
.stack-section {
  margin-bottom: 2rem;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.2rem;
}
.section-head h2 {
  font-size: 1.15rem;
}
.section-sub {
  color: var(--text-soft);
  font-size: 0.9rem;
  margin: 0 0 0.9rem;
}
.pill {
  display: inline-grid;
  place-items: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 0.8rem;
  font-weight: 700;
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* ---------- Purchase card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card.eligible {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}
.card-name {
  font-weight: 650;
  font-size: 1.05rem;
}
.card-price {
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  border: 1px solid var(--border);
}

/* Countdown */
.countdown {
  margin-top: 0.85rem;
}
.countdown-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.countdown-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-ink));
  transition: width 0.5s linear;
}
.countdown-label {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-soft);
}
.countdown-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--text);
}

.ready-banner {
  margin-top: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.9rem;
}
.card-actions .btn {
  flex: 1;
  padding: 0.7rem 0.5rem;
  font-size: 0.92rem;
}

.reflect-note {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-soft);
}
.status-chip {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.status-purchased {
  background: var(--buy-soft);
  color: var(--buy);
}
.status-skipped {
  background: var(--skip-soft);
  color: var(--skip);
}
.status-archived {
  background: var(--surface-2);
  color: var(--text-faint);
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: 1.75rem 1rem;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.empty-emoji {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 0.4rem;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed;
  right: 1.1rem;
  bottom: calc(1.1rem + var(--safe-bottom));
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.9rem;
  line-height: 1;
  box-shadow: var(--shadow-lg);
  z-index: 20;
  display: grid;
  place-items: center;
}
.fab:active {
  transform: scale(0.94);
}

/* ---------- Sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 20, 18, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease;
}
@keyframes fade {
  from {
    opacity: 0;
  }
}
.sheet {
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 22px 22px 0 0;
  padding: 0.5rem 1.1rem calc(1.4rem + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  animation: slideup 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slideup {
  from {
    transform: translateY(100%);
  }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  margin: 0.35rem auto 0.5rem;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.sheet-head h2 {
  font-size: 1.2rem;
}
.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  flex: 1;
}
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
}
.field-row {
  display: flex;
  gap: 0.75rem;
}

.reflect {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0.25rem 0.85rem;
}
.reflect summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent);
  padding: 0.6rem 0;
  list-style: none;
}
.reflect summary::-webkit-details-marker {
  display: none;
}
.reflect summary::before {
  content: "＋ ";
}
.reflect[open] summary::before {
  content: "− ";
}
.reflect-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-bottom: 0.85rem;
}

.need-scale {
  display: flex;
  gap: 0.4rem;
}
.need-opt {
  flex: 1;
}
.need-opt input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.need-opt span {
  display: grid;
  place-items: center;
  padding: 0.6rem 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  color: var(--text-soft);
}
.need-opt input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.need-opt input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.scale-legend {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-faint);
}

.decision-item {
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0;
}
.decision-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.decision-actions .btn {
  padding: 0.9rem 0.5rem;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(5.5rem + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  animation: fade 0.15s ease;
  max-width: 90vw;
  text-align: center;
}

@media (min-width: 560px) {
  .metrics {
    grid-template-columns: repeat(3, 1fr);
  }
}
