/*
 * Mobile client styling.
 *
 * Used one-handed, often while walking, sometimes in the dark. That drives everything here:
 * large hit targets (48px floor, spec 3.1), high contrast, and a dark default because this gets
 * opened at night on the way to the bathroom.
 */

:root {
  --bg: #101114;
  --surface: #1a1c21;
  --surface-2: #23262c;
  --fg: #f2f3f5;
  --muted: #9aa1a9;
  --line: #2e3238;
  --accent: #ff3b30;
  --accent-fg: #ffffff;
  --ok: #34c759;
  --bad: #ff453a;
  --radius: 14px;
  --tap: 52px; /* comfortably above the 48px minimum */
}

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

/*
 * Must come before any component rule that sets `display`. The browser's own
 * `[hidden] { display: none }` is a plain attribute selector, so a class rule like
 * `.btn { display: inline-flex }` outranks it and the element stays visible with the attribute
 * set. Everything in this file toggles visibility through `hidden`, so that silently breaks all
 * of it.
 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  overflow-x: hidden; /* the page must never scroll sideways */
}

body {
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ---------------------------------------------------------------- top bar */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 10;
}

.brand {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  display: inline-block;
  flex: none;
  transition: background 0.2s;
}

.conn.on .dot {
  background: var(--ok);
}

/* ------------------------------------------------------------------ main */

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.thumb-wrap {
  margin: -14px -14px 12px;
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
  background: var(--surface-2);
}

.thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.thumb-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 14px;
}

.title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 620;
  line-height: 1.3;
  letter-spacing: -0.01em;
  /* Long YouTube titles must not push the layout sideways. */
  overflow-wrap: anywhere;
}

.meta {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pos {
  color: var(--fg);
  font-weight: 600;
}

.owner {
  margin-left: auto;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

/* ---------------------------------------------------------------- player */

.player-wrap {
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  border: 1px solid var(--line);
}

.player-wrap #player,
.player-wrap iframe {
  display: block;
  width: 100%;
  /*
   * `height: auto` is required, not cosmetic. The YouTube API stamps a height="360" attribute
   * on the iframe it creates, which browsers map to a presentational height hint — and
   * `aspect-ratio` is only honoured when height resolves to auto. Without this the player
   * renders as a ~1:1 box instead of 16:9.
   */
  height: auto;
  aspect-ratio: 16 / 9;
  border: 0;
}

/* --------------------------------------------------------------- buttons */

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 12px 18px;
  font: inherit;
  font-weight: 620;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.06s ease, opacity 0.15s;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-lg {
  min-height: 60px;
  font-size: 17px;
}

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

.btn-secondary {
  background: var(--surface-2);
}

.btn-nudge {
  flex: 1;
  min-height: var(--tap);
  padding: 10px 6px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.nudge-row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

/* -------------------------------------------------------------- fallback */

.fallback {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}

.fallback-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
}

.fallback-body {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
}

.note {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.estimate-value {
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 6px 0;
  letter-spacing: -0.02em;
}

.screen-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
  text-align: center;
  padding: 0 8px;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 550;
  z-index: 50;
  box-shadow: 0 8px 28px rgb(0 0 0 / 45%);
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* Respect the system preference; the default is dark because of when this gets used. */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #f7f8fa;
    --surface-2: #eceef1;
    --fg: #14161a;
    --muted: #5f666e;
    --line: #dde0e4;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
  .btn:active {
    transform: none;
  }
}

/* ------------------------------------------------------------ auth pages */

.auth-main {
  display: flex;
  justify-content: center;
  padding: 24px 16px 48px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.auth-title {
  margin: 0 0 20px;
  font-size: 22px;
  font-weight: 650;
}

.field {
  display: block;
  margin-bottom: 18px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.optional {
  margin-left: 6px;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  /* 16px minimum, or iOS Safari zooms the whole page on focus. */
  font-size: 16px;
  font-family: inherit;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.field-hint {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.form-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--bad) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 45%, transparent);
  color: var(--fg);
  font-size: 14px;
}

.auth-card .btn-lg {
  width: 100%;
}

.auth-alt {
  margin: 18px 0 0;
  text-align: center;
  font-size: 15px;
  color: var(--muted);
}

.auth-alt a {
  color: var(--fg);
}

.privacy-note {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

/* --------------------------------------------------------- paste a link */

.bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn-quiet {
  min-height: 36px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 14px;
}

.paste-row {
  display: flex;
  gap: 8px;
}

.paste-row .input {
  flex: 1 1 auto;
  min-width: 0; /* without this a flex item refuses to shrink and the row overflows on mobile */
}

.paste-row .btn {
  flex: 0 0 auto;
  padding-inline: 20px;
}

.paste-card .form-error {
  margin: 12px 0 0;
}

/* ---------------------------------------------------------- google button */

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--line);
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
}

.g-mark {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

/* A labelled rule, so "or" sits in a gap in the line rather than on top of it. */
.or-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 13px;
}

.or-sep::before,
.or-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* --------------------------------------------------- desktop extension card */

.ext-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
}

.ext-body {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.token-out {
  margin-top: 14px;
}

.token-value {
  display: block;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  /* A 43-character token must wrap rather than push the card sideways on a phone. */
  word-break: break-all;
  user-select: all;
}
