:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #10201d;
  --muted: #5a6b67;
  --border: #dde6e3;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-soft: #d5efeb;
  --on-accent: #ffffff;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --warn: #b45309;
  --warn-soft: #fbefd9;
  --danger: #c62828;
  --danger-soft: #fbe3e1;
  --shadow: 0 1px 2px rgb(16 32 29 / 6%), 0 4px 16px rgb(16 32 29 / 6%);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1211;
    --surface: #121d1b;
    --surface-2: #182624;
    --text: #e4efec;
    --muted: #93a6a1;
    --border: #23332f;
    --accent: #2cc2b0;
    --accent-strong: #5fd8c9;
    --accent-soft: #123a35;
    --on-accent: #04201c;
    --ok: #4ade80;
    --ok-soft: #12321f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --danger: #f87171;
    --danger-soft: #3d1615;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

a { color: inherit; }

svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ chrome */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark { width: 28px; height: 28px; }
.mark-core { fill: var(--accent); stroke: none; }
.mark-dot { fill: var(--on-accent); stroke: none; }
.mark-ripple { stroke: var(--accent); stroke-width: 2.2; opacity: 0.55; }

.lang-toggle {
  min-width: 44px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font: 600 13px/1 var(--font);
  cursor: pointer;
}
.lang-toggle:hover { color: var(--text); }

main {
  flex: 1;
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
}

.footer {
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------------ shared */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font: 600 16px/1.2 var(--font);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-block { width: 100%; }
.btn-small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:not(:disabled):hover { background: var(--accent-strong); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-strong); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn:focus-visible, .choice:focus-visible, .icon-btn:focus-visible, .lang-toggle:focus-visible, .code-input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: rgb(0 0 0 / 45%);
  color: #fff;
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }

