/* ============================================================
   LAYOUT - Core layout, phone frame, responsive behavior
   ============================================================ */

[hidden] { display: none !important; }

html { height: 100%; box-sizing: border-box; }
*, *::before, *::after { box-sizing: border-box; }

body {
  height: 100%;
  margin: 0;
  background: radial-gradient(120% 90% at 50% 0%, var(--stage-2), var(--stage));
  color: var(--label);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 8px;
}

a { color: inherit; text-decoration: none; }
svg { display: block; }

/* Stage - centers the phone on desktop, full screen on mobile */
.stage {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#fit {
  position: relative;
  width: 393px;
  height: 852px;
}

.phone {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 55px;
  overflow: hidden;
  background: #000;
  transform-origin: 0 0;
  box-shadow:
    0 0 0 10px var(--bezel),
    0 0 0 12px #4a4a50,
    0 40px 90px rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
  color: #fff;
  isolation: isolate;
  clip-path: inset(0 round 55px);
}

/* Responsive phone scaling - fit within viewport preserving aspect ratio */
@media (min-width: 521px) {
  #fit {
    /* Fixed design size; scale to fit viewport */
    width: 393px;
    height: 852px;
    transform: scale(min(calc(100vw / 393px), calc((100vh - 40px) / 852px)));
    transform-origin: center;
  }
}

/* Mobile: full screen, no bezel */
@media (max-width: 520px) {
  .stage { display: block; }
  #fit { width: 100% !important; height: 100% !important; }
  .phone {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    transform: none !important;
    clip-path: none;
  }
  .island { display: none; }
}

/* Layers */
.layer { position: absolute; inset: 0; }

/* Wallpaper */
.wall {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(60% 40% at 78% 14%, rgba(255, 214, 140, 0.55), transparent 70%),
    radial-gradient(70% 50% at 12% 46%, rgba(110, 96, 230, 0.55), transparent 70%),
    radial-gradient(90% 60% at 60% 105%, rgba(255, 120, 160, 0.45), transparent 70%),
    linear-gradient(180deg, #0e1433 0%, #1f2560 45%, #4b3478 78%, #2a1a44 100%);
  background-size: cover;
  background-position: center;
  transition: filter 0.4s, transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}

/* During lock screen, hide the gradient layer so it never flashes through */
.phone[data-ctx="lock"] .wall {
  background: #0e1433; /* dark neutral matching wallpaper base */
}

.wall-photo {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 0.45s, filter 0.4s, transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}

.wall-photo::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.42) 0%,
    rgba(0, 0, 0, 0.12) 28%,
    rgba(0, 0, 0, 0) 45%,
    rgba(0, 0, 0, 0) 58%,
    rgba(0, 0, 0, 0.45) 100%
  );
}

/* Home‑screen wallpaper layer */
.wall-photo-home {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-image: url('../assets/images/main_wallpaper.jpg');
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.45s, filter 0.4s, transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}

/* Show the home‑screen wallpaper in home and app contexts */
.phone[data-ctx="home"] .wall-photo-home,
.phone[data-ctx="app"] .wall-photo-home {
  opacity: 1;
}

/* Initial lock‑screen fallback wallpaper – visible before JS runs */
.wall-lock-default {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  background-image: url('../assets/images/default-lockscreen.jpg');
  background-color: #0e1433;
  opacity: 1;
  pointer-events: none;
  transition: opacity 0s, filter 0.4s, transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}

/* Matching dark gradient overlay so swapping layers causes no brightness jump */
.wall-lock-default::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(0, 0, 0, 0.42) 0%,
    rgba(0, 0, 0, 0.12) 28%,
    rgba(0, 0, 0, 0) 45%,
    rgba(0, 0, 0, 0) 58%,
    rgba(0, 0, 0, 0.45) 100%
  );
}

/* Disable wallpaper transition on initial load for instant paint */
.wall-photo.no-anim {
  transition: none !important;
}

/* Hide the fallback once the real wallpaper is ready */
.phone.lock-default-hidden .wall-lock-default {
  opacity: 0;
}

.phone[data-ctx="lock"] .wall-photo.has,
.phone[data-ctx="pass"] .wall-photo.has,
.phone[data-ctx="hello"] .wall-photo.has { opacity: 1; }

