:root {
  --bg: #0F172A;
  --text: #F8FAFC;
  --text-secondary: #CBD5E1;
  --accent-strong: #A5B4FC;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  background:
    radial-gradient(90vw 60vh at 12% 0%, rgba(49, 61, 110, 0.35) 0%, transparent 55%),
    radial-gradient(70vw 50vh at 100% 20%, rgba(30, 58, 80, 0.28) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Noto Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.senior-screen,
.senior-app {
  min-height: 100dvh;
  height: 100dvh;
}

.senior-app {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 4rem);
  padding:
    max(clamp(1.5rem, 4vh, 3.5rem), var(--safe-top))
    max(clamp(1.5rem, 4vw, 4rem), var(--safe-right))
    max(clamp(1.5rem, 4vh, 3.5rem), var(--safe-bottom))
    max(clamp(1.5rem, 4vw, 4rem), var(--safe-left));
  align-items: center;
  position: relative;
}

.reminder-banner {
  position: absolute;
  top: max(0.75rem, var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  max-width: min(92vw, 36rem);
  padding: 0.85rem 1.25rem;
  border-radius: 999px;
  background: rgba(165, 180, 252, 0.18);
  border: 1px solid rgba(165, 180, 252, 0.35);
  backdrop-filter: blur(8px);
  text-align: center;
  animation: reminder-in 0.35s ease-out;
}

.reminder-banner-text {
  margin: 0;
  font-size: clamp(1.05rem, 2.8vw, 1.35rem);
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}

@keyframes reminder-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.vision-badge {
  position: absolute;
  top: max(0.75rem, var(--safe-top));
  right: max(1rem, var(--safe-right));
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(74, 222, 128, 0.4);
  color: var(--text);
  font-size: clamp(0.95rem, 2.4vw, 1.15rem);
  font-weight: 600;
}

.vision-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #4ADE80;
  box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.55);
  animation: vision-pulse 1.6s ease-out infinite;
}

@keyframes vision-pulse {
  0% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
  70% { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}

.vision-preview {
  position: absolute;
  bottom: max(1rem, var(--safe-bottom));
  right: max(1rem, var(--safe-right));
  z-index: 5;
  width: min(28vw, 160px);
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 1rem;
  border: 1px solid rgba(248, 250, 252, 0.2);
  opacity: 0.88;
  transform: scaleX(-1);
  background: #000;
}

.orientation-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(1rem, 2.5vh, 2rem);
  min-width: 0;
}

.current-time {
  display: block;
  margin: 0;
  font-size: clamp(5rem, 15vw, 10rem);
  font-weight: 650;
  letter-spacing: -0.05em;
  line-height: 0.9;
}

.current-weekday {
  margin: clamp(0.9rem, 2vh, 1.4rem) 0 0;
  font-size: clamp(2.6rem, 5.8vw, 4.25rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.current-date {
  margin: 0.4rem 0 0;
  font-size: clamp(2.1rem, 4.6vw, 3.4rem);
  font-weight: 550;
  color: var(--text-secondary);
}

.day-period,
.location-label,
.weather-label {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0;
  font-size: clamp(1.9rem, 3.8vw, 2.9rem);
  font-weight: 550;
  color: var(--text-secondary);
  line-height: 1.2;
}

.day-period {
  margin-top: clamp(1rem, 2.2vh, 1.75rem);
  color: var(--accent-strong);
}

.place-weather {
  display: grid;
  gap: 0.75rem;
  margin-top: clamp(0.6rem, 1.5vh, 1.1rem);
}

.ambient-icon {
  width: clamp(2.2rem, 3.6vw, 3.1rem);
  height: clamp(2.2rem, 3.6vw, 3.1rem);
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--accent-strong);
}

.ambient-icon svg {
  width: 100%;
  height: 100%;
}

.weather-sep { opacity: 0.5; }

.orb-caption {
  display: none;
}

.presence-title,
.presence-hint,
.presence-copy {
  display: none;
}

.presence-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0;
  min-width: 0;
}

.voice-orb {
  position: relative;
  width: clamp(240px, 38vmin, 320px);
  height: clamp(240px, 38vmin, 320px);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  margin: 0;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  touch-action: manipulation;
}

