:root {
  --bg: #0c1014;
  --bg-2: #141a20;
  --ink: #f4efe4;
  --muted: #9aa7a0;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --panel: rgba(16, 20, 24, 0.92);
  --gold: #ffd36a;
  --gold-deep: #e08a1a;
  --teal: #6fd0c0;
  --danger: #e86a6a;
  --radius: 18px;
  --sans: "DM Sans", system-ui, -apple-system, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --safe-top: max(12px, env(safe-area-inset-top));
  /* No env(safe-area-inset-bottom): iOS Brave/Safari already reserve the home-indicator strip outside the page. */
  --safe-bottom: 14px;
  /* Shadow for bottom-docked panels: cast upward only, so nothing darkens the page's bottom edge
     (which must stay exactly --bg to match the browser-painted strip below it). */
  --shadow-up: 0 -18px 40px -8px rgba(0, 0, 0, 0.42);
  /* Dimming scrim that fades out over the bottom ~130px, so the page edge stays --bg while a menu is open. */
  --scrim: linear-gradient(to bottom, rgba(0, 0, 0, 0.45) calc(100% - 150px), rgba(0, 0, 0, 0) calc(100% - 20px));
}

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

html {
  /* Solid base colour under everything (overscroll, safe areas, toolbar transitions). */
  background: var(--bg);
  min-height: 100%;
}

html,
body {
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: transparent;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

/* Page gradient on a fixed layer sized to the LARGE viewport and extended through the safe areas.
   Previously the gradient lived on body (height:100%) and repeated below it on iOS, leaving a
   hard band above the home indicator. */
body::before {
  content: "";
  position: fixed;
  z-index: -1;
  /* Over-extend past every edge with plain offsets (no vh/lvh maths). On iOS standalone/Brave the
     previous 100lvh-based height came out ~58px short of the screen, so the bottom-left glow was
     cut off in a hard line above the home indicator. The overhang keeps any edge off-screen. */
  top: -160px;
  bottom: -160px;
  left: -40px;
  right: -40px;
  pointer-events: none;
  /* Bottom fade: the last ~110px of the viewport resolve to exactly --bg (= theme-color). iOS Safari/Brave
     stop the web view ~58pt above the screen edge and paint the strip below (toolbar / home-indicator
     zone) themselves with the theme/background colour — page pixels can never reach it. Fading the glow
     out before the viewport edge makes that seam invisible. (160px = this layer's overhang.) */
  background:
    linear-gradient(to bottom, rgba(12, 16, 20, 0) calc(100% - 160px - 110px), var(--bg) calc(100% - 160px)),
    radial-gradient(900px 500px at 80% calc(160px - 10%), rgba(224, 138, 26, 0.18), transparent 55%),
    radial-gradient(700px 420px at 0% calc(100% - 160px + 110px), rgba(111, 208, 192, 0.12), transparent 50%),
    var(--bg);
  background-repeat: no-repeat;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.screen {
  min-height: 100dvh;
}

.screen[hidden],
[hidden] {
  display: none !important;
}

.poster,
.setup-card {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 28px) 20px 48px;
}

.app-mark {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.ios-hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.9rem;
}

#install-app {
  margin-top: 12px;
}

@media (display-mode: standalone) {
  #install-app,
  #ios-hint {
    display: none !important;
  }
}

h1,
h2 {
  font-family: var(--display);
  letter-spacing: -0.03em;
  font-weight: 700;
}

h1 {
  font-size: clamp(2.2rem, 7vw, 3.6rem);
  line-height: 1.05;
  margin: 6px 0 14px;
}

h2 {
  font-size: 1.6rem;
  margin: 4px 0 10px;
}

h3 {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 18px 0 8px;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 650;
}

.lede {
  color: #c9c2b4;
  margin-bottom: 22px;
}

.lede em {
  color: var(--gold);
  font-style: italic;
}

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