.phone[data-lighthome="1"][data-ctx="home"] .status { color: #1d1d1f; }
.phone[data-lighthome="1"][data-ctx="home"] .homebar i { background: #1d1d1f; }
.phone[data-lighthome="1"] .ico-label,
.phone[data-lighthome="1"] .w-label { color: #1d1d1f; text-shadow: 0 0 6px rgba(255, 255, 255, 0.7); }
.phone[data-lighthome="1"] .spot { background: rgba(0, 0, 0, 0.12); color: #1d1d1f; }
.phone[data-lighthome="1"] .dock { background: rgba(255, 255, 255, 0.35); }

.phone[data-ctx="pass"] .wall { filter: blur(24px) brightness(0.62); transform: scale(1.08); }
.phone[data-ctx="pass"] .wall-photo { filter: blur(24px) brightness(0.62); transform: scale(1.08); }
.phone[data-ctx="home"] .wall { filter: brightness(0.92); }

/* Lock Screen Container - fills phone height, flex column for proper anchoring */
#lock {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  padding: 62px 24px 20px;
  z-index: 10;
  transition: transform 0.45s cubic-bezier(0.3, 0.8, 0.3, 1), opacity 0.35s;
}

/* Lock screen slide-away state (when passcode is shown) */
#lock.away {
  transform: translateY(-100%);
  opacity: 0;
}

/* Hide lock screen in home and app contexts */
.phone[data-ctx="home"] #lock,
.phone[data-ctx="app"] #lock {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Lock content container - drag-follow surface for the swipe-up gesture */
#lkc {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  align-items: center;
  transform-origin: top;
  transition: transform 380ms cubic-bezier(0.3, 0.7, 0.2, 1), opacity 380ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* Bottom controls on lock screen: side‑by‑side */
.lock-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 340px;
  margin-top: auto;
  margin-bottom: 24px;
  padding: 0 8px;
}
.lock-bottom .round { flex: 0 0 auto; }
.lock-bottom .round:first-child { margin-left: 11px; }
.lock-bottom .round:last-child { margin-right: 15px; }

/* Lock‑screen clock & date typography */
.phone[data-ctx="lock"] #lockDate,
.phone[data-ctx="pass"] #lockDate {
  font-size: 21px;
  font-weight: 600;
  line-height: normal;
  margin-bottom: 4px;
  color: #fff;
}
.phone[data-ctx="lock"] #lockTime,
.phone[data-ctx="pass"] #lockTime {
  font-size: 96px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -2.88px;
  color: #fff;
}

/* Status Bar */
.status {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 30px 0 46px;
  z-index: 80;
  font-weight: 600;
  font-size: 16.5px;
  letter-spacing: -0.01em;
  pointer-events: none;
  transition: color 0.25s;
  font-variant-numeric: tabular-nums;
}

.status .right { display: flex; gap: 6px; align-items: center; }

.phone[data-ctx="app"] .status { color: var(--label); }
.phone[data-ctx="app"][data-dark="1"] .status,
.phone[data-incall="1"] .status { color: #fff; }

.phone[data-ctx="lock"] .status .st-time,
.phone[data-ctx="pass"] .status .st-time { opacity: 0; }

.batt { display: flex; align-items: center; gap: 1px; }
.batt i {
  display: block;
  width: 25px;
  height: 12px;
  border: 1.2px solid currentColor;
  border-radius: 4px;
  opacity: 0.95;
  padding: 1.5px;
  position: relative;
}
.batt i::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--lvl, 20%);
  background: currentColor;
  border-radius: 1.5px;
}
.batt b { width: 1.6px; height: 4px; background: currentColor; border-radius: 0 1px 1px 0; opacity: 0.5; }

/* Dynamic Island */
.island {
  position: absolute;
  top: 11px;
  left: 50%;
  width: 124px;
  height: 36px;
  margin-left: -62px;
  background: #000;
  border-radius: 20px;
  z-index: 99;
  pointer-events: none;
}

/* Home Bar */
.homebar {
  position: absolute;
  bottom: 0;
  left: 26px;
  right: 26px;
  height: 30px;
  z-index: 85;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  touch-action: none;
  cursor: grab;
  -webkit-tap-highlight-color: transparent;
}

.homebar:active { cursor: grabbing; }
.homebar i {
  width: 136px;
  height: 5px;
  border-radius: 3px;
  background: #fff;
  opacity: 0.9;
  transition: background 0.25s, transform 0.2s, width 0.2s;
}
.homebar:hover i { width: 150px; }
.phone.sw-armed .homebar i { transform: scaleX(0.75); }