.voice-orb::after {
  content: none;
}

.voice-orb:focus-visible {
  box-shadow: 0 0 0 5px rgba(165, 180, 252, 0.55);
}

.orb-ring,
.orb-ring-2 {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid rgba(165, 180, 252, 0.55);
  pointer-events: none;
}

.orb-ring-2 {
  inset: -16px;
  border-width: 2px;
  border-color: rgba(129, 140, 248, 0.3);
  animation: ringBreath 2.4s ease-in-out infinite;
}

.orb-core {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #C7D2FE 0%, #818CF8 40%, #4F46E5 100%);
  box-shadow:
    0 0 0 12px rgba(129, 140, 248, 0.24),
    0 0 48px rgba(99, 102, 241, 0.65),
    0 24px 60px rgba(67, 56, 202, 0.55),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: background 220ms ease, transform 180ms ease, box-shadow 220ms ease;
}

.orb-mic {
  width: 44%;
  height: 44%;
  color: #F8FAFC;
  z-index: 2;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}

.orb-wave {
  display: none;
  align-items: end;
  gap: 0.3rem;
  height: 36%;
  z-index: 2;
}

.orb-wave i {
  display: block;
  width: 0.38rem;
  border-radius: 999px;
  background: #F8FAFC;
  height: 35%;
  animation: wave 1.1s ease-in-out infinite;
}

.orb-wave i:nth-child(2) { animation-delay: 0.1s; height: 55%; }
.orb-wave i:nth-child(3) { animation-delay: 0.2s; height: 80%; }
.orb-wave i:nth-child(4) { animation-delay: 0.15s; height: 50%; }
.orb-wave i:nth-child(5) { animation-delay: 0.05s; height: 40%; }

.orb-caption {
  margin: 1.7rem 0 0;
  font-size: clamp(1.7rem, 3.2vw, 2.35rem);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.voice-orb[data-state="idle"] .orb-core,
.voice-orb[data-state="idle"] .orb-ring {
  animation: idlePulse 2.3s ease-in-out infinite;
}

.voice-orb[data-state="connecting"] .orb-core {
  background: linear-gradient(160deg, #FDE68A, #F59E0B);
  animation: connectSpin 1.4s linear infinite;
}

.voice-orb[data-state="listening"] .orb-core {
  background: linear-gradient(160deg, #6EE7B7, #059669);
  box-shadow:
    0 0 0 14px rgba(52, 211, 153, 0.22),
    0 0 48px rgba(16, 185, 129, 0.45),
    0 22px 55px rgba(5, 150, 105, 0.4);
  animation: listenPulse 1.8s ease-in-out infinite;
}

.voice-orb[data-state="speaking"] .orb-mic { display: none; }
.voice-orb[data-state="speaking"] .orb-wave { display: flex; }
.voice-orb[data-state="speaking"] .orb-core {
  background: linear-gradient(160deg, #C7D2FE, #6366F1);
}

.voice-orb[data-state="error"] .orb-core,
.voice-orb[data-state="offline"] .orb-core,
.voice-orb[data-state="mic_blocked"] .orb-core {
  background: linear-gradient(160deg, #FCA5A5, #DC2626);
  animation: none;
}

.voice-orb:active .orb-core { transform: scale(0.96); }

@keyframes idlePulse {
  0%, 100% {
    box-shadow:
      0 0 0 12px rgba(129, 140, 248, 0.24),
      0 0 40px rgba(99, 102, 241, 0.55),
      0 24px 60px rgba(67, 56, 202, 0.5);
    transform: scale(1);
  }
  50% {
    box-shadow:
      0 0 0 24px rgba(129, 140, 248, 0.34),
      0 0 70px rgba(99, 102, 241, 0.75),
      0 30px 75px rgba(67, 56, 202, 0.65);
    transform: scale(1.04);
  }
}

@keyframes ringBreath {
  0%, 100% { transform: scale(1); opacity: 0.65; }
  50% { transform: scale(1.07); opacity: 1; }
}

@keyframes listenPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

@keyframes connectSpin {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.18); }
}

@keyframes wave {
  0%, 100% { transform: scaleY(0.55); opacity: 0.7; }
  50% { transform: scaleY(1); opacity: 1; }
}

.empty-senior {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 2rem;
  gap: 0.75rem;
}

.empty-senior h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
}

.empty-senior p {
  margin: 0;
  color: var(--text-secondary);
  font-size: clamp(1.15rem, 2.4vw, 1.45rem);
  max-width: 28rem;
}

@media (max-width: 1023px), (orientation: portrait) {
  .senior-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow: hidden;
  }

  .orientation-panel {
    align-items: center;
    text-align: center;
    gap: clamp(0.55rem, 1.4vh, 1rem);
  }

  .day-period,
  .location-label,
  .weather-label {
    justify-content: center;
  }

  .current-time {
    font-size: clamp(4rem, 17vw, 7rem);
  }

  .presence-panel {
    justify-content: center;
    padding-bottom: clamp(0.75rem, 2vh, 1.5rem);
  }
}

@media (max-width: 767px) {
  .senior-app {
    gap: 0.85rem;
    padding:
      max(1rem, var(--safe-top))
      max(1rem, var(--safe-right))
      max(1.2rem, var(--safe-bottom))
      max(1rem, var(--safe-left));
  }

  .current-weekday {
    font-size: clamp(2.1rem, 8.5vw, 2.9rem);
  }

  .current-date,
  .day-period,
  .location-label,
  .weather-label {
    font-size: clamp(1.6rem, 6.2vw, 2.05rem);
  }

  .orb-caption {
    display: none;
  }

  .voice-orb {
    width: clamp(240px, 58vw, 300px);
    height: clamp(240px, 58vw, 300px);
  }
}

@media (min-width: 1440px) {
  .senior-app {
    padding-inline: clamp(4rem, 8vw, 8rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .voice-orb[data-state],
  .orb-core,
  .orb-ring,
  .orb-ring-2,
  .orb-wave i {
    animation: none !important;
  }
}

.pin-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) 1.25rem calc(1.5rem + var(--safe-bottom));
  background:
    radial-gradient(80vw 50vh at 50% 0%, rgba(49, 61, 110, 0.4) 0%, transparent 60%),
    var(--bg);
}

.pin-gate[hidden] {
  display: none !important;
}

.pin-pad[hidden],
.pin-dots[hidden],
.pin-dash-link[hidden] {
  display: none !important;
}

.pin-gate-card {
  width: min(420px, 100%);
  text-align: center;
}

.pin-gate-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.4rem);
  font-weight: 650;
  letter-spacing: -0.02em;
}

