:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #18212f;
  --muted: #667085;
  --line: #dde5ef;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --active: #047857;
  --active-bg: #e8fbf2;
  --active-line: #9be5c4;
  --cart-bg: #edf2f7;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 28rem),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 18rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
}

a { color: var(--accent); text-decoration: none; }

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.8rem 1rem;
  background: rgba(248, 251, 255, 0.9);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.brand-heading {
  justify-self: center;
  margin: 0;
  line-height: 1;
}

.brand {
  justify-self: center;
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0;
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
  background: #e8edf5;
  padding: 0.3rem;
  border-radius: 999px;
}

.mode-switch a,
.venue-tabs a {
  min-height: 42px;
  display: grid;
  place-items: center;
  color: var(--text);
  border-radius: 999px;
  font-weight: 650;
}

.mode-switch a.active,
.venue-tabs a.active {
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.1);
}

.page {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 1.1rem 1rem 5rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

h1 {
  margin: 0;
  font-size: clamp(1.65rem, 5vw, 2.2rem);
  line-height: 1.05;
}

h2 {
  margin: 0;
  line-height: 1.05;
}

.psychedelic-headline {
  position: relative;
  display: inline-block;
  z-index: 0;
  isolation: isolate;
  max-width: 100%;
  padding: 0.08em 0.02em 0.18em;
  color: transparent;
  background:
    radial-gradient(circle at 15% 35%, #fff176 0 10%, transparent 21%),
    radial-gradient(circle at 72% 20%, #00f5d4 0 8%, transparent 19%),
    linear-gradient(90deg, #ff2f8b, #ffb000, #32d74b, #00c2ff, #7c3aed, #ff2f8b);
  background-size: 180% 180%, 170% 170%, 260% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  filter: saturate(1.25);
  font-weight: 950;
  letter-spacing: 0;
  text-wrap: balance;
  overflow-wrap: anywhere;
  text-shadow:
    0.035em 0.035em 0 rgba(255, 0, 153, 0.28),
    -0.035em 0.03em 0 rgba(0, 221, 255, 0.3),
    0 0.14em 0.38em rgba(124, 58, 237, 0.22);
  animation: psychedelic-drift 7s ease-in-out infinite alternate;
}

.psychedelic-headline-main {
  font-size: clamp(2.1rem, 10vw, 4.4rem);
}

.psychedelic-headline-section {
  font-size: clamp(1.75rem, 7vw, 3rem);
}

.psychedelic-headline::after {
  content: "";
  position: absolute;
  left: -0.08em;
  right: -0.08em;
  bottom: 0.02em;
  height: 0.16em;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff2f8b, #ffb000, #32d74b, #00c2ff, #7c3aed);
  box-shadow: 0 0.18em 0.65em rgba(255, 47, 139, 0.28);
  transform: skewX(-12deg);
  z-index: -1;
}

.psychedelic-headline-section::after {
  content: none;
}

@keyframes psychedelic-drift {
  from {
    background-position: 0% 40%, 100% 30%, 0% 50%;
    transform: rotate(-0.5deg);
  }
  to {
    background-position: 100% 55%, 0% 65%, 100% 50%;
    transform: rotate(0.7deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .psychedelic-headline {
    animation: none;
  }
}

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

.errorlist {
  margin: 0.15rem 0 0;
  padding-left: 1.1rem;
  color: var(--danger);
  font-size: 0.92rem;
  font-weight: 650;
}

.auth-panel {
  max-width: 420px;
  margin: 2rem auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.stack-form {
  display: grid;
  gap: 0.85rem;
}

label {
  display: grid;
  gap: 0.3rem;
  color: var(--muted);
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.8rem;
  background: var(--panel);
  color: var(--text);
}

textarea {
  resize: vertical;
}

.add-form {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.85rem;
  background: var(--panel);
  border: 1px solid rgba(37, 99, 235, 0.28);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.add-item-row {
  display: grid;
  grid-template-columns: 1fr 5.5rem auto;
  gap: 0.5rem;
}

.venue-add-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  width: min(30rem, 100%);
  margin: 0.25rem 0 1rem;
}

.item-autocomplete {
  position: relative;
  min-width: 0;
}

.autocomplete-options {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.3rem);
  left: 0;
  right: 0;
  max-height: 18rem;
  overflow-y: auto;
  padding: 0.35rem;
  border: 1px solid rgba(37, 99, 235, 0.32);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.autocomplete-options button {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 700;
}

.autocomplete-options button:hover,
.autocomplete-options button[aria-selected="true"] {
  background: #eef4ff;
  color: var(--accent-dark);
}

.venue-picker {
  position: relative;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.venue-picker legend {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.venue-picker-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.venue-option {
  display: inline-flex;
  width: auto;
  min-height: 38px;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

.venue-option input {
  width: auto;
  margin: 0;
}

.venue-option:has(input:checked) {
  border-color: var(--active-line);
  background: var(--active-bg);
  color: var(--active);
}

.add-venue-button {
  border-style: dashed;
  color: var(--accent);
}

.add-venue-window {
  width: min(280px, 100%);
  margin-top: 0.45rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
}

.add-venue-window label {
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.add-venue-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.add-venue-actions button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef4ff;
  color: var(--accent);
  font-weight: 700;
}

.add-venue-actions button:first-child {
  background: var(--panel);
  color: var(--muted);
}

.primary,
.secondary,
.icon-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.65rem 0.9rem;
  font-weight: 750;
}

.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #0891b2);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.22);
}

.primary:hover {
  background: var(--accent-dark);
}

.secondary,
.icon-button {
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.button-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem 0;
}

.bulk-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0.85rem;
  margin: 1.5rem 0 0.75rem;
  box-shadow: var(--shadow);
}

.item-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-start;
}

.item-chip {
  position: relative;
  display: inline-flex;
  gap: 0.25rem;
  align-items: center;
  min-height: 48px;
  max-width: 100%;
  padding: 0.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.item-chip.is-active {
  background: var(--active-bg);
  border-color: var(--active-line);
}

.item-chip > form:first-child {
  min-width: 0;
}

.chip-main,
.shopping-row {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font-weight: 750;
}

.is-active .chip-main {
  color: var(--active);
}

.chip-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.quantity-badge,
.venue-badge {
  display: inline-grid;
  place-items: center;
  min-height: 24px;
  min-width: 24px;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: #eef4ff;
  color: var(--muted);
  font-size: 0.85rem;
}

.quantity-form {
  display: inline-grid;
  grid-template-columns: 32px 2.6rem 32px;
  gap: 0.15rem;
  align-items: center;
  padding: 0.1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
}

.quantity-form button,
.menu-button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
}

.quantity-form input {
  text-align: center;
  height: 32px;
  padding: 0.2rem;
  border-radius: 999px;
}

.menu-button {
  width: 36px;
  font-size: 1.25rem;
}

.venue-menu {
  position: fixed;
  z-index: 50;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 1rem));
  max-height: calc(100vh - 1rem);
  overflow: auto;
}

.menu-surface {
  background: var(--panel);
  border: 2px solid rgba(37, 99, 235, 0.45);
  border-radius: 18px;
  box-shadow: 0 16px 38px rgba(37, 99, 235, 0.16), var(--shadow);
  padding: 0.4rem;
}

.menu-surface button {
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
}

.menu-surface button:hover,
.menu-surface button:focus-visible {
  background: #eef4ff;
  outline: none;
}

.inline-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.delete-item-form {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
}

.rename-item {
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px solid var(--line);
}

.rename-item > button {
  border: 1px solid rgba(37, 99, 235, 0.24);
  background: #eef4ff;
  color: var(--accent);
  font-weight: 750;
  text-align: center;
}

.rename-item > button:hover,
.rename-item > button:focus-visible {
  background: #dbeafe;
  border-color: rgba(37, 99, 235, 0.4);
}

.rename-item-window {
  margin-top: 0.35rem;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbff;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
}

.rename-item-window form {
  display: grid;
  gap: 0.45rem;
}

.rename-item-window label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.rename-item-window input {
  min-width: 0;
  width: 100%;
}

.rename-item-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.rename-item-actions button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #eef4ff;
  color: var(--accent);
  font-weight: 700;
  text-align: center;
}

.rename-item-actions button:first-child {
  background: var(--panel);
  color: var(--muted);
}

.rename-item-actions button:hover,
.rename-item-actions button:focus-visible {
  background: #dbeafe;
  border-color: rgba(37, 99, 235, 0.32);
}

.delete-item-form button {
  border: 1px solid rgba(180, 35, 24, 0.28);
  border-radius: 10px;
  background: #fff4f2;
  color: #b42318;
  font-weight: 700;
  text-align: center;
}

.delete-item-form button:hover,
.delete-item-form button:focus-visible {
  background: #fee4e2;
  border-color: rgba(180, 35, 24, 0.45);
}

.placeholder-check {
  display: inline-block;
  width: 1em;
}

.venue-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
}

.venue-tabs a {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 0 0.75rem;
  background: #e8edf5;
}

.shopping-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: flex-start;
}

.shopping-entry {
  max-width: 100%;
  touch-action: none;
  transition: transform 120ms ease, opacity 120ms ease;
}

.history-list {
  display: grid;
  gap: 0.65rem;
}

.shopping-row {
  width: auto;
  max-width: 100%;
  min-height: 50px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.shopping-entry.is-dragging {
  opacity: 0.72;
  transform: scale(0.99);
  z-index: 2;
}

.shopping-list.is-reordering .shopping-entry:not(.is-dragging) {
  transition: transform 120ms ease;
}

.shopping-row.in-cart {
  background: var(--cart-bg);
  color: var(--muted);
  text-decoration: line-through;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.25rem;
}

.shopping-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.finish-button {
  width: auto;
  min-width: 12rem;
  margin-top: 1rem;
}

.shopping-venue-tabs.follows-shopping {
  margin-top: 1rem;
}

.history-row {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 0.85rem;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.history-row p {
  margin: 0.25rem 0 0;
}

.messages {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 0.8rem;
}

.message,
.empty {
  margin: 0;
  padding: 0.75rem;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.message.error {
  color: var(--danger);
}

@media (min-width: 720px) {
  .topbar {
    grid-template-columns: auto minmax(340px, 520px);
    justify-content: center;
  }

  .mode-switch {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .add-item-row {
    grid-template-columns: 1fr 4.75rem;
  }

  .add-item-row .primary {
    grid-column: 1 / -1;
  }

  .item-chip,
  .shopping-row {
    max-width: 100%;
  }

  .shopping-list {
    padding-right: 2.75rem;
  }

  .shopping-entry {
    max-width: 100%;
  }
}

.system-actions {
  width: min(1040px, calc(100% - 2rem));
  margin: 0 auto 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.system-actions form {
  margin: 0;
}

.htmx-indicator { opacity: 0; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