@media (min-width: 640px) {
  .role-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.role-card {
  text-align: left;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}

.role-card.kyle {
  border-color: rgba(255, 211, 106, 0.35);
}

.role-card.seeker {
  border-color: rgba(111, 208, 192, 0.3);
}

.role-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.role-card strong {
  font-size: 1.15rem;
}

.role-card span:last-child {
  color: var(--muted);
  font-size: 0.92rem;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--muted);
}

input {
  background: #0b0f13;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 12px 13px;
}

input[readonly] {
  opacity: 0.72;
  color: var(--muted);
  cursor: default;
}

.hint {
  color: var(--muted);
  margin-bottom: 16px;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 8px 0;
}

.row-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.row-actions.compact {
  margin-top: 0;
}

.btn {
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 650;
}

.btn-primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  color: #1a140c;
}

.btn-danger {
  background: #e5484d;
  color: #fff;
}

.confirm-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--scrim);
  animation: confirm-fade 0.14s ease-out;
}

.confirm-card {
  width: min(340px, 100%);
  background: #121820;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  padding: 20px 18px 16px;
  box-shadow: var(--shadow);
}

.confirm-title {
  margin: 0 0 16px;
  font-family: var(--display, inherit);
  font-size: 1.15rem;
  font-weight: 650;
  color: var(--ink);
  text-align: center;
  overflow-wrap: anywhere;
}

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

.confirm-actions .btn {
  flex: 1;
}

@keyframes confirm-fade {
  from {
    opacity: 0;
  }
}

.btn-ghost {
  border: 1px solid var(--line-strong);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.03);
}

.app-screen {
  position: relative;
  height: 100dvh;
  overflow: hidden;
}

.finder {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 8px) 20px calc(var(--safe-bottom) + 72px);
}

.finder-name {
  font-family: var(--display);
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}

.compass {
  position: relative;
  width: min(72vw, 320px);
  height: min(72vw, 320px);
  display: grid;
  place-items: center;
  perspective: 720px;
  perspective-origin: 50% 50%;
}

.compass.mode-3d {
  /* Stronger perspective so into-screen / out-of-screen tilt reads clearly. */
  perspective: 540px;
}

.compass-sphere {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  transform-style: preserve-3d;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 230, 160, 0.10), transparent 42%),
    radial-gradient(circle at 50% 50%, rgba(255, 211, 106, 0.05), transparent 62%);
}

.compass-floor {
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: 14%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.42), transparent 70%);
  filter: blur(2px);
  pointer-events: none;
  transform: translateZ(-18px);
}

.compass-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 211, 106, 0.18);
  box-shadow:
    inset 0 0 80px rgba(224, 138, 26, 0.08),
    inset 0 -24px 40px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

/* Real 3D arrow (three.js canvas) — 3D mode only, once WebGL view is ready. */
.arrow-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  pointer-events: none;
  filter: drop-shadow(0 18px 22px rgba(90, 50, 8, 0.5));
}

.compass.mode-3d.has-webgl .arrow-canvas {
  display: block;
}

.compass.mode-3d.has-webgl .arrow-scene {
  display: none;
}

.finder.is-lost .arrow-canvas {
  opacity: 0.18;
}

.finder.is-here .arrow-canvas {
  visibility: hidden;
}

.debug-overlay {
  margin: 8px auto 0;
  max-width: 340px;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 211, 106, 0.35);
  color: #ffe9a8;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: left;
  white-space: pre-wrap;
  user-select: text;
  -webkit-user-select: text;
}

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

.arrow-scene {
  width: 62%;
  transform-style: preserve-3d;
  display: grid;
  place-items: center;
  will-change: transform;
  transform-origin: 50% 55%;
}

.arrow-wrap {
  width: 100%;
  will-change: transform;
  transform-style: preserve-3d;
  transform-origin: 50% 50%;
}

.arrow-stack {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
}

.arrow-face {
  width: 100%;
  height: auto;
  display: block;
  transform-origin: 50% 50%;
  backface-visibility: hidden;
}

.arrow-face-back,
.arrow-face-mid {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}