.pin-gate-message {
  margin: 0.65rem 0 0;
  color: var(--text-secondary);
  font-size: clamp(1.05rem, 2.8vw, 1.2rem);
  line-height: 1.35;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 0.65rem;
  margin: 1.75rem 0 1.25rem;
  min-height: 1.1rem;
}

.pin-dot {
  width: 0.95rem;
  height: 0.95rem;
  border-radius: 50%;
  border: 2px solid rgba(248, 250, 252, 0.35);
  background: transparent;
}

.pin-dot.is-filled {
  background: #F8FAFC;
  border-color: #F8FAFC;
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  max-width: 320px;
  margin: 0 auto;
}

.pin-key {
  appearance: none;
  border: 0;
  border-radius: 999px;
  aspect-ratio: 1;
  font-size: clamp(1.5rem, 4.5vw, 1.85rem);
  font-weight: 600;
  color: var(--text);
  background: rgba(248, 250, 252, 0.08);
  cursor: pointer;
  min-height: 4.2rem;
}

.pin-key:active {
  background: rgba(248, 250, 252, 0.18);
}

.pin-key-ok {
  background: rgba(165, 180, 252, 0.28);
  font-size: clamp(1.1rem, 3.5vw, 1.35rem);
}

.pin-key-back {
  font-size: clamp(1.25rem, 4vw, 1.55rem);
}

.pin-error {
  min-height: 1.4rem;
  margin: 1rem 0 0;
  color: #FCA5A5;
  font-size: 1rem;
}

.pin-dash-link {
  display: inline-block;
  margin-top: 1.25rem;
  color: var(--accent-strong);
  font-size: 1.1rem;
  text-decoration: none;
}

.pin-dash-link:hover {
  text-decoration: underline;
}