.phone[data-ctx="app"] .homebar i { background: var(--label); }
.phone[data-ctx="app"][data-dark="1"] .homebar i,
.phone[data-incall="1"] .homebar i { background: #fff; }

/* Back to App Button */
#backApp {
  position: absolute;
  top: 15px;
  left: 18px;
  z-index: 91;
  display: none;
  align-items: center;
  gap: 4px;
  height: 26px;
  padding: 0 8px;
  border-radius: 13px;
  font-size: 14px;
  font-weight: 600;
  color: #007aff;
  letter-spacing: -0.01em;
  max-width: 130px;
  overflow: hidden;
  white-space: nowrap;
}
#backApp svg { flex: none; width: 8px; height: 13px; }
#backApp span { overflow: hidden; text-overflow: ellipsis; }
.phone[data-ctx="app"][data-back="1"] #backApp { display: flex; }
.phone[data-ctx="app"][data-back="1"] .status .st-time { opacity: 0; }
.phone[data-dark="1"] #backApp { color: #5aa9ff; }

/* App Switcher */
#switcher {
  z-index: 84;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: rgba(12, 12, 18, 0.4);
  backdrop-filter: blur(26px) saturate(140%);
  -webkit-backdrop-filter: blur(26px) saturate(140%);
  opacity: 0;
  transition: opacity 0.22s;
}
#switcher.on { opacity: 1; }

.sw-track {
  display: flex;
  align-items: center;
  gap: 22px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  padding: 20px calc(50% - var(--cw) / 2) 30px;
  scrollbar-width: none;
  transform: scale(1.06);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.25, 1);
}
#switcher.on .sw-track { transform: none; }
.sw-track::-webkit-scrollbar { display: none; }

.sw-card {
  flex: none;
  scroll-snap-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.25, 1), opacity 0.25s;
}

.sw-lab {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  padding-left: 6px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}
.sw-lab .ico { width: 28px; height: 28px; border-radius: 7px; box-shadow: none; }
.sw-lab .ico svg { width: 18px; height: 18px; }
.sw-lab .cal-ico em { font-size: 6px; }
.sw-lab .cal-ico b { font-size: 14px; line-height: 1; }

.sw-frame {
  position: relative;
  width: var(--cw);
  height: var(--ch);
  border-radius: 30px;
  overflow: hidden;
  background: var(--bg);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  touch-action: pan-x;
}

.sw-shot {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  pointer-events: none;
}

.snap { position: absolute; inset: 0; overflow: hidden; background: var(--bg); color: var(--label); }
.snap, .snap * { animation: none !important; transition: none !important; pointer-events: none !important; }

.sw-blank { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; }
.sw-blank svg { width: 64px; height: 64px; }
.sw-empty { text-align: center; color: #fff; font-size: 17px; font-weight: 600; opacity: 0.85; }
.sw-empty:empty, .sw-hint:empty { display: none; }
.sw-hint { position: absolute; left: 16px; right: 16px; bottom: 46px; text-align: center; color: rgba(255, 255, 255, 0.8); font-size: 13px; }

#apps.from-card { animation: appCard 0.42s cubic-bezier(0.2, 0.9, 0.25, 1) both; }
@keyframes appCard { from { transform: scale(var(--s0)); border-radius: calc(30px / var(--s0)); } to { transform: none; border-radius: 0; } }

/* Navigation Tip */
#navTip {
  position: absolute;
  left: 50%;
  bottom: 122px;
  transform: translate(-50%, 10px);
  z-index: 86;
  width: max-content;
  max-width: 300px;
  padding: 9px 14px;
  border-radius: 16px;
  background: rgba(30, 30, 34, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.35s cubic-bezier(0.2, 0.9, 0.25, 1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
#navTip.on { opacity: 1; transform: translate(-50%, 0); }

/* Toast */
.toast {
  position: absolute;
  top: 62px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: max-content;
  padding: 10px 12px;
  border-radius: 20px;
  background: rgba(30, 30, 34, 0.88);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  transition: opacity 0.25s, transform 0.35s cubic-bezier(0.2, 0.9, 0.25, 1);
  z-index: 96;
  pointer-events: none;
  white-space: nowrap;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Notification Center */
#nc {
  position: absolute;
  inset: 0;
  z-index: 97;
  display: flex;
  flex-direction: column;
  padding: 64px 10px 20px;
  background: rgba(10, 10, 14, 0.55);
  backdrop-filter: blur(34px) saturate(160%);
  -webkit-backdrop-filter: blur(34px) saturate(160%);
  color: #fff;
  transform: translateY(-100%);
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.25, 1);
  touch-action: none;
}
#nc.on { transform: translateY(0); }
#nc.drag { transition: none; }

.nc-head { display: flex; justify-content: space-between; align-items: center; padding: 0 16px 16px; }
.nc-date { font-size: 15px; font-weight: 600; }
.nc-time { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.nc-close { width: 30px; height: 30px; border-radius: 50%; background: var(--fill); color: var(--label2); display: grid; place-items: center; }
.nc-list { flex: 1; overflow-y: auto; padding: 0 10px; scrollbar-width: none; }
.nc-list::-webkit-scrollbar { display: none; }
.nc-empty { text-align: center; color: var(--label2); padding: 40px 0; font-size: 15px; }

/* Banner */
#banner {
  position: absolute;
  top: 10px;
  left: 8px;
  right: 8px;
  z-index: 95;
  touch-action: none;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  padding: 12px 14px;
  border-radius: 24px;
  background: rgba(30, 30, 34, 0.8);
  color: #fff;
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  transform: translateY(-140%);
  transition: transform 0.5s cubic-bezier(0.2, 0.9, 0.25, 1);
}
#banner.on { transform: translateY(42px); }
#banner.drag { transition: none; }

/* Banner inner content (iOS-style) */
#banner .kn-banner-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
#banner .kn-banner-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
#banner .kn-banner-title {
  font-size: 16px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#banner .kn-banner-time {
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
  flex-shrink: 0;
}
#banner .kn-banner-body {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.35;
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Pull Zone */
#pullZone {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 46px;
  z-index: 90;
  touch-action: none;
}
.phone[data-ctx="lock"] #pullZone,
.phone[data-ctx="pass"] #pullZone,
.phone[data-ctx="hello"] #pullZone { display: none; }