.arrow-face-front,
.arrow {
  position: relative;
  filter: drop-shadow(0 18px 22px rgba(120, 70, 10, 0.55));
  transform: translateZ(12px);
}

/* 3D mode: extruded stack + reveal depth layers */
.compass.mode-3d .arrow-face-back,
.compass.mode-3d .arrow-face-mid {
  opacity: 1;
  visibility: visible;
}

.compass.mode-3d .arrow-face-back {
  transform: translateZ(-16px);
  filter: brightness(0.42) drop-shadow(0 10px 14px rgba(0, 0, 0, 0.35));
}

.compass.mode-3d .arrow-face-mid {
  transform: translateZ(-8px);
  filter: brightness(0.62);
}

.compass.mode-3d .arrow-face-front,
.compass.mode-3d .arrow {
  transform: translateZ(4px);
  filter: drop-shadow(0 22px 26px rgba(90, 50, 8, 0.55));
}

.compass.mode-2d .arrow-face-front,
.compass.mode-2d .arrow {
  transform: none;
  filter: drop-shadow(0 14px 18px rgba(120, 70, 10, 0.5));
}

.arrow .arrow-body {
  /* gradient via fill attr */
}

.alt-cue {
  margin-top: 4px;
  min-height: 1.1em;
  color: var(--muted, #8b9bb0);
  font-size: 0.85rem;
  font-weight: 560;
  letter-spacing: 0.02em;
  opacity: 0.85;
}

.name-card {
  margin-top: 18px;
  padding: 14px 14px 12px;
  border-radius: 14px;
  border: 1px solid rgba(36, 48, 65, 0.95);
  background: rgba(16, 22, 30, 0.72);
}

.name-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.name-card-row strong {
  display: block;
  margin-top: 2px;
  font-size: 1.05rem;
}

.name-card.is-editing .name-card-row {
  display: none;
}

.name-edit {
  margin-top: 12px;
  display: grid;
  gap: 10px;
}

.name-card.is-editing .name-edit {
  margin-top: 0;
}

.name-edit label {
  display: grid;
  gap: 6px;
}

.name-edit input {
  width: 100%;
}

.finder.is-lost .arrow-wrap {
  opacity: 0.18;
}

.finder.is-here .compass-ring {
  border-color: rgba(127, 216, 154, 0.65);
  box-shadow: inset 0 0 80px rgba(127, 216, 154, 0.16), 0 0 48px rgba(127, 216, 154, 0.28);
  animation: here-pulse 1.6s ease-in-out infinite;
}

.finder.is-here .arrow-wrap {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.here-mark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.here-mark[hidden] {
  display: none !important;
}

.here-check {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2.75rem;
  font-weight: 700;
  color: #7fd89a;
  background: rgba(127, 216, 154, 0.14);
  border: 2px solid rgba(127, 216, 154, 0.7);
  box-shadow: 0 0 28px rgba(127, 216, 154, 0.28);
}

.finder.is-here .finder-name {
  color: #7fd89a;
}

@keyframes here-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.03); opacity: 0.92; }
}

.status {
  min-height: 1.3em;
  color: var(--teal);
  font-size: 0.92rem;
  margin: 4px 0 10px;
  text-align: center;
}

#enable-sensors {
  margin-top: 14px;
}

.kyle-screen {
  height: 100dvh;
  overflow: auto;
  padding: calc(var(--safe-top) + 28px) 20px calc(var(--safe-bottom) + 24px);
  max-width: 520px;
  margin: 0 auto;
}

