:root {
  color-scheme: dark;
  font: 16px/1.55 "Geist", "Segoe UI", system-ui, sans-serif;
  color: #f3f4fa;
  background: #10121a;
  --accent: #d2ff88;
  --muted: #b4b9ce;
  --line: #363b50;
}

* { box-sizing: border-box; }
body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(ellipse at 76% 0, #292847, transparent 52rem),
    radial-gradient(ellipse at 12% 78%, #1a3736, transparent 42rem);
}
.shell {
  width: min(100% - max(20px, env(safe-area-inset-left)) - max(20px, env(safe-area-inset-right)), 920px);
  margin-inline: auto;
}
header { border-bottom: 1px solid #ffffff1a; background: #10121a55; backdrop-filter: blur(16px); }
header:has(#lock[hidden]) { display: none; }
header { padding-top: env(safe-area-inset-top); }
.topbar { min-height: 70px; display: flex; align-items: center; justify-content: flex-end; }
.topbar-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding-block: 8px; }
main { padding-block: 32px max(36px, env(safe-area-inset-bottom)); }
main:has(#vault[hidden]) {
  position: relative;
  display: grid;
  min-height: 100svh;
  padding-block: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-bottom));
  place-items: center;
  perspective: 1000px;
}
main:has(#vault[hidden])::before {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background: radial-gradient(ellipse at center, #baff6716, transparent 63%),
    radial-gradient(circle, #c6c0ff32 1px, transparent 1px) 0 0 / 19px 19px;
  mask-image: radial-gradient(ellipse, #000 12%, transparent 70%);
  animation: field-drift 12s ease-in-out infinite alternate;
}
#locked {
  position: relative;
  width: min(100%, 460px);
  border-color: #93a1aa46;
  background: linear-gradient(155deg, #dce7ff20, #b3c0ff07 60%, #adf4df0c), #1317228c;
  box-shadow: 0 1px #ffffff24 inset, 0 9px 0 -4px #11131d, 0 34px 75px #05060db8;
  transform: rotateX(var(--tilt-x, 0deg)) rotateY(var(--tilt-y, 0deg));
  transition: transform 360ms cubic-bezier(.2,.75,.25,1), border-color 360ms;
}
#locked:focus-within { transform: none; border-color: #d2ff8870; }
.cipher {
  position: relative;
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 18px;
  perspective: 180px;
  color: var(--accent);
}
.cipher span {
  position: absolute;
  inset: 6px;
  border: 1px solid currentColor;
  border-radius: 50%;
  box-shadow: 0 0 10px #d2ff8840, inset 0 0 8px #d2ff8825;
  transform: rotateZ(var(--orbit)) rotateY(58deg);
  animation: cipher-orbit 5s linear infinite;
}
.cipher span:nth-child(1) { --orbit: 0deg; }
.cipher span:nth-child(2) { --orbit: 60deg; }
.cipher span:nth-child(3) { --orbit: 120deg; }
.cipher::after {
  width: 9px;
  height: 9px;
  border: 1px solid currentColor;
  background: #d2ff8840;
  box-shadow: 0 0 16px #d2ff8866;
  content: "";
  transform: rotate(45deg);
}
#locked:has(#accessButton:disabled) .cipher span { animation-duration: 1.2s; }
@keyframes cipher-orbit {
  to { transform: rotateZ(calc(var(--orbit) + 360deg)) rotateY(58deg); }
}
@keyframes field-drift {
  to { transform: translateY(-16px); opacity: .48; }
}
#locked h1 { margin: 0; font-size: clamp(2rem, 7vw, 3rem); letter-spacing: -.06em; line-height: 1.1; }
#accessButton { width: 100%; }
h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.035em; }
p { color: var(--muted); margin: 12px 0 0; }
.panel, article {
  padding: clamp(16px, 4vw, 28px);
  background: linear-gradient(145deg, #e6ebff16, #d2ff8805), #181c2980;
  backdrop-filter: blur(16px) saturate(125%);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: inset 0 1px #ffffff10, 0 16px 35px #08091052;
}
form { margin-top: 16px; }
label { display: block; font-size: .875rem; margin-bottom: 6px; font-weight: 650; }
input, button { font: inherit; min-height: 44px; border-radius: 9px; border: 1px solid var(--line); }
input { width: 100%; padding: 9px 12px; background: #080c155c; color: inherit; margin-bottom: 14px; }
input::placeholder { color: #a0a6bc; }
button { cursor: pointer; padding: 8px 15px; background: #d4ddff13; color: inherit; font-weight: 650; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #182214; border-color: var(--accent); box-shadow: 0 4px 0 #678941; }
button.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 #678941; }
button:disabled { opacity: .65; cursor: wait; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.grid { display: grid; grid-template-columns: 1fr 2fr; gap: 16px; }
.history { margin-top: 36px; }
#historyPanel summary, #rotatePanel summary, #backupPanel summary, #restorePanel summary { cursor: pointer; font-weight: 700; }
#restorePanel { margin-top: 16px; }
#restorePanel:not([open]) summary { color: var(--muted); font-size: .85rem; }
#retryBackup { margin-top: 12px; }
#savedHistory { padding-left: 20px; margin-bottom: 0; overflow-wrap: anywhere; }
#savedHistory li + li { margin-top: 10px; }
#savedHistory time { display: block; }
.row { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
article { margin-top: 12px; }
article strong { overflow-wrap: anywhere; }
.otp { display: block; font: 700 1.6rem ui-monospace, monospace; color: var(--accent); letter-spacing: .13em; margin-top: 6px; }
.otp-remaining { display: block; margin-top: 12px; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.otp-remaining + progress { margin-top: 6px; }
.muted { color: var(--muted); font-size: .85rem; }
#message, #accessMessage { color: var(--accent); }
#message:empty, #accessMessage:empty { margin: 0; }
#keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 64px));
  justify-content: center;
  gap: 9px 14px;
  margin: 16px 0 20px;
  transform-origin: top center;
  animation: keypad-in 240ms cubic-bezier(.2,.75,.25,1) both;
}
#keypad button {
  width: 100%;
  min-height: 0;
  aspect-ratio: 1;
  padding: 4px;
  border-radius: 50%;
  border-color: #e1eaff2e;
  background: linear-gradient(#e1eaff18, #aebce608);
  box-shadow: 0 1px #ffffff1c inset;
  font-size: 1.35rem;
  font-weight: 500;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, border-color 120ms ease;
}
#keypad button:nth-child(10) { grid-column: 2; }
#keypad button:hover { border-color: var(--accent); }
#keypad button:active {
  transform: scale(.94);
  background: var(--accent);
  border-color: var(--accent);
  color: #172112;
  box-shadow: 0 0 16px #d2ff8866;
}
@keyframes keypad-in {
  from { opacity: 0; transform: perspective(500px) rotateX(-12deg) translateY(-6px); }
}
#invite { letter-spacing: .22em; margin-bottom: 0; }
#financeLink { color: var(--accent); }
.access-sequence {
  position: relative;
  overflow: hidden;
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid #d2ff8845;
  border-radius: 10px;
  background: #090f13b8;
  font: .75rem/1.7 ui-monospace, Consolas, monospace;
}
.access-sequence::after {
  position: absolute;
  inset: 0 0 auto;
  height: 24px;
  background: linear-gradient(transparent, #d2ff881c, transparent);
  content: "";
  pointer-events: none;
  animation: access-scan 650ms linear infinite;
}
.access-stream {
  display: grid;
  overflow: hidden;
  color: #d2ff8880;
  white-space: nowrap;
}
.access-stream span { animation: access-decode 500ms steps(8, end) infinite alternate; }
.access-stream span:nth-child(2) { animation-delay: -170ms; }
.access-stream span:nth-child(3) { animation-delay: -320ms; }
.access-sequence p { margin-top: 6px; color: var(--accent); }
#vault:not([hidden]) { animation: vault-in 320ms cubic-bezier(.2,.75,.25,1) both; }
@keyframes access-scan {
  from { transform: translateY(-100%); }
  to { transform: translateY(120px); }
}
@keyframes access-decode {
  from { clip-path: inset(0 80% 0 0); }
  to { clip-path: inset(0); }
}
@keyframes vault-in {
  from { opacity: 0; transform: translateY(9px); }
}
progress { display: block; width: 100%; height: 6px; accent-color: var(--accent); margin-top: 16px; }
[hidden] { display: none !important; }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; gap: 0; }
  .cipher { width: 48px; height: 48px; margin-bottom: 12px; }
  #locked { padding: clamp(16px, 5vw, 25px); }
  #keypad { grid-template-columns: repeat(3, minmax(0, 62px)); gap: 9px clamp(12px, 5vw, 22px); }
}

@media (prefers-reduced-motion: reduce) {
  main:has(#vault[hidden])::before, .cipher span, #keypad { animation: none; }
  .access-sequence::after, .access-stream span, #vault:not([hidden]) { animation: none; }
  #locked, #keypad button { transform: none; transition: none; }
}

html[data-embedded-wallet], html[data-embedded-wallet] body { background: transparent; }
html[data-embedded-wallet] body { min-height: 0; }
html[data-embedded-wallet] .shell { width: 100%; }
html[data-embedded-wallet] main { padding-block: 12px 6px; }
html[data-embedded-wallet] main:has(#vault[hidden]) { min-height: 0; }
html[data-embedded-wallet] .topbar { min-height: 0; }

@media (max-width: 600px) {
  .shell { width: min(100% - max(14px, env(safe-area-inset-left)) - max(14px, env(safe-area-inset-right)), 920px); }
  input { min-width: 0; max-width: 100%; font-size: 16px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .panel, article { min-width: 0; overflow-wrap: anywhere; }
  .row > *, #unlockFields { min-width: 0; }
  #keypad { grid-template-columns: repeat(3, minmax(0, 58px)); gap: 8px clamp(7px, 4vw, 18px); }
  html[data-embedded-wallet] .shell { width: 100%; }
}
