/*
 * The same font files the Android app bundles, so the two clients render
 * identically. Without these the page silently fell back to the system font —
 * San Francisco on an iPhone, Segoe on Windows — which is why it looked wrong.
 *
 * swap: text shows immediately in the fallback and re-renders when Plex lands,
 * rather than leaving a blank screen on a slow connection.
 */
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-400.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-500.ttf') format('truetype');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('fonts/plex-sans-600.ttf') format('truetype');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('fonts/plex-mono-500.ttf') format('truetype');
  font-weight: 500; font-style: normal; font-display: swap;
}

/*
 * The Android app's design tokens, transcribed.
 *
 * Same brand, same meanings, same spacing — someone moving between an iPhone
 * and an Android handset should not feel they are using a different system.
 * If a colour is not here, it belongs in the design first.
 */
:root {
  --brand: #2f6446;
  --brand-accent: #457d58;
  --brand-dark: #24462f;
  --brand-darkest: #17301f;
  --brand-surface: #e4eee7;
  --brand-surface-subtle: #f1f6f2;
  --brand-border: #a8c6b2;

  --text: #171818;
  --text-2: #4e5150;
  --text-3: #7c807e;
  --text-disabled: #b6bab8;

  --bg: #f1f1ee;
  --surface: #ffffff;
  --surface-subtle: #f7f8f6;
  --surface-muted: #edefec;
  --border: #dcdfdc;

  --success: #2f6446;
  --success-surface: #f1f6f2;
  --warning: #8a5300;
  --warning-surface: #fbeeda;
  --danger: #a3231c;
  --danger-surface: #fae7e5;
  --leave: #5a4494;
  --leave-surface: #eae5f5;

  --r-s: 4px;
  --r-card: 8px;
  --r-card-l: 12px;
  --r-pill: 999px;
  --screen-pad: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  /* Stops iOS bouncing the whole page behind the app shell. */
  overscroll-behavior-y: none;
}

/* Respects the notch and the home indicator on an iPhone. */
#app {
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
}

.pad { padding: var(--screen-pad); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.center { text-align: center; }
.hidden { display: none !important; }

/* ── type ─────────────────────────────────────────────────────────────── */
.display { font-size: 30px; font-weight: 600; line-height: 1.1; letter-spacing: -0.5px; }
.title { font-size: 20px; font-weight: 600; }
.title-s { font-size: 17px; font-weight: 600; }
.body { font-size: 15px; }
.body-s { font-size: 13.5px; color: var(--text-2); }
.caption { font-size: 12px; color: var(--text-3); }
.label {
  font-size: 10px; font-weight: 600; letter-spacing: 0.8px;
  text-transform: uppercase; color: var(--text-3);
}
.strong { font-weight: 600; }
.muted { color: var(--text-3); }
/* The timer uses Plex Mono for the same reason Android does: digits that do not
   shift width as the minutes tick over. */
.mono { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }

/* ── surfaces ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card-l);
  padding: 14px;
}
.card.tint { background: var(--brand-surface-subtle); border-color: var(--brand-border); }

.hero {
  background: linear-gradient(135deg, var(--brand-darkest), var(--brand-dark) 55%, var(--brand));
  color: #fff;
  padding: 20px;
}
.hero .label, .hero .caption { color: rgba(255, 255, 255, 0.62); }
.hero .body-s { color: rgba(255, 255, 255, 0.78); }

.rule { height: 3px; background: linear-gradient(90deg, var(--brand), #d9a441, var(--danger)); }

/* ── controls ─────────────────────────────────────────────────────────── */
button { font: inherit; cursor: pointer; }

.btn {
  display: flex; align-items: center; justify-content: center;
  width: 100%; min-height: 54px; padding: 0 16px;
  background: var(--brand); color: #fff; border: 0;
  font-weight: 600; font-size: 15px; letter-spacing: 0.4px;
}
.btn:disabled { background: var(--surface-muted); color: var(--text-disabled); }
.btn.danger { background: #8e2b22; }
/* Must come after .btn.danger, or a disabled danger button keeps its red and
   looks tappable while doing nothing. */
.btn.danger:disabled, .btn.ghost:disabled {
  background: var(--surface-muted); color: var(--text-disabled); border-color: var(--border);
}
.btn.ghost {
  background: var(--brand-surface); color: var(--brand);
  border: 1.5px solid rgba(47, 100, 70, 0.45); border-radius: var(--r-card);
  min-height: 46px;
}

/* Avatar. A plain circle reads as decoration, so nobody discovers it is
   tappable — the camera badge is the whole affordance. */
.avatar-btn {
  position: relative; background: none; border: 0; padding: 0;
  line-height: 0; cursor: pointer;
}
.avatar-btn .avatar { display: flex; }
.avatar-btn img.avatar { object-fit: cover; }
.avatar-badge {
  position: absolute; right: -2px; bottom: -2px;
  width: 19px; height: 19px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--surface);
  font-size: 9px; line-height: 15px; text-align: center;
}
.avatar-xl {
  width: 104px !important; height: 104px !important;
  font-size: 34px !important; border-radius: 50%; object-fit: cover;
  margin: 0 auto;
}

.emoji-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.emoji-cell {
  aspect-ratio: 1; font-size: 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); cursor: pointer;
}
.emoji-cell.on { background: var(--brand-surface); border: 2px solid var(--brand); }

