/* ===== TOKENS =====
   Palette comes from a mid-century tiled bathroom: mint wall tile, a bubblegum
   pink fixture, porcelain, and the green/amber of a stall lock indicator.
   A hard drop shadow always means "you can press this". */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --tile:       #BDE5D6;
  --grout:      #D6F1E6;
  --porcelain:  #FDFEFD;
  --ink:        #14263F;
  --ink-soft:   #4A5B73;
  --pink:       #FF9DB5;
  --pink-pale:  #FFE1E8;
  --go:         #6BD699;
  --fresh:      #178A4C;
  --stale:      #C97A10;
  --alert:      #C92A36;
  --lcd:        #BAC7A7;
  --lcd-ink:    #1B2A1F;

  --font-display: 'Bagel Fat One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-body:    'Overpass', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'Overpass Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --border: 3px solid var(--ink);
  --press:  0 5px 0 var(--ink);
  --radius: 18px;
}

body {
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--tile);
  background-image:
    linear-gradient(var(--grout) 3px, transparent 3px),
    linear-gradient(90deg, var(--grout) 3px, transparent 3px);
  background-size: 64px 64px;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}

.container { width: 100%; max-width: 560px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.center { text-align: center; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

a { color: inherit; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 8px; }

/* ===== HEADER ===== */
.header { padding: 14px 0 0; }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.logo { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.logo-icon { font-size: 30px; line-height: 1; position: relative; top: 3px; }
.logo-text { font-family: var(--font-display); font-size: 18px; line-height: 1; letter-spacing: 0.01em; }

.user-chip {
  background: var(--porcelain);
  border: var(--border);
  border-radius: 999px;
  padding: 6px 14px 4px;
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 3px 0 var(--ink);
  max-width: 55vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: transform 80ms, box-shadow 80ms;
}
.user-chip .pts { margin-left: 4px; font-size: 13px; }
.user-chip:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.user-chip.bump { animation: bump 500ms ease-out; }

@keyframes bump {
  0%   { transform: scale(1); background: var(--porcelain); }
  35%  { transform: scale(1.12) rotate(-2deg); background: var(--go); }
  100% { transform: scale(1); background: var(--porcelain); }
}

/* ===== NAV ===== */
.nav {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  gap: 4px;
  padding: 5px;
  background: var(--ink);
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(20, 38, 63, 0.3);
}

.nav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 16px 8px;
  border-radius: 999px;
  color: var(--porcelain);
  font-weight: 800;
  font-size: 15px;
  text-decoration: none;
}
.nav-link svg {
  width: 18px; height: 18px; margin-top: -2px;
  fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round;
}
.nav-link[aria-current="page"] { background: var(--pink); color: var(--ink); }
.nav-link:focus-visible { outline-color: var(--porcelain); }

/* On a phone the place page belongs to the keypad and its two buttons, so the
   floating nav steps aside. "All places" and the logo still lead back. */
@media (max-width: 859px) {
  body[data-view="business"] { padding-bottom: 40px; }
  body[data-view="business"] .nav { display: none; }
  body[data-view="business"] .toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
}

@media (min-width: 860px) {
  body { padding-bottom: 48px; }
  .header .container { max-width: 960px; }
  .nav { position: absolute; top: 10px; bottom: auto; box-shadow: none; }
}

/* ===== VIEWS ===== */
.view { display: none; padding-top: 22px; }
.view.active { display: block; }

.back {
  display: inline-block;
  margin-bottom: 12px;
  font-weight: 800;
  font-size: 15px;
  text-decoration: none;
  border-bottom: 3px solid transparent;
}
.back:hover { border-bottom-color: var(--ink); }

/* ===== HOME ===== */
.hero { padding: 12px 0 28px; }

.hero h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(44px, 13vw, 68px);
  line-height: 0.98;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.hero-sub { margin: 14px 0 22px; max-width: 34ch; color: var(--ink-soft); font-weight: 600; }

.search {
  display: flex; align-items: center; gap: 10px;
  background: var(--porcelain);
  border: var(--border);
  border-radius: var(--radius);
  padding: 0 16px;
  cursor: text;
}
.search:focus-within { outline: 3px solid var(--ink); outline-offset: 3px; }
.search svg {
  width: 22px; height: 22px; flex-shrink: 0;
  fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round;
}
.search input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  padding: 17px 0 14px;
  font-size: 18px; font-weight: 600;
}
.search input::placeholder { color: var(--ink-soft); font-weight: 400; }

.near-ask {
  background: var(--porcelain);
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  margin-bottom: 24px;
}
.near-ask p { color: var(--ink-soft); font-weight: 600; font-size: 16px; }
.near-ask p strong { color: var(--ink); font-weight: 800; }
.near-ask-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.near-ask .btn { padding: 11px 16px 8px; font-size: 16px; }

.list-header-actions { display: flex; gap: 14px; flex-shrink: 0; }
.list-header .link-btn { font-size: 14px; }

.list-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.list-header h2 { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }

.link-btn {
  background: none; border: 0; padding: 0;
  font-weight: 800; text-decoration: underline; text-underline-offset: 3px;
}

/* ===== PLACE LIST ===== */
.place-list { display: grid; gap: 14px; }

.place {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--porcelain);
  border: var(--border);
  border-radius: var(--radius);
  padding: 15px 16px 13px;
  text-decoration: none;
  box-shadow: var(--press);
  transition: transform 80ms, box-shadow 80ms;
}
.place:hover { transform: translateY(-1px); box-shadow: 0 6px 0 var(--ink); }
.place:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }

