/* Two physical boards, one fixture: a cream enamel split-flap board
   (the kind bolted up in old European stations) by daylight, and the
   same board backlit at night once the sun — or the OS theme — goes
   down. Same hardware, same amber/teal signal lamps, different light. */
:root {
  --board: #eee8d9;
  --panel: #f8f3e6;
  --flap: #e4dcc6;
  --ink: #201c17;
  --ink-dim: #6d6656;
  --amber: #b8481c;
  --amber-ink: #fef8ec;
  --teal: #0d8a7f;
  --signal: #2c7a44;
  --line: #d6cbac;
  --shadow: rgba(32, 26, 18, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --board: #101216;
    --panel: #191c22;
    --flap: #21252d;
    --ink: #f2ede1;
    --ink-dim: #8a8f9c;
    --amber: #ff7a3c;
    --amber-ink: #1b0e07;
    --teal: #3fd0c9;
    --signal: #57e08a;
    --line: #2d323c;
    --shadow: rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  --board: #101216;
  --panel: #191c22;
  --flap: #21252d;
  --ink: #f2ede1;
  --ink-dim: #8a8f9c;
  --amber: #ff7a3c;
  --amber-ink: #1b0e07;
  --teal: #3fd0c9;
  --signal: #57e08a;
  --line: #2d323c;
  --shadow: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--board);
  color: var(--ink);
  font-family: ui-sans-serif, "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  justify-content: center;
  padding: 0 0 6vh;
}

main {
  width: 100%;
  max-width: 62rem;
}

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

/* --- flap-tile lettering: individual hinged characters, the one place
   the whole page spends its display-type personality --- */

.flap-tiles {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.16rem;
}

.flap-char {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-weight: 700;
  background: var(--flap);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 -3px 5px rgba(0, 0, 0, 0.22);
}

.flap-char::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(0, 0, 0, 0.4);
}

.flap-char.flap-space {
  background: none;
  border: none;
  box-shadow: none;
}

.flap-tiles.flap-lg .flap-char {
  width: clamp(1.5rem, 4.6vw, 1.95rem);
  height: clamp(1.9rem, 5.7vw, 2.5rem);
  font-size: clamp(1.05rem, 2.9vw, 1.32rem);
}

.flap-tiles.flap-lg .flap-char.flap-space { width: clamp(0.7rem, 2vw, 0.9rem); }

/* --- header, styled as a split-flap departures board masthead --- */

.pass {
  padding: 1.6rem 1.4rem 1.1rem;
}

.pass-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
}

.tagline {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--ink-dim);
}

.pass-sub {
  margin-top: 0.4rem;
  font-size: 0.95rem;
  color: var(--ink-dim);
  max-width: 34rem;
}

.pass-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* --- the boarding ticker: a live strip of who's headed where --- */

.ticker {
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.ticker-label {
  flex: none;
  display: flex;
  align-items: center;
  padding: 0.5rem 0.9rem;
  background: var(--amber);
  color: var(--amber-ink);
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  white-space: nowrap;
}

.ticker-window {
  overflow: hidden;
  flex: 1;
  display: flex;
  align-items: center;
}

.ticker-track {
  display: flex;
  align-items: center;
  width: max-content;
  padding: 0 1.2rem;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  color: var(--teal);
  white-space: nowrap;
  animation: ticker-scroll 32s linear infinite;
}

.ticker-item { color: var(--ink-dim); }
.ticker-item b { color: var(--teal); font-weight: 700; }
.ticker-sep { margin: 0 0.9rem; color: var(--line); }

@keyframes ticker-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

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

.auth-actions {
  display: flex;
  gap: 0.5rem;
}

.auth-actions[hidden] { display: none; }

.auth-btn {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 3px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  border: 1px solid var(--line);
}

.auth-btn.ghost {
  background: var(--panel);
  color: var(--ink);
}

.auth-btn.ghost:hover { border-color: var(--teal); }

.auth-btn.solid {
  background: var(--amber);
  border-color: var(--amber);
  color: var(--amber-ink);
}

.auth-btn.solid:hover { opacity: 0.9; }

.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.account-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: var(--ink-dim);
}

