:root {
  --bg: #16161d;
  --surface: #1f1f29;
  --surface-raised: #292933;
  --border: #34343f;
  --text: #f2f2f5;
  --text-dim: #9d9dab;
  /*
   * Chosen against WCAG AA, not by eye. White text on this reaches 5.11:1
   * (needs 4.5), and the colour itself hits 3.53:1 on --bg so focus outlines
   * still clear the 3.0 required for UI components. The lighter #7c5cff it
   * replaced failed the first test at 4.35:1.
   */
  --accent: #6f4ff5;
  --accent-dim: #5a3fe0;
  --danger: #ff5c7c;
  --success: #4fd68c;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  /*
   * Safe-area insets on every edge (L8). They are zero in a desktop browser,
   * and non-zero on a notched phone -- most of all once the app is installed
   * to the home screen and no browser toolbar sits over the edges.
   */
  padding:
    calc(20px + env(safe-area-inset-top, 0px))
    calc(16px + env(safe-area-inset-right, 0px))
    calc(40px + env(safe-area-inset-bottom, 0px))
    calc(16px + env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  min-height: 40px;
}

.back-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header h1 {
  font-size: 22px;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-title {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 4px;
}

.app-subtitle {
  color: var(--text-dim);
  margin: 0 0 20px;
  font-size: 14px;
}

/* ---------- Buttons ---------- */

button {
  font-family: inherit;
  cursor: pointer;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: white;
}

.btn-primary:active {
  background: var(--accent-dim);
}

.btn-primary:disabled {
  opacity: 0.4;
}

.btn-block {
  width: 100%;
}

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

.btn-success {
  background: transparent;
  border: 1px solid var(--success);
  color: var(--success);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.fab {
  position: fixed;
  /* Clears the home indicator and a landscape notch (L8). */
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  right: max(calc(24px + env(safe-area-inset-right, 0px)), calc((100vw - 480px) / 2 + 24px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 28px;
  border: none;
  box-shadow: 0 6px 20px rgba(124, 92, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Category list ---------- */

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

.category-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  width: 100%;
  color: var(--text);
}

.category-card .name {
  font-size: 17px;
  font-weight: 600;
}

.category-card .meta {
  color: var(--text-dim);
  font-size: 13px;
  margin-top: 2px;
}

.category-card .chevron {
  color: var(--text-dim);
  font-size: 20px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-dim);
  gap: 8px;
  padding: 40px 20px;
}

.empty-state .emoji {
  font-size: 40px;
  margin-bottom: 8px;
}

.empty-state .btn {
  margin-top: 16px;
}

/* ---------- Category detail ---------- */

.pick-zone {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 18px;
  margin-bottom: 20px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.pick-result-card {
  width: 100%;
  text-align: center;
  animation: pop-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop-in {
  0% {
    transform: scale(0.6);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.pick-result-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.pick-result-text {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 18px;
  word-break: break-word;
}

.pick-result-actions {
  display: flex;
  gap: 10px;
}

.pick-result-actions .btn {
  flex: 1;
}

.pick-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 14px;
}

.spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

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

.pick-idle {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}

.pick-btn {
  font-size: 17px;
  padding: 16px 28px;
  border-radius: 16px;
}

.section-label {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin: 18px 0 8px;
}

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

.option-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.option-item.last-picked {
  border-color: var(--success);
  background: rgba(79, 214, 140, 0.08);
}

.option-item .option-text {
  font-size: 15px;
  word-break: break-word;
}

.option-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.option-item .badge {
  font-size: 11px;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: 999px;
  padding: 2px 8px;
  flex-shrink: 0;
  white-space: nowrap;
}


.add-option-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.add-option-row input {
  flex: 1;
  min-width: 0;
}

.empty-options {
  color: var(--text-dim);
  font-size: 14px;
  padding: 10px 2px;
}

/* ---------- Forms / inputs ---------- */

:root {
  /*
   * Input edges only. --border is decorative and measures 1.17:1 against an
   * input's own background, which leaves the field's edge invisible. This
   * clears the 3:1 a component boundary needs on --surface-raised (3.20),
   * --surface (3.63) and --bg (4.00).
   */
  --border-strong: #75758a;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 13px 14px;
  color: var(--text);
  font-size: 16px;
  width: 100%;
}

input::placeholder {
  /* 5.38:1 on --surface-raised. */
  color: var(--text-dim);
}

/*
 * One focus style for everything interactive -- v1 buttons had none (L4).
 * The ring sits OUTSIDE the element. Drawn inside an input it landed on
 * --surface-raised at 2.82:1, below the 3:1 a focus indicator needs; outside,
 * it measures 3.20:1 on --surface and 3.53:1 on --bg.
 */
input:focus-visible,
button:focus-visible,
a:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Headings take focus only so it is not lost to <body>; they are not controls. */
h1[tabindex="-1"]:focus {
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Screens around the jars ---------- */

.list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.settings-link {
  color: var(--text-dim);
  font-size: 14px;
  padding: 8px 4px;
}

.view-auth,
.view-settings {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view-status {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 40px 20px;
}

.status-heading {
  font-size: 18px;
  margin: 0;
}

.auth-form,
.card-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.card-form h2 {
  margin: 0;
  font-size: 16px;
}

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

.field label {
  font-size: 14px;
  font-weight: 600;
}

.field-hint {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
}

.field-error {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

/* About the attempt, not a field: set apart from the inputs so it does not read
   as a validation message for whichever field happens to be nearest. */
.form-error {
  margin: 0;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 12px;
}

.segmented {
  display: flex;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
}

.segment {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 10px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
}

/* Selected state is marked by more than a background shift: the inset edge
   is 3.20:1 against the raised fill, and the text brightens. */
.segment[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.notice {
  margin: 0;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  font-size: 14px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  text-decoration: underline;
  font-size: 14px;
  padding: 10px;
  align-self: center;
}

.btn[aria-disabled="true"] {
  /* No opacity change: dimming the label would drop it below 4.5:1. */
  cursor: progress;
}

.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--success);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

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

.banner-dismiss {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  padding: 2px 6px;
}

.share-code {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-align: center;
}

.settings-value {
  margin: 0;
  font-size: 17px;
}

.member-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 15px;
  word-break: break-word;
}

a.back-btn {
  text-decoration: none;
}

/* ---------- Modal (new category) ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}

.modal-sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 22px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slide-up 0.22s ease-out;
}

@keyframes slide-up {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-sheet h2 {
  margin: 0;
  font-size: 18px;
}

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

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

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

/* ---------- Reduced motion ---------- */

/*
 * Honour the OS-level "reduce motion" setting. The pick reveal is the whole
 * point of the app, so it still happens — it just arrives as a fade rather
 * than a bounce, and the confetti is suppressed entirely (app.js checks the
 * same query). Motion sensitivity and vestibular disorders make a 60-particle
 * burst genuinely unpleasant, not merely busy.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* Keep the reveal legible: a plain fade, no scale bounce. */
  .pick-result-card {
    animation: fade-in 0.15s ease-out !important;
  }

  /* The spinner conveys "working"; keep it turning, just slower and calmer. */
  .spinner {
    animation: spin 1.4s linear infinite !important;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------- Jars (v2 markup) ---------- */

.category-card .name,
.category-card .meta {
  display: block;
}

.empty-title {
  margin: 0;
  font-size: 17px;
  color: var(--text);
}

.empty-state p {
  margin: 0;
}

.load-error {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 0;
}

.view-detail .empty-options {
  margin: 0;
}

.pick-zone p {
  margin-top: 0;
}

.pick-zone .pick-idle,
.pick-loading p {
  margin: 0;
}

.pick-result-card .form-error {
  margin-bottom: 12px;
}

.add-option-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.add-option-form .add-option-row {
  margin-top: 0;
}

.recent-meta {
  /* 6.10:1 on --surface. */
  color: var(--text-dim);
  font-size: 13px;
  flex-shrink: 0;
  text-align: right;
  word-break: break-word;
}

#jar-action-error {
  margin-bottom: 12px;
}

/* ---------- Delete: labelled, and confirmed (L7) ---------- */

.option-entry {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.option-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row-action {
  /* A real target: the v1 ✕ was an 18px glyph with 2px of padding. */
  min-height: 40px;
  padding: 6px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

/* 5.50:1 on --surface. */
.row-action-danger {
  color: var(--danger);
  border-color: var(--danger);
}

.confirm-delete {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.confirm-text {
  margin: 0;
  font-size: 14px;
  word-break: break-word;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

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

/* ---------- Removed view ---------- */

.removed-link {
  display: inline-block;
  margin-top: 14px;
  padding: 10px 2px;
  /* 6.72:1 on --bg, and underlined, so it reads as a link without colour. */
  color: var(--text-dim);
  font-size: 14px;
}

.view-removed .app-subtitle {
  margin: 0 0 14px;
}

/* ---------- Take out from the row ---------- */

/* Three controls (badge, Take out, Delete) do not fit beside a long option on
   a 375px phone. The actions wrap under the text instead of squeezing it to a
   few characters per line. */
.option-entry .option-row {
  flex-wrap: wrap;
}

.option-entry .option-item-actions {
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ---------- Home screen ---------- */

/* The floating "+" is 56px tall and sits 24px above the bottom inset; this
   keeps the last jar card from ending up underneath it. */
.view-list {
  padding-bottom: 48px;
}

.install-offer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 0 16px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
}

.install-offer h2 {
  margin: 0;
  font-size: 16px;
}

.install-offer p {
  margin: 0;
  font-size: 14px;
  color: var(--text-dim);
}

.install-offer-actions {
  display: flex;
  gap: 10px;
}

.install-offer-actions .btn {
  flex: 1;
}
