:root {
  color-scheme: dark;
  --grid-gap-x: 22px;
  --grid-gap-y: 26px;
  --icon-size: 64px;
  --icon-radius: 18px;
  /* keep in sync with SLIDE_MS in app.js */
  --splash-exit-ms: .7s;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", sans-serif;
  background: #0b0b12;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Splash Screen ---------------- */

#splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateY(0);
  transition: transform var(--splash-exit-ms, .7s) cubic-bezier(.4, 0, .2, 1);
  will-change: transform;
}

#splash.hide {
  transform: translateY(-100%);
  pointer-events: none;
}

.splash-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, #3a2a6d, #0b0b12 55%),
              linear-gradient(160deg, #1c1440, #0b0b12 70%);
  background-size: 200% 200%;
  animation: splashDrift 6s ease-in-out infinite alternate;
}

@keyframes splashDrift {
  from { background-position: 0% 0%, 0% 0%; }
  to   { background-position: 60% 40%, 30% 30%; }
}

.splash-content {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.splash-logo {
  width: min(62vw, 420px);
  height: auto;
  opacity: 0;
  transform: scale(.72);
  filter: drop-shadow(0 0 28px rgba(140, 120, 255, 0.35));
  animation: logoIn 1.1s cubic-bezier(.2, 1.4, .4, 1) forwards .15s;
}

@keyframes logoIn {
  0%   { opacity: 0; transform: scale(.72) translateY(8px); }
  60%  { opacity: 1; transform: scale(1.04) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.splash-ring {
  position: absolute;
  width: min(74vw, 500px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(170, 150, 255, 0.35);
  opacity: 0;
  animation: ringPulse 2.4s cubic-bezier(.2, .6, .3, 1) infinite;
}

@keyframes ringPulse {
  0%   { transform: scale(.7); opacity: 0; }
  30%  { opacity: .6; }
  100% { transform: scale(1.15); opacity: 0; }
}

/* ---------------- Home Screen ---------------- */

#home {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  overflow: hidden;
}

.wallpaper {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(140, 105, 255, 0.9), transparent 42%),
    radial-gradient(circle at 88% 18%, rgba(255, 130, 170, 0.6), transparent 38%),
    radial-gradient(circle at 45% 92%, rgba(70, 140, 255, 0.55), transparent 50%),
    linear-gradient(160deg, #221a45 0%, #140f2e 50%, #09081a 100%);
  animation: wallpaperDrift 16s ease-in-out infinite alternate;
}

@keyframes wallpaperDrift {
  from { filter: hue-rotate(0deg) brightness(1); }
  to   { filter: hue-rotate(-18deg) brightness(1.08); }
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--grid-gap-y) var(--grid-gap-x);
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 64px) 22px 60px;
}

@media (min-width: 620px) {
  .app-grid { grid-template-columns: repeat(6, 1fr); max-width: 720px; }
}

.app-icon {
  appearance: none;
  border: none;
  background: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  transform: translateY(14px);
}

/* JS adds this once the splash has fully finished sliding away — starting
   the fade-in any earlier just plays it out invisibly underneath. */
#app-grid.reveal .app-icon {
  animation: iconIn .5s cubic-bezier(.2, .8, .3, 1) forwards;
}

@keyframes iconIn {
  to { opacity: 1; transform: translateY(0); }
}

.app-icon .icon-glyph {
  width: var(--icon-size);
  height: var(--icon-size);
  border-radius: var(--icon-radius);
  object-fit: cover;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 0 0 0.5px rgba(255,255,255,0.15);
  transition: transform .15s ease, box-shadow .15s ease;
}

.app-icon:hover .icon-glyph {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.4), inset 0 0 0 0.5px rgba(255,255,255,0.2);
}

.app-icon:active .icon-glyph,
.app-icon.pressed .icon-glyph {
  transform: scale(0.88);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
}

.app-icon .icon-label {
  font-size: 12px;
  font-weight: 500;
  color: #f5f5f7;
  text-align: center;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  line-height: 1.25;
  max-width: 78px;
  word-break: keep-all;
  overflow-wrap: normal;
}

@media (prefers-reduced-motion: reduce) {
  #splash, #splash.hide, .splash-logo, .splash-ring, .wallpaper,
  .app-icon, #app-grid.reveal .app-icon {
    animation: none !important;
    transition: none !important;
  }
  #splash.hide { display: none; }
  .splash-logo { opacity: 1; transform: none; }
  .app-icon { opacity: 1; transform: none; }
}