/* Consent, on the sign-in screen when a code is first claimed. */
.consent {
  display: flex; align-items: center; gap: 10px;
  padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-card);
  cursor: pointer; text-align: left;
}
.consent.on { background: var(--brand-surface); border-color: var(--brand); }
.consent-box {
  width: 24px; flex: 0 0 24px; text-align: center;
  color: var(--brand); font-size: 18px; font-weight: 700;
}
.linkish {
  background: none; border: 0; padding: 6px 12px;
  color: var(--brand); font-weight: 600; font-size: 13.5px; cursor: pointer;
}

/* Confirmation sheet. Slides from the bottom so the buttons land under the
   thumb, and sits above the tab bar and the iOS home indicator. */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(23, 48, 31, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: sheet-fade 140ms ease-out;
}
.sheet {
  width: 100%; max-width: 520px;
  background: var(--surface);
  border-radius: var(--r-card-l) var(--r-card-l) 0 0;
  padding: 22px var(--screen-pad) calc(18px + env(safe-area-inset-bottom));
  animation: sheet-rise 180ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.sheet-num {
  width: 100%; margin-top: 8px; padding: 14px;
  font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums;
  color: var(--text); background: var(--surface-subtle);
  border: 1px solid var(--border); border-radius: var(--r-card);
}
.sheet-num:focus { outline: 2px solid var(--brand); outline-offset: -2px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 20px; }
.sheet-actions .btn { min-height: 50px; }

@keyframes sheet-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes sheet-rise { from { transform: translateY(14px) } to { transform: none } }

/* One-shot entrance only, and skipped entirely when the person asked for less
   motion — the app runs on cheap handsets. */
@media (prefers-reduced-motion: reduce) {
  .sheet-backdrop, .sheet { animation: none; }
}

/* On the hero the action is white so it reads against the gradient. */
.hero .btn { background: #fff; color: var(--brand); }
.hero .btn:disabled { background: rgba(255, 255, 255, 0.14); color: rgba(255, 255, 255, 0.55); }
.hero .btn.danger { background: #8e2b22; color: #fff; border: 1.5px solid rgba(255, 255, 255, 0.38); }

.tile {
  display: flex; align-items: center; gap: 8px;
  min-height: 62px; padding: 0 10px 0 14px;
  background: var(--surface); border: 1.5px solid var(--brand-border);
  font-weight: 600; text-align: left; color: var(--text);
}
.tile:active { background: var(--brand-surface-subtle); transform: scale(0.98); }
.tile .chev { color: var(--brand); font-size: 18px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input, textarea, select {
  font: inherit; width: 100%; padding: 12px 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-card);
}
input:focus, textarea:focus { outline: 2px solid var(--brand-border); outline-offset: -1px; }
textarea { min-height: 110px; resize: vertical; }

.code-input {
  text-align: center; font-size: 28px; font-weight: 600;
  letter-spacing: 6px; padding: 16px; border-radius: var(--r-card-l);
}

/* ── bits ─────────────────────────────────────────────────────────────── */
.pill {
  display: inline-block; padding: 4px 10px; border-radius: var(--r-pill);
  font-size: 10px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase;
}
.pill.ok { background: var(--success-surface); color: var(--success); }
.pill.warn { background: var(--warning-surface); color: var(--warning); }
.pill.bad { background: var(--danger-surface); color: var(--danger); }
.pill.leave { background: var(--leave-surface); color: var(--leave); }
.pill.neutral { background: var(--surface-muted); color: var(--text-2); }

.banner {
  display: flex; gap: 10px; padding: 12px 14px;
  border-left: 4px solid var(--brand); background: var(--brand-surface-subtle);
  border-radius: var(--r-card);
}
.banner.warn { border-color: var(--warning); background: var(--warning-surface); }
.banner.bad { border-color: var(--danger); background: var(--danger-surface); }

.bar { height: 8px; border-radius: var(--r-pill); background: var(--surface-muted); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); transition: width 0.5s ease; }

.avatar {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--brand-surface); color: var(--brand);
  font-size: 13px; font-weight: 600;
}

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card-l); }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 14px; }
.list > .item + .item { border-top: 1px solid var(--border); }

/* ── chrome ───────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px var(--screen-pad); background: var(--surface);
  padding-top: calc(10px + env(safe-area-inset-top));
}
.screen { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.tabbar {
  display: flex; background: var(--brand-darkest);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; padding: 12px 4px 14px; background: none; border: 0;
  color: rgba(255, 255, 255, 0.55); font-size: 11px; font-weight: 600;
}
.tabbar button.on { color: #fff; }
.tabbar .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); margin-left: 4px; vertical-align: top;
}

.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--brand-border); border-top-color: var(--brand);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Someone who prefers less motion gets none of it. */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