.account-chip[hidden] { display: none; }

.account-chip span { color: var(--ink); font-weight: 700; }

.inbox-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.inbox-btn[hidden] { display: none; }

.inbox-btn:hover { border-color: var(--teal); }

.inbox-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.inbox-badge {
  background: var(--amber);
  color: var(--amber-ink);
  border-radius: 999px;
  min-width: 1.1rem;
  height: 1.1rem;
  font-size: 0.65rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.3rem;
}

.inbox-badge[hidden] { display: none; }

.inbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--board);
}

.inbox-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.inbox-row:hover { border-color: var(--teal); }

.inbox-row:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.inbox-row img {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  border: 1px solid var(--line);
}

.inbox-row-info { min-width: 0; flex: 1; }

.inbox-row-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.inbox-row-name { font-weight: 700; font-size: 0.85rem; }

.inbox-row-route {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.65rem;
  color: var(--ink-dim);
  white-space: nowrap;
}

.inbox-row-preview {
  font-size: 0.78rem;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.1rem;
}

.inbox-empty {
  padding: 2.2rem 1rem;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.85rem;
}

/* --- your profile / photo gate --- */

.your-profile {
  padding: 1.2rem 1.4rem 0.2rem;
}

.profile-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 6px;
  padding: 0.7rem 1rem;
}

.profile-row[data-complete="true"] {
  border-style: solid;
  border-color: var(--signal);
}

.avatar-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}

.avatar-circle {
  position: relative;
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 50%;
  background: var(--flap);
  border: 2px dashed var(--ink-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
}

.avatar-circle canvas,
.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-edit-badge {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 1.05rem;
  height: 1.05rem;
  border-radius: 50%;
  background: var(--teal);
  color: var(--amber-ink);
  font-size: 0.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--panel);
  pointer-events: none;
}

.avatar-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--teal);
}

.avatar-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
  border-radius: 999px;
}

.profile-hint {
  font-size: 0.78rem;
  color: var(--ink-dim);
  margin: 0;
}

/* --- filters --- */

.filters {
  padding: 1.3rem 1.4rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.search {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.6rem 0.9rem;
  box-shadow: inset 0 1px 2px var(--shadow);
}

.search svg { flex: none; color: var(--ink-dim); }

.search input {
  border: none;
  background: none;
  outline: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.92rem;
  width: 100%;
}

.search input::placeholder { color: var(--ink-dim); }

.filters-label {
  margin: 0;
  font-size: 0.76rem;
  color: var(--ink-dim);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.chip:hover { border-color: var(--teal); }

.chip[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--amber-ink);
}

.chip:focus-visible, .search input:focus-visible, .say-hi:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* --- grid of cards --- */

.grid {
  padding: 1.4rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15.5rem, 1fr));
  gap: 1.3rem;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.9rem;
  padding: 2rem 1rem;
}

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0.6rem 1.4rem var(--shadow);
  overflow: hidden;
}

.grommet {
  position: absolute;
  top: -8px;
  left: 22px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--board);
  border: 2px solid var(--ink-dim);
  z-index: 2;
}

.photo-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--flap);
}

.photo-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.stub {
  padding: 0.9rem 1rem 1rem;
  border-top: 2px dashed var(--line);
  position: relative;
}

.stub::before, .stub::after {
  content: "";
  position: absolute;
  top: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--board);
}
.stub::before { left: -9px; }
.stub::after { right: -9px; }

.route-row {
  display: flex;
  justify-content: space-between;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--teal);
}

/* a rubber ink stamp, not a UI pill — the one deliberately round
   shape in an otherwise square-edged, mechanical system */
.match-badge {
  display: inline-flex;
  margin-top: 0.5rem;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--signal);
  background: none;
  border: 2px solid var(--signal);
  border-radius: 999px;
  padding: 0.16rem 0.6rem;
  transform: rotate(-4deg);
}

.match-badge[hidden] { display: none; }

.name {
  margin: 0.3rem 0 0.5rem;
  font-size: 1.02rem;
  font-weight: 700;
}

