/* Alibi styles — mobile-first, works from 375px up, light + dark, safe-area
   aware, all interactive targets at least 44x44px. System fonts only. */

:root {
  --bg: #f6f6fb;
  --surface: #ffffff;
  --surface-2: #eeeef6;
  --text: #16161d;
  --muted: #5c5c6b;
  --border: #dcdce6;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --danger: #c02b3c;
  --panic: #e11d48;
  --shadow: 0 1px 3px rgba(20, 20, 40, 0.12), 0 6px 20px rgba(20, 20, 40, 0.06);
  --radius: 14px;
  --tap: 44px;

  /* Safe-area insets (iPhone notch / home indicator). */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  --tabbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b12;
    --surface: #17171f;
    --surface-2: #22222d;
    --text: #f2f2f7;
    --muted: #a1a1b0;
    --border: #2e2e3a;
    --brand: #7c74ff;
    --brand-ink: #0b0b12;
    --danger: #ff6b7d;
    --panic: #f43f5e;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always beat an authored `display` rule so that a
   JS `el.hidden = true` reliably removes the element from layout. Without this,
   rules like `.backdrop { display: flex }` override the user-agent
   `[hidden] { display: none }` and the element stays visible. (normalize.css
   ships the same guard.) */
[hidden] {
  display: none !important;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom));
}

/* ------------------------------ header ------------------------------ */

.app-header {
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) 8px
    calc(var(--safe-left) + 16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--brand);
  color: var(--brand-ink);
  font-weight: 800;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ------------------------------- views ------------------------------ */

main {
  padding: 8px calc(var(--safe-right) + 16px) 24px calc(var(--safe-left) + 16px);
  max-width: 720px;
  margin: 0 auto;
}

.view {
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.muted {
  color: var(--muted);
}

.count {
  font-size: 0.85rem;
  margin: 4px 2px 10px;
}

/* ---------------------------- search/chips -------------------------- */

.search-row {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 8px 0;
  background: linear-gradient(var(--bg), var(--bg) 70%, transparent);
}

.search-input,
.text-input,
.select,
.textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  font-size: 16px; /* prevents iOS zoom on focus */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: inherit;
}

.textarea {
  resize: vertical;
  line-height: 1.4;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 38px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 6px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.chip.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
  font-weight: 600;
}

/* ------------------------------- cards ------------------------------ */

.cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.card.is-burned {
  opacity: 0.62;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.card-occasion {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
}

.card-stars {
  color: var(--brand);
  letter-spacing: 1px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.card-stars .off {
  opacity: 0.3;
}

.card-text {
  margin: 8px 0 6px;
  font-size: 1.05rem;
}

.card-notes {
  margin: 0 0 6px;
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0 0;
}

.badge {
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge.badge-custom {
  background: color-mix(in srgb, var(--brand) 18%, transparent);
  color: var(--brand);
}

/* Interactive "tap to un-burn" chips: real buttons, so they must meet the
   44x44px tap-target minimum. Plain status badges (spans) stay small. */
.badge-action {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* ------------------------------ buttons ----------------------------- */

.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
}

.fab {
  position: sticky;
  bottom: calc(var(--safe-bottom) + 12px);
  width: 100%;
  margin-top: 16px;
  box-shadow: var(--shadow);
}

/* ------------------------------- panic ------------------------------ */

.panic-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 8px 0 18px;
}

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

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

.btn-panic {
  width: 100%;
  min-height: 88px;
  border: none;
  border-radius: 20px;
  background: var(--panic);
  color: #fff;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--panic) 45%, transparent);
  cursor: pointer;
}

.btn-panic:active {
  transform: scale(0.99);
}

.panic-result {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panic-text {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  line-height: 1.35;
  border-left: 4px solid var(--brand);
  padding-left: 12px;
}

.panic-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.panic-actions .btn {
  flex: 1;
}

.empty {
  margin: 20px 4px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: var(--radius);
}

/* ------------------------------ modal ------------------------------- */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  padding: env(safe-area-inset-top) 0 0;
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px calc(var(--safe-right) + 18px)
    calc(var(--safe-bottom) + 20px) calc(var(--safe-left) + 18px);
  box-shadow: var(--shadow);
}

@media (min-width: 620px) {
  .backdrop {
    align-items: center;
  }
  .modal {
    border-radius: 20px;
  }
}

.modal h2 {
  margin: 0 0 14px;
}

.modal .field {
  margin-bottom: 14px;
}

.range {
  width: 100%;
  min-height: var(--tap);
  accent-color: var(--brand);
}

.errors {
  list-style: disc inside;
  margin: 0 0 12px;
  padding: 10px 14px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .btn {
  flex: 1;
}

/* ------------------------------ tab bar ----------------------------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--border);
}

.tab {
  flex: 1;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.tab-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.tab.is-active {
  color: var(--brand);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