/* Glow for flashlight */
.flash-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(60% 40% at 50% 0%, rgba(255, 255, 240, 0.35), rgba(0, 0, 0, 0) 70%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.flash-glow.on { opacity: 1; }

/* Face ID */
.faceid {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.25);
  animation: bubIn 0.2s both;
}
.faceid div {
  width: 150px;
  height: 150px;
  border-radius: 30px;
  background: var(--bar);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 15px;
  color: var(--label);
}
.faceid svg { width: 60px; height: 60px; color: var(--label); }
.faceid.ok svg { color: var(--green); }

/* Animations */
@keyframes bubIn { from { transform: translateY(10px) scale(0.96); opacity: 0; } }
@keyframes notifIn { from { transform: translateY(-14px) scale(0.96); opacity: 0; } }
@keyframes hint { 50% { transform: translateY(-4px); opacity: 0.55; } }
@keyframes shake { 20% { transform: translateX(-14px); } 40% { transform: translateX(12px); } 60% { transform: translateX(-8px); } 80% { transform: translateX(5px); } }
@keyframes pop { 40% { transform: scale(1.25); } }
@keyframes burst { 0% { transform: scale(0); opacity: 0; } 15% { transform: scale(1.2); opacity: 1; } 30% { transform: scale(0.95); } 70% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.1) translateY(-20px); } }
@keyframes mePulse { 0% { r: 9; opacity: 0.5; } 100% { r: 30; opacity: 0; } }
@keyframes eq { 0%, 100% { height: 30%; } 50% { height: 100%; } }
@keyframes ringPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.6); } 60% { box-shadow: 0 0 0 16px rgba(52, 199, 89, 0); } }
@keyframes tlIn { from { opacity: 0; transform: translateY(8px); } }
@keyframes typ { 0%, 60%, 100% { opacity: 0.35; transform: none; } 30% { opacity: 1; transform: translateY(-2px); } }
@keyframes blink { 50% { opacity: 0; } }

/* Respect prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .lock-bottom .swipe-hint { animation: none !important; opacity: 0.8; }
}

/* Cracked screen overlay: sits above every screen, never blocks taps.
   Hide it later (story "phone fixed" moment) with: .phone[data-cracked="0"] #crack { display: none; } */
#crack {
  position: absolute;
  inset: 0;
  z-index: 1000;
  opacity: 0.7; /* lower for fainter cracks, raise (max 1) for stronger */
  pointer-events: none;
  background: url("../assets/images/broken-screen.svg") center / 100% 100% no-repeat;
}
.phone[data-cracked="0"] #crack { display: none; }