.name span {
  font-weight: 400;
  color: var(--ink-dim);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.tag {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.66rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--teal);
  border: 1px solid var(--teal);
  border-radius: 3px;
  padding: 0.18rem 0.5rem;
}

.say-hi {
  width: 100%;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--amber-ink);
  background: var(--amber);
  border: none;
  border-radius: 3px;
  padding: 0.6rem;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.say-hi:hover { opacity: 0.9; }

.say-hi:disabled {
  background: var(--flap);
  color: var(--ink-dim);
  cursor: not-allowed;
  opacity: 0.75;
}

.caption {
  padding: 0.4rem 1.4rem 0;
  text-align: center;
  font-size: 0.76rem;
  color: var(--ink-dim);
}

/* --- chat --- */

.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 10, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.chat-overlay[hidden] { display: none; }

.chat-panel {
  width: 100%;
  max-width: 26rem;
  max-height: 82vh;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1.5rem 3rem var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 1rem;
  border-bottom: 2px dashed var(--line);
}

.chat-head canvas {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  flex: none;
}

.chat-head-info { flex: 1; min-width: 0; }
.chat-head-info h3 { margin: 0; font-size: 0.95rem; }
.chat-head-info span {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.7rem;
  color: var(--ink-dim);
}

.chat-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--ink-dim);
  cursor: pointer;
  line-height: 1;
  padding: 0.3rem;
}

.chat-close:hover { color: var(--ink); }

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--board);
}

.bubble {
  max-width: 80%;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.4;
}

.bubble.them {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-bottom-left-radius: 2px;
}

.bubble.me {
  align-self: flex-end;
  background: var(--teal);
  color: var(--amber-ink);
  border-bottom-right-radius: 2px;
}

.chat-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.7rem;
  border-top: 1px solid var(--line);
}

.chat-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.5rem 0.7rem;
  font-family: inherit;
  font-size: 0.85rem;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.chat-input-row input:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.chat-input-row button {
  background: var(--amber);
  color: var(--amber-ink);
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-weight: 700;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}

.chat-input-row button:hover { opacity: 0.9; }

/* --- register / log in --- */

.auth-panel { max-width: 22rem; }

.auth-form {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.auth-field[hidden] { display: none; }

.auth-field input {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  outline: none;
}

.auth-field input:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}

.auth-error {
  margin: 0;
  font-size: 0.8rem;
  color: var(--amber);
}

.auth-error[hidden] { display: none; }

.auth-submit {
  font-family: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--amber-ink);
  background: var(--amber);
  border: none;
  border-radius: 4px;
  padding: 0.65rem;
  cursor: pointer;
}

.auth-submit:hover { opacity: 0.9; }
.auth-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-switch {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.auth-link {
  background: none;
  border: none;
  color: var(--teal);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  text-decoration: underline;
}

/* --- email notice (now sent for real, by Supabase Auth's mail server) --- */

.email-toast {
  position: fixed;
  top: 1.2rem;
  right: 1.2rem;
  left: 1.2rem;
  margin-left: auto;
  max-width: 20rem;
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 1rem 2.2rem var(--shadow);
  padding: 0.9rem 1rem;
  z-index: 60;
  animation: toast-in 0.3s ease;
}

.email-toast[hidden] { display: none; }

.email-toast.leaving { animation: toast-out 0.25s ease forwards; }

@keyframes toast-in {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-12px); opacity: 0; }
}

.email-toast-icon { font-size: 1.4rem; line-height: 1; flex: none; }

.email-toast-body { min-width: 0; flex: 1; }

.email-toast-from {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
}

.email-toast-subject {
  margin: 0.2rem 0 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.email-toast-preview {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.email-toast-note {
  margin: 0.4rem 0 0;
  font-size: 0.68rem;
  color: var(--ink-dim);
  font-style: italic;
}

.email-toast-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  color: var(--ink-dim);
  cursor: pointer;
  padding: 0.1rem;
  flex: none;
}

.email-toast-close:hover { color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .email-toast, .email-toast.leaving { animation: none; }
}
