:root { 
      --app-size:64px; 
      --fg:white;
      --blur-heavy: saturate(180%) blur(20px);
      --blur-light: saturate(150%) blur(12px);
      --glass-bg: rgba(30, 30, 46, 0.72);
      --glass-border: rgba(255, 255, 255, 0.08);
      --glass-highlight: rgba(255, 255, 255, 0.04);
      --parallax-factor: 0.15;
    }
    * { box-sizing:border-box; margin:0; padding:0; }
    html { height: 100%; width: 100%; overflow: hidden; }
    
    body {
      height:100dvh; width:100%; max-width:100%; overflow:hidden;
      font-family:-apple-system,BlinkMacSystemFont,"SF Pro Display","SF Pro Text",sans-serif;
      background:#050914;
      color:var(--fg);
      display:flex; flex-direction:column;
      padding-top:0;
      overscroll-behavior: none;
    }

    /* 🎨 BACKGROUND RULE (LOGIN + DESKTOP SPEC)
       - Always preserve verticality: image height fits 100% of viewport
       - Anchor is BOTTOM-LEFT (stable across resize/rotation)
       - Never deform; only crop the RIGHT side (overflow hidden)
       - Desktop-only: JS may translateX to reveal the rest of the image (no CSS transition) */
    .parallax-bg {
      position: fixed;
      inset: 0;
      z-index: -1;
      overflow: hidden;
      pointer-events: none;
    }
    .parallax-bg img {
      position: absolute;
      left: 0;
      bottom: 0;
      height: 100%;
      width: auto;
      max-width: none;
      max-height: none;
      /* No transition: must be 1:1 with scroll (no lag/delay) */
      transform: translate3d(0, 0, 0);
      will-change: transform;
    }
    /* Subtle vignette overlay for depth */
    .parallax-bg::after {
      content: '';
      position: absolute;
      inset: 0;
      background: radial-gradient(ellipse at center, transparent 0%, rgba(5, 9, 20, 0.3) 100%);
      pointer-events: none;
    }
    
    body.no-bg .parallax-bg { display: none; }
    body.no-bg { background: linear-gradient(135deg, #0f0c29 0%, #1a1a2e 50%, #16213e 100%); }

    /* 🍎 iOS-STYLE STATUS BAR - Glassmorphism */
    .status-bar {
      height:calc(44px + env(safe-area-inset-top));
      display:flex; justify-content:space-between; align-items:center;
      padding:env(safe-area-inset-top) 16px 0 16px;
      font-size:12px; font-weight:600;
      background: var(--glass-bg);
      backdrop-filter: var(--blur-heavy);
      -webkit-backdrop-filter: var(--blur-heavy);
      border-bottom:1px solid var(--glass-border);
    }
    .status-left { display:flex; align-items:center; gap:10px; }
    .status-dot { 
      width:10px; height:10px; border-radius:50%; 
      background:#64748b;
      transition: all 0.3s ease;
    }
    .status-dot.ok { 
      background:#34d399; 
      box-shadow: 0 0 12px rgba(52, 211, 153, 0.6);
    }
    .status-dot.bad { background:#f87171; box-shadow: 0 0 8px rgba(248, 113, 113, 0.5); }
    .status-title { 
      text-transform:uppercase; 
      letter-spacing:0.1em; 
      opacity:0.85;
      font-weight: 500;
    }
    .status-mid { flex:1; text-align:center; opacity:0.6; font-weight: 400; }
    .status-right { opacity:0.6; font-weight: 400; display:flex; align-items:center; gap:10px; }

    /* ⚙️ CONFIG BADGE + RESET */
    .config-badge {
      font-size: 10px;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      padding: 4px 8px;
      border-radius: 999px;
      border: 1px solid rgba(255, 255, 255, 0.12);
      background: rgba(255, 255, 255, 0.06);
      color: rgba(255, 255, 255, 0.85);
      user-select: none;
      white-space: nowrap;
    }
    .config-badge.shipped {
      border-color: rgba(34, 197, 94, 0.35);
      background: rgba(34, 197, 94, 0.12);
      color: rgba(34, 197, 94, 0.95);
    }
    .config-badge.overrides {
      border-color: rgba(251, 191, 36, 0.35);
      background: rgba(251, 191, 36, 0.12);
      color: rgba(251, 191, 36, 0.95);
    }
    .config-btn {
      border: 1px solid rgba(255, 255, 255, 0.12);
      background: rgba(255, 255, 255, 0.06);
      color: rgba(255, 255, 255, 0.9);
      border-radius: 10px;
      padding: 6px 10px;
      font-size: 11px;
      cursor: pointer;
    }
    .config-btn:active { transform: scale(0.98); }

    /* 🔍 iOS-STYLE SEARCH - Frosted glass */
    .search-wrap { padding:12px 20px 0; }
    .search {
      width:100%; max-width:600px; margin:0 auto;
      display:flex; align-items:center; gap:10px;
      padding:12px 16px; border-radius:12px;
      background: rgba(120, 120, 128, 0.24);
      backdrop-filter: var(--blur-light);
      -webkit-backdrop-filter: var(--blur-light);
      border:1px solid rgba(255,255,255,0.06);
    }
    .search:focus-within {
      background: rgba(120, 120, 128, 0.32);
      border-color: rgba(255,255,255,0.12);
    }
    .search input {
      flex:1; background:transparent; border:none; outline:none;
      color:white; font-size:16px; font-weight: 400;
    }
    .search input::placeholder { color:rgba(235, 235, 245, 0.3); }

    .pages {
      flex:1; display:flex; overflow-x:auto; overflow-y:hidden;
      scroll-snap-type:x mandatory; scroll-behavior:smooth;
      -webkit-overflow-scrolling:touch;
      touch-action: pan-x pan-y;
      overscroll-behavior-x: contain;
    }
    .pages::-webkit-scrollbar { display:none; }
    .pages { scrollbar-width: none; }

    .page {
      flex:0 0 100%; scroll-snap-align:start;
      display:flex; justify-content:center; align-items:flex-start;
      height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
      overscroll-behavior-x: none;
      position: relative;
      touch-action: pan-x pan-y;
    }
    .page::-webkit-scrollbar { display:none; }
    .page { scrollbar-width: none; }
    .page-grid {
      width:100%; max-width:560px; padding:20px;
      display:grid; grid-template-columns:repeat(4,1fr);
      gap:16px; align-content:start;
    }
    @media(min-width:768px) { .page-grid { max-width:700px; gap:20px; } }

    .app {
      display:flex; flex-direction:column; align-items:center;
      text-decoration:none; color:white; cursor:pointer;
      border:none; background:none; padding:0;
      transition:transform 0.1s;
    }
    .app:active { transform:scale(0.9); }
    .app-icon {
      width:var(--app-size); height:var(--app-size);
      border-radius:14px; display:flex; align-items:center; justify-content:center;
      font-size:28px; box-shadow:0 4px 12px rgba(0,0,0,0.3);
      margin-bottom:6px; position:relative;
    }
    .app-label {
      font-size:11px; font-weight:500;
      text-shadow:0 1px 3px rgba(0,0,0,0.8);
      text-align:center; white-space:nowrap;
      overflow:hidden; text-overflow:ellipsis; width:100%;
    }

    /* 📱 REAL WIDGET SYSTEM - iPhone-style live data widgets */
    .widget-page {
      flex: 0 0 100%;
      scroll-snap-align: start;
      display: flex;
      justify-content: center;
      align-items: flex-start;
      padding: 16px;
      height: 100%;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
      overscroll-behavior-y: contain;
      overscroll-behavior-x: none;
      touch-action: pan-x pan-y;
    }
    .widget-page::-webkit-scrollbar { display:none; }
    .widget-page { scrollbar-width: none; }
    .widget-grid {
      width: 100%;
      max-width: 600px;
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 12px;
      align-content: start;
      user-select: none;
      -webkit-user-select: none;
    }

    /* 🍎 iOS-STYLE LIVE WIDGET - True glassmorphism */
    .live-widget {
      background: rgba(30, 30, 46, 0.15);
      backdrop-filter: var(--blur-heavy);
      -webkit-backdrop-filter: var(--blur-heavy);
      border-radius: 22px;
      border: 1px solid var(--glass-border);
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 8px;
      transition: background 0.3s ease,
                  transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), 
                  box-shadow 0.25s ease,
                  border-color 0.25s ease;
      cursor: default;
      min-height: 100px;
      user-select: none;
      -webkit-user-select: none;
      -webkit-touch-callout: none;
      -webkit-tap-highlight-color: transparent;
      /* Inner highlight for depth */
      box-shadow: 
        inset 0 1px 0 var(--glass-highlight),
        0 4px 24px rgba(0, 0, 0, 0.2);
    }
    .live-widget * { user-select: none; -webkit-user-select: none; }
    /* Desktop only: hover effects */
    @media (hover: hover) and (pointer: fine) {
      .live-widget:hover {
        transform: translateY(-2px);
        box-shadow: 
          inset 0 1px 0 var(--glass-highlight),
          0 12px 40px rgba(0, 0, 0, 0.35);
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(30, 30, 46, 0.85);
      }
    }
    
    /* Touch: NO transform to avoid swipe interference */
    @media (hover: none) and (pointer: coarse) {
      .live-widget:active {
        background: rgba(30, 30, 46, 0.9) !important;
        border-color: rgba(255, 255, 255, 0.2);
        /* NO transform - prevents widget moving during swipe */
      }
    }
    
    .live-widget.selected {
      background: rgba(30, 30, 46, 0.85) !important;
      border-color: rgba(255, 255, 255, 0.2);
    }
    
    .live-widget.clickable {
      cursor: pointer;
    }

    /* Widget sizes */
    .live-widget.size-small {
      grid-column: span 1;
      min-height: 90px;
    }
    .live-widget.size-medium {
      grid-column: span 1;
      min-height: 120px;
    }
    .live-widget.size-large {
      grid-column: span 2;
      min-height: 140px;
    }

    /* Modular widget iframe: each widget can be its own HTML file */
    .widget-iframe {
      width: 100%;
      height: 100%;
      border: 0;
      background: transparent;
      border-radius: 16px;
      flex: 1;
      /* Critical: don't steal swipe gestures from the OS page scroller */
      pointer-events: none;
    }

    /* Widget Header */
    .widget-header {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .widget-header-icon {
      font-size: 16px;
      opacity: 0.8;
    }
    .widget-header-title {
      font-size: 13px;
      font-weight: 600;
      color: rgba(255, 255, 255, 0.7);
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    /* Widget Body */
    .widget-body {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }

    /* Primary Value - Big number or status */
    .widget-primary {
      font-size: 32px;
      font-weight: 700;
      color: white;
      line-height: 1.1;
    }
    .widget-primary.status-up {
      color: #22c55e;
    }
    .widget-primary.status-down {
      color: #ef4444;
    }
    .widget-primary .suffix {
      font-size: 14px;
      font-weight: 500;
      opacity: 0.7;
    }

    /* Secondary Value */
    .widget-secondary {
      font-size: 13px;
      color: rgba(255, 255, 255, 0.6);
      margin-top: 4px;
    }

    /* Details Row */
    .widget-details {
      display: flex;
      gap: 12px;
      margin-top: 8px;
      flex-wrap: wrap;
    }
    .widget-detail-item {
      display: flex;
      align-items: center;
      gap: 4px;
      font-size: 11px;
      color: rgba(255, 255, 255, 0.5);
    }
    .widget-detail-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #64748b;
    }
    .widget-detail-dot.up { background: #22c55e; box-shadow: 0 0 8px #22c55e; }
    .widget-detail-dot.down { background: #ef4444; }

    /* Clock Widget */
    .widget-clock {
      font-size: 42px;
      font-weight: 200;
      font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
      letter-spacing: -1px;
    }
    .widget-date {
      font-size: 14px;
      color: rgba(255, 255, 255, 0.6);
    }

    /* Loading state */
    .widget-loading {
      opacity: 0.5;
    }
    .widget-loading .widget-primary::after {
      content: '...';
      animation: loadingDots 1s infinite;
    }
    @keyframes loadingDots {
      0%, 20% { content: '.'; }
      40% { content: '..'; }
      60%, 100% { content: '...'; }
    }

    /* Status Badge */
    .status-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 12px;
      border-radius: 20px;
      font-size: 14px;
      font-weight: 600;
    }
    .status-badge.up {
      background: rgba(34, 197, 94, 0.2);
      color: #22c55e;
    }
    .status-badge.down {
      background: rgba(239, 68, 68, 0.2);
      color: #ef4444;
    }
    
    /* Mode badges for Engine/DB type */
    .mode-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 14px;
      border-radius: 20px;
      font-size: 15px;
      font-weight: 600;
      color: white;
      text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    }
    
    .widget-text-value {
      font-size: 18px;
      font-weight: 600;
      color: #e2e8f0;
    }
    
    .widget-detail-value {
      font-weight: 600;
      color: #94a3b8;
      margin-right: 4px;
    }
    
    /* Tau time (simulation time) */
    .tau-time {
      font-size: 28px;
      font-weight: 700;
      color: #a78bfa;
      font-family: 'SF Mono', 'JetBrains Mono', monospace;
    }
    .tau-time small {
      font-size: 14px;
      opacity: 0.7;
      margin-left: 2px;
    }
    
    /* Uptime display */
    .uptime-value {
      font-size: 20px;
      font-weight: 600;
      color: #5eead4;
      font-family: 'SF Mono', 'JetBrains Mono', monospace;
    }
    
    /* Stat items for Dream World grid */
    .stat-item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 2px 0;
    }
    .stat-label {
      font-size: 11px;
      color: rgba(255,255,255,0.7);
    }
    .stat-value {
      font-size: 13px;
      font-weight: 600;
      color: #e2e8f0;
    }
    
    /* Hero name styling */
    .hero-name {
      font-size: 22px;
      font-weight: 700;
      color: #fbbf24;
      text-shadow: 0 2px 8px rgba(251, 191, 36, 0.3);
    }
    
    /* Realm name styling */
    .realm-name {
      font-size: 18px;
      font-weight: 600;
      color: #a78bfa;
      text-shadow: 0 2px 8px rgba(167, 139, 250, 0.3);
    }
    .status-badge::before {
      content: '';
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: currentColor;
    }

    .page-dots {
      display:flex; justify-content:center; gap:8px; padding:10px 0;
    }
    .page-dot {
      width:8px; height:8px; border-radius:50%; border:none; padding:0;
      background:rgba(255,255,255,0.35); cursor:pointer;
    }
    .page-dot.active { background:rgba(255,255,255,0.9); }

    .dock-wrap {
      padding:12px 20px; padding-bottom:calc(8px + env(safe-area-inset-bottom));
    }
    /* Profile Bar Dock - Minimal bottom bar */
    .dock.profile-bar {
      background: rgba(0, 0, 0, 0.4);
      backdrop-filter: blur(25px);
      -webkit-backdrop-filter: blur(25px);
      border-radius: 20px;
      padding: 8px 24px;
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 32px;
      max-width: 200px;
      margin: 0 auto;
      border: 1px solid rgba(255, 255, 255, 0.1);
    }
    .dock.profile-bar .dock-item {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 36px;
      height: 36px;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.1);
      font-size: 18px;
      cursor: pointer;
      transition: transform 0.15s, background 0.15s;
      text-decoration: none;
    }
    .dock.profile-bar .dock-item:hover {
      transform: scale(1.1);
      background: rgba(255, 255, 255, 0.2);
    }
    .dock.profile-bar .dock-item:active {
      transform: scale(0.95);
    }
    .dock.profile-bar .dock-item.profile {
      background: linear-gradient(135deg, #7c3aed, #a855f7);
    }
    
    /* Legacy dock (apps) - hidden by default with new config */
    .dock.apps-dock {
      background:rgba(255,255,255,0.2); backdrop-filter:blur(25px);
      border-radius:30px; padding:12px 20px;
      display:flex; justify-content:space-around;
      max-width:400px; margin:0 auto;
    }
    .dock.apps-dock .app-icon { width:52px; height:52px; font-size:24px; margin-bottom:0; }

    .edit-mode .app { animation:wiggle 0.3s infinite; }
    @keyframes wiggle {
      0%,100% { transform:rotate(-1deg); }
      50% { transform:rotate(1deg); }
    }
    .edit-mode .app-delete {
      position:absolute; top:-6px; left:-6px;
      width:20px; height:20px; border-radius:50%;
      background:#ef4444; color:white; font-size:14px; font-weight:bold;
      display:flex; align-items:center; justify-content:center;
      cursor:pointer; border:2px solid white;
    }
    .app-delete { display:none; }

    .edit-bar {
      display:none; position:fixed; bottom:0; left:0; right:0;
      padding:12px 20px; padding-bottom:calc(12px + env(safe-area-inset-bottom));
      background:rgba(0,0,0,0.8); backdrop-filter:blur(12px);
      text-align:center;
    }
    .edit-mode .edit-bar { display:block; }
    .edit-mode .dock-wrap { display:none; }
    .edit-bar button {
      padding:10px 24px; border-radius:10px; border:none;
      background:#22c55e; color:white; font-weight:600; font-size:14px;
      cursor:pointer;
    }

    /* 📁 FOLDER STYLES - iOS-style folder with long-press expand */
    .folder .app-icon {
      position: relative;
    }
    .folder .app-icon::after {
      content: '';
      position: absolute;
      bottom: 4px;
      right: 4px;
      width: 12px;
      height: 12px;
      background: rgba(255,255,255,0.3);
      border-radius: 3px;
      backdrop-filter: blur(4px);
    }
    .folder .folder-preview {
      position: absolute;
      inset: 6px;
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 2px;
      pointer-events: none;
    }
    .folder .folder-preview-item {
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0,0,0,0.2);
      border-radius: 4px;
    }

    /* 📱 FOLDER POPUP MODAL - iPhone-style glassmorphism */
    .folder-popup-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.6);
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
      z-index: 9999;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
    }
    .folder-popup-overlay.open {
      opacity: 1;
      pointer-events: auto;
    }
    .folder-popup {
      background: rgba(30, 30, 30, 0.85);
      border-radius: 28px;
      padding: 20px;
      min-width: 280px;
      max-width: 90vw;
      max-height: 70vh;
      overflow-y: auto;
      border: 1px solid rgba(255,255,255,0.15);
      box-shadow: 0 25px 50px rgba(0,0,0,0.5);
      transform: scale(0.8);
      transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    .folder-popup-overlay.open .folder-popup {
      transform: scale(1);
    }
    .folder-popup-header {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 16px;
      padding-bottom: 12px;
      border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    .folder-popup-icon {
      width: 48px;
      height: 48px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
    }
    .folder-popup-title {
      font-size: 18px;
      font-weight: 600;
      color: white;
    }
    .folder-popup-close {
      margin-left: auto;
      width: 28px;
      height: 28px;
      border-radius: 50%;
      background: rgba(255,255,255,0.15);
      border: none;
      color: white;
      font-size: 16px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .folder-popup-close:hover {
      background: rgba(255,255,255,0.25);
    }
    .folder-popup-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 12px;
    }
    .folder-popup-grid .app {
      padding: 8px;
      border-radius: 12px;
      transition: background 0.15s;
    }
    .folder-popup-grid .app:hover {
      background: rgba(255,255,255,0.1);
    }
    .folder-popup-grid .app-icon {
      width: 52px;
      height: 52px;
      font-size: 22px;
    }
    .folder-popup-grid .app-label {
      font-size: 10px;
      margin-top: 4px;
    }

    /* 📱 APP VIEWER (iOS-style in-OS app container) */
    .app-viewer-overlay {
      position: fixed;
      inset: 0;
      z-index: 10000; /* above folder popup */
      background: rgba(5, 9, 20, 0.98);
      backdrop-filter: var(--blur-heavy);
      -webkit-backdrop-filter: var(--blur-heavy);
      opacity: 0;
      pointer-events: none;
      transform: translateY(12px);
      transition: opacity 0.18s ease, transform 0.18s ease;
      display: flex;
      flex-direction: column;
    }
    .app-viewer-overlay.open {
      opacity: 1;
      pointer-events: auto;
      transform: translateY(0);
    }
    .app-viewer-header {
      height: calc(44px + env(safe-area-inset-top));
      padding: env(safe-area-inset-top) 12px 0 12px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
      border-bottom: 1px solid rgba(255,255,255,0.08);
      background: rgba(30, 30, 46, 0.65);
      backdrop-filter: var(--blur-heavy);
      -webkit-backdrop-filter: var(--blur-heavy);
    }
    .app-viewer-title {
      flex: 1;
      text-align: center;
      font-size: 12px;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      opacity: 0.85;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      padding: 0 6px;
      user-select: none;
      -webkit-user-select: none;
    }
    .app-viewer-btn {
      appearance: none;
      border: 1px solid rgba(255,255,255,0.14);
      background: rgba(255,255,255,0.08);
      color: rgba(255,255,255,0.92);
      border-radius: 12px;
      padding: 8px 10px;
      font-size: 12px;
      font-weight: 700;
      cursor: pointer;
    }
    .app-viewer-btn:active { transform: scale(0.98); }
    .app-viewer-frame {
      width: 100%;
      height: calc(100dvh - (44px + env(safe-area-inset-top)));
      border: 0;
      background: transparent;
    }

    /* Haptic feedback animation */
    @keyframes folderPulse {
      0% { transform: scale(1); }
      50% { transform: scale(1.08); }
      100% { transform: scale(1); }
    }
    .folder.activating .app-icon {
      animation: folderPulse 0.2s ease;
    }

    /* 🍎 iOS-STYLE APP ICONS - Better glassmorphism */
    .app-icon {
      background: var(--glass-bg) !important;
      backdrop-filter: var(--blur-light);
      -webkit-backdrop-filter: var(--blur-light);
      box-shadow: 
        inset 0 1px 0 var(--glass-highlight),
        0 4px 16px rgba(0, 0, 0, 0.25);
    }
