/* space2 — TV screen UI. Direction: soft premium, one sheet, one accent (sunlight). */
:root {
  --ink: #f3f5ff;
  --ink-2: rgba(243, 245, 255, 0.58);
  --glass: rgba(11, 15, 34, 0.72);
  --well: rgba(255, 255, 255, 0.07);
  --well-hi: rgba(255, 255, 255, 0.12);
  --sun: #ffd23f;
  --sun-ink: #201600;
  --danger: #ff6b5e;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --font: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Hiragino Maru Gothic ProN", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #03040b; overflow: hidden; }
body { font-family: var(--font); color: var(--ink); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; width: 100%; height: 100%; opacity: 0; transition: opacity 1.6s ease; }
body.ready #stage canvas { opacity: 1; }
body.idle { cursor: none; }

/* preloader: a moon on an orbit, nothing else */
.pre { position: fixed; inset: 0; display: grid; place-content: center; justify-items: center; gap: 28px; background: #03040b; transition: opacity 1.2s ease; z-index: 5; }
body.ready .pre { opacity: 0; pointer-events: none; }
.pre-orbit { width: 64px; height: 64px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px rgba(243, 245, 255, 0.14); animation: spin 2.4s linear infinite; }
.pre-orbit i { display: block; width: 10px; height: 10px; margin: -5px auto 0; border-radius: 50%; background: var(--sun); box-shadow: 0 0 18px var(--sun); }
.pre-bar { width: 120px; height: 3px; border-radius: 3px; background: rgba(243, 245, 255, 0.1); overflow: hidden; }
.pre-fill { height: 100%; background: var(--ink); transform: scaleX(0); transform-origin: left; transition: transform 0.5s var(--ease); }
@keyframes spin { to { transform: rotate(360deg); } }

/* menu button: two strokes that cross */
.menu-btn {
  position: fixed; z-index: 10; top: max(20px, env(safe-area-inset-top)); right: max(20px, env(safe-area-inset-right));
  width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.4); -webkit-backdrop-filter: blur(18px) saturate(1.4);
  color: var(--ink); transition: opacity 0.6s ease, transform 0.35s var(--ease), background-color 0.25s ease;
}
.menu-btn span { position: absolute; left: 17px; width: 18px; height: 2px; border-radius: 2px; background: currentColor; transition: transform 0.4s var(--ease); }
.menu-btn span:first-child { top: 21px; }
.menu-btn span:last-child { top: 29px; }
.menu-btn.open span:first-child { transform: translateY(4px) rotate(45deg); }
.menu-btn.open span:last-child { transform: translateY(-4px) rotate(-45deg); }
.menu-btn:hover { background: rgba(26, 32, 66, 0.86); }
.menu-btn:active { transform: scale(0.94); }
body.idle .menu-btn:not(.open) { opacity: 0; }
@media (hover: none) { body.idle .menu-btn:not(.open) { opacity: 0.55; } }

/* sheet */
.sheet {
  position: fixed; z-index: 9; top: max(84px, calc(env(safe-area-inset-top) + 64px)); right: max(20px, env(safe-area-inset-right));
  width: 348px; max-height: calc(100dvh - 104px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  padding: 20px; border-radius: 30px;
  background: var(--glass); backdrop-filter: blur(28px) saturate(1.5); -webkit-backdrop-filter: blur(28px) saturate(1.5);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  display: grid; gap: 22px;
  opacity: 0; visibility: hidden; transform: translateY(-10px) scale(0.97); transform-origin: top right;
  transition: opacity 0.3s ease, transform 0.45s var(--ease), visibility 0s linear 0.3s;
}
.sheet::-webkit-scrollbar { display: none; }
.sheet.open { opacity: 1; visibility: visible; transform: none; transition-delay: 0s; }
.grabber { display: none; }

.scan-open { display: grid; grid-template-columns: 132px 1fr; gap: 18px; align-items: center; }
.qr { display: block; width: 132px; height: 132px; padding: 9px; border-radius: 22px; background: #fff; transition: transform 0.35s var(--ease); }
.qr:hover { transform: scale(1.03); }
.qr svg { display: block; width: 100%; height: 100%; }
.scan-title { display: block; font-size: 19px; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; color: var(--ink); text-decoration: none; }
.hint { margin: 6px 0 0; font-size: 14px; line-height: 1.35; color: var(--ink-2); }
.pin { margin: 16px 0 0; display: flex; align-items: baseline; gap: 8px; }
.pin span { font-size: 13px; color: var(--ink-2); }
.pin b { font-size: 30px; font-weight: 800; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; color: var(--sun); }

.scan-locked > div { display: grid; gap: 12px; }
.pin-input {
  width: 100%; height: 68px; border: 0; border-radius: 20px; outline: 0; background: var(--well);
  font: 800 32px/1 var(--font); letter-spacing: 0.5em; text-indent: 0.5em; text-align: center; color: var(--ink); caret-color: var(--sun);
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
}
.pin-input::placeholder { color: rgba(243, 245, 255, 0.22); }
.pin-input:focus { background: var(--well-hi); box-shadow: 0 0 0 2px var(--sun); }
.pin-msg { margin: 0; min-height: 18px; font-size: 14px; color: var(--danger); }

.rows { display: grid; gap: 4px; }
.row {
  display: flex; align-items: center; justify-content: space-between; min-height: 56px; padding: 0 6px 0 4px;
  font-size: 17px; font-weight: 600; color: var(--ink); text-decoration: none; border-radius: 16px;
}
a.row { transition: background-color 0.2s ease, padding 0.3s var(--ease); color: var(--ink); }
a.row svg { color: var(--ink-2); transition: transform 0.3s var(--ease); }
a.row:hover { background: var(--well); padding-left: 14px; }
a.row:hover svg { transform: translateX(3px); }

.switch { position: relative; width: 56px; height: 34px; padding: 0; border: 0; border-radius: 17px; cursor: pointer; background: var(--well-hi); transition: background-color 0.3s ease; }
.switch i { position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%; background: var(--ink); transition: transform 0.4s var(--ease), background-color 0.3s ease; }
.switch[aria-checked="true"] { background: var(--sun); }
.switch[aria-checked="true"] i { transform: translateX(22px); background: var(--sun-ink); }

.crew-wrap h2 { margin: 0 0 14px 4px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); }
.crew-wrap h2 span { color: var(--ink); margin-left: 4px; }
.crew { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.crew-empty { grid-column: 1 / -1; margin: 0 4px; font-size: 15px; line-height: 1.4; color: var(--ink-2); }
.face { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 50%; overflow: hidden; cursor: pointer; background: #e9edf8; transition: transform 0.35s var(--ease), box-shadow 0.25s ease; }
.face img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: 50% 12%; transform: scale(1.9); transform-origin: 50% 14%; }
.face:hover { transform: scale(1.06); }
.face.armed { box-shadow: 0 0 0 3px var(--danger); }
.face.armed::after {
  content: ""; position: absolute; inset: 0; background: rgba(255, 107, 94, 0.82)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.6' stroke-linecap='round'%3E%3Cpath d='M7 7l10 10M17 7L7 17'/%3E%3C/svg%3E") center / 46% no-repeat;
}
.manage { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 18px 4px 0; }
.quiet { padding: 6px 0; border: 0; background: none; cursor: pointer; font: 600 15px/1.2 var(--font); color: var(--ink-2); transition: color 0.2s ease; }
.quiet:hover { color: var(--ink); }
.quiet.armed { color: var(--danger); }

:where(button, a, input):focus-visible { outline: 2px solid var(--sun); outline-offset: 3px; }

/* phone: the same sheet rises from the bottom */
@media (max-width: 600px) {
  .menu-btn { top: max(14px, env(safe-area-inset-top)); right: 14px; }
  .sheet {
    top: auto; right: 0; left: 0; bottom: 0; width: auto; max-height: 86dvh;
    padding: 10px 20px calc(24px + env(safe-area-inset-bottom)); border-radius: 30px 30px 0 0;
    transform: translateY(104%); transform-origin: bottom; opacity: 1;
    transition: transform 0.5s var(--ease), visibility 0s linear 0.5s;
  }
  .sheet.open { transform: none; }
  .grabber { display: block; width: 40px; height: 5px; margin: 0 auto -6px; border-radius: 3px; background: rgba(243, 245, 255, 0.22); }
  .crew { grid-template-columns: repeat(5, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .menu-btn, .menu-btn span, .switch i, .face, a.row { transition-duration: 0.01s; }
  .pre-orbit { animation: none; }
}
