:root {
  --bg-0: #070a18;
  --bg-1: #0b1020;
  --card: rgba(255, 255, 255, 0.06);
  --card-hover: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef1ff;
  --text-dim: rgba(238, 241, 255, 0.55);
  --accent: #7c5cff;
  --accent-2: #30d7c1;
  --success: #22c55e;
  --error: #ef4444;
  --radius: 24px;
  --shadow: 0 14px 50px rgba(0, 0, 0, 0.40), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter",
    system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--text);
  min-height: 100svh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Animated aurora background */
.aurora {
  position: fixed;
  inset: -20% -20% auto -20%;
  height: 100svh;
  z-index: -1;
  background:
    radial-gradient(60% 50% at 20% 20%, rgba(124, 92, 255, 0.40), transparent 60%),
    radial-gradient(55% 45% at 85% 15%, rgba(48, 215, 193, 0.32), transparent 60%),
    radial-gradient(55% 45% at 60% 85%, rgba(255, 100, 180, 0.26), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 70%);
  filter: blur(44px) saturate(125%);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  50%  { transform: translate3d(-4%, 2%, 0) scale(1.04); }
  100% { transform: translate3d(3%, -2%, 0) scale(1.02); }
}

header {
  max-width: 480px;
  margin: 0 auto;
  padding: 28px 20px 14px;
  text-align: center;
}
h1 {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  background: linear-gradient(135deg, #ffffff 0%, #b3a8ff 55%, #64f3dc 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.subtitle {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: lowercase;
}

/* 2 columns × 3 rows, as large as possible on a 412×915 portrait */
.grid {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  /* three equal rows that consume the remaining viewport */
  grid-auto-rows: 1fr;
  height: calc(100svh - 105px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 520px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  backdrop-filter: blur(28px) saturate(140%);
  -webkit-backdrop-filter: blur(28px) saturate(140%);
  box-shadow: var(--shadow);
  transition:
    transform 160ms cubic-bezier(0.2, 0.8, 0.3, 1),
    background 220ms ease,
    border-color 220ms ease,
    box-shadow 320ms ease;
  overflow: hidden;
  isolation: isolate;
  -webkit-tap-highlight-color: transparent;
}
.tile::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    130% 90% at var(--mx, 50%) var(--my, 50%),
    rgba(124, 92, 255, 0.32),
    transparent 60%
  );
  opacity: 0;
  transition: opacity 260ms ease;
  pointer-events: none;
  z-index: -1;
}
.tile::after {
  /* top sheen */
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 40%;
  background: linear-gradient(180deg, rgba(255,255,255,0.10), rgba(255,255,255,0));
  pointer-events: none;
  opacity: 0.6;
}
.tile:hover { background: var(--card-hover); border-color: rgba(255,255,255,0.15); }
.tile:hover::before { opacity: 1; }
.tile:active { transform: scale(0.97); }

.tile .icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(124,92,255,0.42), rgba(48,215,193,0.32));
  border: 1px solid rgba(255,255,255,0.14);
  font-size: 34px;
  line-height: 1;
  transition: transform 320ms cubic-bezier(0.2, 0.8, 0.3, 1);
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.25), 0 1px 0 rgba(255,255,255,0.15) inset;
}
.tile .label {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  line-height: 1.15;
  color: var(--text);
}

.tile .check {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 62px;
  height: 62px;
  stroke: #ffffff;
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  filter: drop-shadow(0 6px 18px rgba(34, 197, 94, 0.45));
}
.tile .check circle { stroke-dasharray: 151; stroke-dashoffset: 151; }
.tile .check path   { stroke-dasharray: 60;  stroke-dashoffset: 60; }

/* Ripple from tap point */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: radial-gradient(circle, rgba(255,255,255,0.50), rgba(255,255,255,0) 60%);
  pointer-events: none;
  mix-blend-mode: overlay;
  animation: ripple 720ms ease-out forwards;
}
@keyframes ripple {
  to { transform: translate(-50%, -50%) scale(6); opacity: 0; }
}

/* Loading state */
.tile.loading .icon { animation: pulse 900ms ease-in-out infinite; }
.tile.loading::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), var(--accent-2), transparent);
  background-size: 200% 100%;
  animation: slide 1.1s linear infinite;
  opacity: 1;
}
@keyframes slide { to { background-position: -200% 0; } }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.10); }
}

/* Success state */
.tile.success {
  border-color: rgba(34, 197, 94, 0.65);
  background: linear-gradient(135deg, rgba(34,197,94,0.22), rgba(48,215,193,0.18));
  animation: pop 520ms cubic-bezier(0.2, 0.8, 0.3, 1);
}
.tile.success .icon,
.tile.success .label { opacity: 0; transition: opacity 200ms ease; }
.tile.success .check { opacity: 1; transform: scale(1); transition: transform 420ms cubic-bezier(0.2, 0.8, 0.3, 1); }
.tile.success .check circle { animation: drawCircle 520ms ease forwards; }
.tile.success .check path   { animation: drawCheck 360ms 260ms ease forwards; }

@keyframes drawCircle { to { stroke-dashoffset: 0; } }
@keyframes drawCheck  { to { stroke-dashoffset: 0; } }

@keyframes pop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}

/* Error state */
.tile.error {
  border-color: rgba(239, 68, 68, 0.65);
  background: rgba(239, 68, 68, 0.12);
  animation: shake 460ms ease-in-out;
}
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 40px);
  padding: 12px 18px;
  border-radius: 14px;
  background: rgba(10, 12, 24, 0.85);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease, transform 260ms cubic-bezier(0.2, 0.8, 0.3, 1);
  max-width: calc(100vw - 32px);
  text-align: center;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok   { border-color: rgba(34, 197, 94, 0.55); }
.toast.err  { border-color: rgba(239, 68, 68, 0.55); }

/* Entrance stagger */
.tile {
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  animation: rise 620ms cubic-bezier(0.2, 0.8, 0.3, 1) forwards;
}
@keyframes rise {
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .aurora, .tile, .tile *, .toast, .ripple { animation: none !important; transition: none !important; }
}