.setting-card {
  margin-top: 16px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(36, 48, 65, 0.95);
  background: rgba(16, 22, 30, 0.72);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.setting-copy strong {
  font-size: 0.98rem;
}

.setting-hint {
  color: var(--muted, #8b9bb0);
  font-size: 0.78rem;
  line-height: 1.35;
  font-weight: 500;
}

.seg {
  display: inline-flex;
  flex-shrink: 0;
  border-radius: 999px;
  padding: 3px;
  background: rgba(11, 15, 19, 0.9);
  border: 1px solid rgba(53, 80, 110, 0.55);
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted, #8b9bb0);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  min-width: 48px;
}

.seg-btn.is-active {
  background: linear-gradient(180deg, #ffe08a, #e08a1a);
  color: #0c1014;
  box-shadow: 0 4px 12px rgba(224, 138, 26, 0.35);
}

.seg-btn:focus-visible {
  outline: 2px solid rgba(255, 211, 106, 0.7);
  outline-offset: 2px;
}


.peek {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: var(--safe-bottom);
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 650;
  backdrop-filter: blur(12px);
}

.sheet {
  position: absolute;
  z-index: 8;
  left: 12px;
  right: 12px;
  bottom: var(--safe-bottom);
  max-height: min(70dvh, 560px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px 16px 16px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow-up);
}

.profile-btn {
  position: absolute;
  z-index: 7;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  right: max(8px, env(safe-area-inset-right, 0px));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: #6d8588;
  -webkit-tap-highlight-color: transparent;
}

.profile-btn-inner {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: rgba(90, 110, 115, 0.1);
}

.profile-btn:active .profile-btn-inner {
  background: rgba(90, 110, 115, 0.2);
}

/* Profile: a popover anchored top-right, its top aligned with the profile icon's top. */
.sheet.profile-sheet {
  z-index: 9;
  top: calc(env(safe-area-inset-top, 0px) + 6px);
  right: max(8px, env(safe-area-inset-right, 0px));
  bottom: auto;
  left: auto;
  width: min(360px, calc(100vw - 16px));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - 24px);
  padding: 14px 16px 16px;
  border-radius: 18px;
  transform-origin: top right;
  animation: profile-pop 0.16s ease-out;
  box-shadow: var(--shadow);
}

@keyframes profile-pop {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Feedback bug button sits behind every sheet/menu (its own modal/backdrop keep their high z-index). */
#ficarra-feedback-root .ff-fab {
  z-index: 4 !important;
  bottom: 10px !important;
}

/* Feedback form: same bottom margin as our sheets, upward shadow, scrim that fades out at the bottom. */
#ficarra-feedback-root .ff-modal {
  bottom: var(--safe-bottom) !important;
  box-shadow: var(--shadow-up) !important;
}

#ficarra-feedback-root .ff-backdrop {
  background: var(--scrim) !important;
}

.profile-group > * + * {
  margin-top: 12px;
}


.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.code-box {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #0b0f13;
  border: 1px dashed rgba(255, 211, 106, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.code-box strong {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0.14em;
  font-size: 1.25rem;
  color: var(--gold);
}

.muted {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toggle {
  position: relative;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--ink);
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
}

.toggle-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.toggle-copy strong {
  color: var(--ink);
  font-size: 0.95rem;
  font-weight: 600;
}

.toggle-hint {
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.toggle-ui {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #2c3a4c;
  border: 1px solid var(--line-strong);
  transition: background 0.18s ease, border-color 0.18s ease;
}

.toggle-ui::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #8896a6;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.18s ease, background 0.18s ease;
}

.toggle input:checked + .toggle-ui {
  background: rgba(224, 138, 26, 0.35);
  border-color: var(--gold-deep);
}

.toggle input:checked + .toggle-ui::after {
  transform: translateX(20px);
  background: var(--gold);
}

.toggle input:focus-visible + .toggle-ui {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.add-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.list li.is-active {
  border-color: rgba(255, 211, 106, 0.45);
}

.list .meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.empty {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 4px 2px 8px;
}

.pick {
  text-align: left;
  flex: 1;
  background: none;
  color: inherit;
}

#friend-code {
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
}

#friend-code:active {
  opacity: 0.75;
}

#enable-sensors {
  min-width: 200px;
}

.ios-hint {
  max-width: 36em;
}

#refresh-finder {
  margin-top: 12px;
}
#kyle-update-row {
  margin: 8px 0 4px;
}