.place-main { display: grid; gap: 2px; min-width: 0; }
.place-name { font-weight: 800; font-size: 19px; line-height: 1.2; }
.place-address { color: var(--ink-soft); font-size: 15px; line-height: 1.3; }

.chip {
  flex-shrink: 0;
  max-width: 45%;
  overflow-wrap: anywhere;
  background: var(--lcd);
  color: var(--lcd-ink);
  border: var(--border);
  border-radius: 10px;
  padding: 7px 10px 4px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: 0.08em;
  box-shadow: inset 0 2px 0 rgba(27, 42, 31, 0.18);
}
.chip-empty {
  background: var(--pink-pale);
  font-family: var(--font-body); font-weight: 800; font-size: 14px; letter-spacing: 0;
  box-shadow: none;
}

.place-meta { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 12px; }
.distance { font-family: var(--font-mono); font-weight: 700; font-size: 13px; color: var(--ink-soft); }

/* Stall-lock style indicator: the colour says how far to trust the code */
.status { display: inline-flex; align-items: center; gap: 7px; margin-top: 5px; font-size: 14px; font-weight: 800; }
.status i { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--ink); flex-shrink: 0; margin-top: -2px; }
.status-fresh { color: var(--fresh); }
.status-fresh i { background: var(--go); }
.status-stale { color: var(--stale); }
.status-stale i { background: #F5C15C; }
.status-none  { color: var(--ink-soft); }
.status-none i { background: var(--pink-pale); }

.status-large {
  display: flex; justify-content: center;
  margin: 16px 0 0;
  font-size: 16px;
}
.status-large i { width: 14px; height: 14px; }

/* ===== PLACE DETAIL ===== */
.plaque {
  background: var(--ink);
  color: var(--porcelain);
  border-radius: var(--radius);
  padding: 18px 20px 13px;
  /* the inset keyline every restroom sign has */
  box-shadow: inset 0 0 0 5px var(--ink), inset 0 0 0 7px rgba(253, 254, 253, 0.55);
}
.plaque h1 {
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(30px, 8.5vw, 42px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}
.plaque p { margin-top: 6px; color: #C9D6E6; font-weight: 600; }
.plaque-profile p strong { color: var(--pink); font-size: 22px; }

.keypad {
  position: relative;
  max-width: 310px;
  margin: 16px auto 0;
  padding: 28px 18px 12px;
  background: var(--pink);
  border: var(--border);
  border-radius: 30px;
}
/* mounting screws */
.keypad::before, .keypad::after {
  content: '';
  position: absolute; top: 10px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ink);
  box-shadow: inset 2px 2px 0 rgba(253, 254, 253, 0.35);
}
.keypad::before { left: 14px; }
.keypad::after  { right: 14px; }

.lcd {
  background: var(--lcd);
  color: var(--lcd-ink);
  border: var(--border);
  border-radius: 12px;
  padding: 8px 14px 4px;
  min-height: 78px;
  box-shadow: inset 0 3px 0 rgba(27, 42, 31, 0.18);
}
.lcd-label { display: block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.14em; opacity: 0.7; }
.lcd-value, .lcd-input {
  display: block; width: 100%;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: clamp(30px, 10vw, 40px);
  line-height: 1.25;
  letter-spacing: 0.14em;
  overflow-wrap: anywhere;
  user-select: all;
}
.lcd-ghost { opacity: 0.3; }
.lcd-input { border: 0; outline: 0; background: transparent; color: inherit; padding: 0; user-select: auto; }
.lcd-input::placeholder { font-family: var(--font-body); font-size: 18px; letter-spacing: 0; color: var(--lcd-ink); opacity: 0.55; }

.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; margin-top: 14px; }

.key {
  background: var(--porcelain);
  border: var(--border);
  border-radius: 14px;
  padding: 9px 0 5px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 22px;
  box-shadow: var(--press);
  transition: transform 70ms, box-shadow 70ms, background-color 200ms;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.key:disabled { color: var(--ink); cursor: default; }
.key.is-used { background: var(--tile); }
.key.is-pressed, .key:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
  background: var(--go);
}

.keypad-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; }
.pad-btn {
  background: none; border: 0;
  padding: 6px 4px 2px;
  font-weight: 800; font-size: 15px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* View mode vs. entering a new code. These come after the component styles so
   the display rules below win without needing extra specificity. */
.place-detail .when-editing { display: none; }
.place-detail.is-editing .when-viewing { display: none; }
.place-detail.is-editing span.when-editing,
.place-detail.is-editing input.when-editing { display: block; }
.place-detail.is-editing div.when-editing { display: flex; }

.actions { display: flex; gap: 12px; margin-top: 14px; }
.actions .btn { flex: 1; }

.fine { margin-top: 22px; text-align: center; color: var(--ink-soft); font-size: 14px; font-weight: 600; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--porcelain);
  border: var(--border);
  border-radius: 16px;
  padding: 14px 18px 11px;
  font-weight: 800;
  font-size: 17px;
  text-decoration: none;
  box-shadow: var(--press);
  transition: transform 80ms, box-shadow 80ms;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn-primary { background: var(--pink); }
.btn-go { background: var(--go); }
.btn-full { width: 100%; }
.btn-quiet { background: transparent; border-color: transparent; box-shadow: none; text-decoration: underline; text-underline-offset: 3px; }
.btn-quiet:active { transform: none; box-shadow: none; }

.pts {
  font-family: var(--font-mono); font-size: 14px;
  background: var(--ink); color: var(--porcelain);
  border-radius: 999px; padding: 3px 8px 1px;
}

/* ===== PANELS & FORMS ===== */
.panel {
  background: var(--porcelain);
  border: var(--border);
  border-radius: var(--radius);
  padding: 22px 18px;
}
.panel + .center, .stats + .panel { margin-top: 16px; }
.panel-title { font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1.05; }
.panel-heading { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 6px; }
.panel-sub { margin-top: 8px; color: var(--ink-soft); font-weight: 600; }
.panel form { margin-top: 20px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; min-width: 0; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.field-row .field-state { flex: 0 0 88px; }
.field label { font-weight: 800; font-size: 15px; }
.optional { font-weight: 600; color: var(--ink-soft); font-size: 13px; }

.field input {
  width: 100%;
  background: var(--porcelain);
  border: var(--border);
  border-radius: 12px;
  padding: 13px 14px 10px;
  font-size: 17px;
}
.field input::placeholder { color: #8A97A8; }
.field input:focus-visible { outline-offset: 2px; border-radius: 12px; }
.field-state input { text-transform: uppercase; }
.field .code-input {
  background: var(--lcd); color: var(--lcd-ink);
  font-family: var(--font-mono); font-weight: 700; font-size: 22px; letter-spacing: 0.14em;
}
.field .code-input::placeholder { color: var(--lcd-ink); opacity: 0.4; }

.hint { font-size: 14px; color: var(--ink-soft); }

/* Place suggestions under the name field */
.suggest { position: relative; }
.suggestions {
  list-style: none;
  background: var(--porcelain);
  border: var(--border);
  border-radius: 12px;
  overflow: hidden;
}
.suggestion { display: grid; gap: 1px; padding: 10px 14px 8px; cursor: pointer; border-top: 2px dashed var(--tile); }
.suggestion:first-child { border-top: 0; }
.suggestion:hover, .suggestion.is-active { background: var(--pink-pale); }
.suggestion-name { font-weight: 800; }
.suggestion-address { font-size: 14px; color: var(--ink-soft); }
.points-note { margin-bottom: 16px; font-size: 15px; font-weight: 600; color: var(--ink-soft); }
.points-note strong { color: var(--ink); }
.error-msg { margin-bottom: 14px; color: var(--alert); font-weight: 800; font-size: 15px; }

/* ===== ROWS (leaderboard, activity) ===== */
.rows { list-style: none; margin-top: 10px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 0 10px; border-top: 2px dashed var(--tile); }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.row-points { font-family: var(--font-mono); font-weight: 700; white-space: nowrap; }
.row-you { background: var(--pink-pale); margin: 0 -10px; padding-left: 10px; padding-right: 10px; border-radius: 12px; border-top-color: transparent; }
.row-you + .row { border-top-color: transparent; }

.you {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--ink); color: var(--porcelain);
  border-radius: 999px; padding: 3px 7px 1px; margin-left: 4px; vertical-align: 2px;
}

.rank {
  flex: 0 0 38px; height: 38px;
  display: grid; place-items: center;
  padding-top: 3px;
  border: var(--border); border-radius: 10px;
  font-family: var(--font-mono); font-weight: 700;
  background: var(--porcelain);
}
.rank-1 { background: var(--pink); }
.rank-2 { background: var(--go); }
.rank-3 { background: var(--grout); }

/* ===== PROFILE ===== */
.stats { display: flex; gap: 12px; margin-top: 14px; }
.stat {
  flex: 1;
  background: var(--porcelain);
  border: var(--border); border-radius: var(--radius);
  padding: 14px 14px 10px;
  font-weight: 600; font-size: 15px; color: var(--ink-soft);
}
.stat-value { display: block; font-family: var(--font-mono); font-weight: 700; font-size: 30px; line-height: 1.1; color: var(--ink); }

/* ===== EMPTY & LOADING ===== */
.empty {
  background: var(--porcelain);
  border: 3px dashed var(--ink);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
}
.empty-title { font-family: var(--font-display); font-size: 26px; line-height: 1.1; }
.empty p + p { margin-top: 8px; color: var(--ink-soft); font-weight: 600; }
.empty .btn { margin-top: 18px; max-width: 100%; overflow-wrap: anywhere; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 36px 0; font-weight: 800; color: var(--ink-soft); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid var(--ink); border-right-color: transparent;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== DIALOG ===== */
.dialog {
  width: min(440px, calc(100vw - 32px));
  margin: auto;
  background: var(--porcelain);
  color: var(--ink);
  border: var(--border);
  border-radius: 24px;
  padding: 24px 20px 20px;
}
.dialog::backdrop { background: rgba(20, 38, 63, 0.55); }
.dialog h2 { font-family: var(--font-display); font-weight: 400; font-size: 32px; line-height: 1.05; }
.dialog p { margin: 10px 0 18px; color: var(--ink-soft); font-weight: 600; }
.dialog p.error-msg { margin: 0 0 14px; color: var(--alert); }
.dialog-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.dialog .field label { color: var(--ink); }
.btn:disabled { opacity: 0.6; cursor: progress; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  width: max-content;
  max-width: calc(100vw - 32px);
  background: var(--ink);
  color: var(--porcelain);
  border-radius: 14px;
  padding: 13px 18px 10px;
  font-weight: 800;
  font-size: 15px;
  text-align: center;
  animation: toast-in 220ms ease-out;
}
.toast-error { background: var(--alert); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (min-width: 860px) {
  .toast { bottom: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
  .spinner { animation-duration: 1.4s !important; }
}