.status-row { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.chip-neutral::before { display: none; }
.chip[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
.chip[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
.chip[data-tone="bad"] { background: var(--danger-soft); color: var(--danger); }
.chip[data-tone="warn"]::before { animation: blink 1.2s ease-in-out infinite; }

@keyframes blink { 50% { opacity: 0.25; } }

.banner {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 14px;
  font-weight: 600;
}

.hint { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }

.content-preview {
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  word-break: break-all;
  white-space: pre-wrap;
  max-height: 9em;
  overflow: auto;
}
.content-preview.empty { font-family: var(--font); color: var(--muted); }
.content-meta, .qr-meta { margin-top: 8px; font-size: 13px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 10;
}

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

/* ------------------------------------------------------------------ home */

.hero { text-align: center; padding: 28px 0 24px; }
.hero-title { margin: 0; font-size: clamp(36px, 9vw, 56px); letter-spacing: -0.03em; line-height: 1.1; }
.hero-tagline { margin: 6px 0 0; font-size: 18px; font-weight: 600; color: var(--accent); }
.hero-desc { margin: 12px auto 0; max-width: 32em; color: var(--muted); }

.choices {
  display: grid;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}
@media (min-width: 640px) { .choices { grid-template-columns: 1fr 1fr; gap: 16px; } }

.choice {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-items: center;
  padding: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-decoration: none;
  transition: transform 0.15s, border-color 0.15s;
}
.choice:hover { border-color: var(--accent); transform: translateY(-1px); }
.choice svg { grid-row: span 2; width: 44px; height: 44px; padding: 9px; border-radius: 12px; }
.choice-share svg { background: var(--accent); color: var(--on-accent); }
.choice-join svg { background: var(--accent-soft); color: var(--accent-strong); }
.choice-title { font-size: 19px; font-weight: 700; }
.choice-sub { font-size: 14px; color: var(--muted); }

.facts {
  display: grid;
  gap: 8px;
  max-width: 720px;
  margin: 24px auto 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--muted);
}
.facts li { display: flex; gap: 8px; }
.facts li::before { content: "✓"; color: var(--accent); font-weight: 700; }

/* ------------------------------------------------------------------ share */

.share-grid { display: grid; gap: 12px; }

@media (min-width: 860px) {
  .share-grid {
    grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
    grid-template-areas:
      "camera code"
      "camera content"
      "camera end";
    grid-template-rows: auto auto 1fr;
    align-items: start;
    gap: 16px;
  }
  .share-grid .camera-card { grid-area: camera; }
  .share-grid .code-card { grid-area: code; }
  .share-grid .content-card { grid-area: content; }
  .share-grid #share-end { grid-area: end; }
}

.pair-code {
  margin: 4px 0 10px;
  font-family: var(--mono);
  font-size: clamp(40px, 12vw, 56px);
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.camera-card { padding: 0; overflow: hidden; }

.camera {
  position: relative;
  aspect-ratio: 1 / 1;
  max-height: 72vh;
  width: 100%;
  background: #0b0f0e;
  overflow: hidden;
}
@media (min-width: 860px) { .camera { aspect-ratio: 4 / 3.4; } }

.camera video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera video.mirrored { transform: scaleX(-1); }

/* The viewfinder size is mirrored in scanner.js (VIEWFINDER_RATIO). */
.viewfinder {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  max-width: 70cqh;
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgb(0 0 0 / 38%);
  transition: box-shadow 0.2s;
}
.camera { container-type: size; }
@supports not (container-type: size) {
  .viewfinder { max-width: none; }
}
.viewfinder i {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 4px solid #fff;
  opacity: 0.9;
  transition: border-color 0.2s;
}
.viewfinder i:nth-child(1) { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-top-left-radius: 18px; }
.viewfinder i:nth-child(2) { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-top-right-radius: 18px; }
.viewfinder i:nth-child(3) { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-bottom-left-radius: 18px; }
.viewfinder i:nth-child(4) { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-bottom-right-radius: 18px; }
.viewfinder.detected i { border-color: #4ade80; }

.camera-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  background: rgb(11 15 14 / 88%);
  color: #f1f5f4;
  text-align: center;
}
.camera-message p { margin: 0; max-width: 26em; }

.camera-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}
.camera-bar > * { pointer-events: auto; }

.scan-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.scan-pill:empty { display: none; }

.camera-actions { display: flex; align-items: center; gap: 8px; }

/* Current auto-zoom level; tapping it resets to 1x. */
.zoom-badge {
  min-width: 52px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgb(0 0 0 / 55%);
  color: #fff;
  font: 700 14px/1 var(--font);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.scan-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fbbf24;
}
.scan-pill[data-state="scanning"]::before { animation: blink 1s ease-in-out infinite; }
.scan-pill[data-state="detected"]::before { background: #4ade80; }
.scan-pill[data-state="lost"]::before, .scan-pill[data-state="closer"]::before { background: #fb923c; }
.scan-pill[data-state="paused"]::before, .scan-pill[data-state="error"]::before { background: #f87171; }

/* Several codes in view: numbered markers on the preview plus a list. */
.code-markers { position: absolute; inset: 0; pointer-events: none; }
.code-outlines { position: absolute; inset: 0; width: 100%; height: 100%; }
.code-outlines polygon {
  fill: rgb(255 255 255 / 12%);
  stroke: #fff;
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}
.code-outlines polygon.is-current { fill: rgb(74 222 128 / 18%); stroke: #4ade80; }

.code-marker {
  position: absolute;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  border: 2px solid #fff;
  border-radius: 50%;
  background: rgb(0 0 0 / 62%);
  color: #fff;
  font: 700 18px/1 var(--font);
  cursor: pointer;
  pointer-events: auto;
}
.code-marker.is-current { background: #16a34a; border-color: #bbf7d0; }

.code-choices { padding: 12px 14px 14px; border-top: 1px solid var(--border); }
.code-choices-title { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.code-choices-list { display: grid; gap: 6px; }
.code-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: 14px/1.3 var(--font);
  text-align: left;
  cursor: pointer;
}
.code-choice:hover { border-color: var(--accent); }
.code-choice.is-current { border-color: var(--ok); background: var(--ok-soft); }
.code-choice-num {
  flex: none;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--text);
  color: var(--surface);
  font-weight: 700;
  font-size: 13px;
}
.code-choice.is-current .code-choice-num { background: var(--ok); color: #fff; }
.code-choice-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 13px; }
.code-choice-tag { flex: none; font-size: 12px; font-weight: 700; color: var(--ok); }
.code-marker:focus-visible, .code-choice:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ join */

.view-join { max-width: 560px; margin: 0 auto; }

.join-form { display: grid; gap: 14px; margin-top: 12px; padding: 20px; }

.code-input {
  width: 100%;
  padding: 12px 0 12px 0.45em;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--text);
  font: 700 clamp(34px, 11vw, 44px)/1.1 var(--mono);
  letter-spacing: 0.45em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.code-input::placeholder { color: var(--border); letter-spacing: 0.45em; }
.code-input:focus { border-color: var(--accent); outline: none; }
.code-input[aria-invalid="true"] { border-color: var(--danger); }

.form-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 600; text-align: center; }

.join-session { display: grid; gap: 12px; }

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
}
.session-code { font-family: var(--mono); font-size: 24px; font-weight: 700; letter-spacing: 0.12em; }

.qr-card { display: grid; justify-items: center; padding: 20px 16px; }

.qr-frame {
  display: grid;
  place-items: center;
  width: min(100%, 420px);
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  background: #fff;
}
.qr-frame svg { width: 100%; height: 100%; display: block; border-radius: 12px; }
.qr-frame.updated { animation: pulse 0.6s ease-out; }
.qr-frame.stale svg { opacity: 0.45; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}

.qr-placeholder { display: grid; justify-items: center; gap: 12px; padding: 24px; color: #5a6b67; text-align: center; }
.qr-placeholder p { margin: 0; font-size: 14px; }

.ended-card { display: grid; justify-items: center; gap: 12px; margin-top: 12px; padding: 28px 20px; text-align: center; }
.ended-card svg { width: 48px; height: 48px; color: var(--muted); }
.ended-card h2 { margin: 0; font-size: 20px; }
.ended-card p { margin: 0; color: var(--muted); }
.ended-card .btn { width: 100%; max-width: 320px; }

.view-share .ended-card { max-width: 560px; margin: 12px auto 0; }
