*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #0a0a0a;
  --fg: #e8e8e8;
  --fg-dim: #777;
  --accent: #ff3c3c;
  --glass: rgba(10, 10, 10, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  --transition: 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* ---- Viewport & Iframes ---- */

#viewport {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.site-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
  background: var(--bg);
}

.site-frame.active {
  opacity: 1;
  pointer-events: auto;
  z-index: 2;
}

/* Edge swipe zones: narrow strips on left/right edges for mobile nav.
   The rest of the screen passes through to the iframe for scrolling. */
.swipe-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 28px;
  z-index: 3;
  background: transparent;
  pointer-events: none;
  touch-action: none;
}

#swipe-zone-left { left: 0; }
#swipe-zone-right { right: 0; }

@media (pointer: coarse) {
  .swipe-zone {
    pointer-events: auto;
  }
}

/* ---- Loader ---- */

#loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

#loader.visible {
  opacity: 1;
}

.loader-spinner {
  width: 32px;
  height: 32px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- Top bar ---- */

#topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
  transition: opacity var(--transition), transform var(--transition);
}

.logo {
  font-family: 'Space Mono', monospace;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--fg);
}

.logo-accent {
  color: var(--accent);
}

.topbar-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#counter {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 1px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-right a,
.topbar-right button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--fg);
  cursor: pointer;
  transition: background var(--transition), transform 0.15s ease;
  text-decoration: none;
}

.topbar-right a:hover,
.topbar-right button:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.05);
}

.topbar-right a:active,
.topbar-right button:active {
  transform: scale(0.95);
}

/* ---- Bottom bar ---- */

#bottombar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, transparent 100%);
  transition: opacity var(--transition), transform var(--transition);
}

.site-info {
  flex: 1;
  min-width: 0;
}

#site-url {
  font-family: 'Space Mono', monospace;
  font-size: 12px;
  color: var(--fg-dim);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  max-width: 200px;
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-controls button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--fg);
  cursor: pointer;
  transition: all var(--transition);
}

.nav-controls button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.08);
}

.nav-controls button:active:not(:disabled) {
  transform: scale(0.92);
}

.nav-controls button:disabled {
  opacity: 0.25;
  cursor: default;
}

#btn-shuffle {
  width: 44px;
  height: 44px;
  background: var(--accent);
  border-color: transparent;
}

#btn-shuffle:hover {
  background: #ff5555 !important;
  border-color: transparent !important;
}

/* ---- UI auto-hide ---- */

.ui-hidden #topbar {
  opacity: 0;
  transform: translateY(-20px);
  pointer-events: none;
}

.ui-hidden #bottombar {
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
}

/* ---- List Panel ---- */

#list-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 85vw;
  z-index: 20;
  background: rgba(14, 14, 14, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-left: 1px solid var(--glass-border);
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#list-panel.panel-visible {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
}

.panel-header h2 {
  font-family: 'Space Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--fg);
}

.panel-header button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.panel-header button:hover {
  color: var(--fg);
  background: rgba(255, 255, 255, 0.08);
}

#site-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0;
}

#site-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background var(--transition);
  border-left: 3px solid transparent;
}

#site-list li:hover {
  background: rgba(255, 255, 255, 0.04);
}

#site-list li.active {
  background: rgba(255, 60, 60, 0.08);
  border-left-color: var(--accent);
}

.list-number {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--fg-dim);
  min-width: 24px;
}

.list-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
}

.list-url {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  color: var(--fg-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Swipe Hint ---- */

#swipe-hint {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 10px 20px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 100px;
  font-size: 13px;
  color: var(--fg-dim);
  opacity: 1;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

#swipe-hint.hint-hidden {
  opacity: 0;
}

/* ---- Scrollbar ---- */

#site-list::-webkit-scrollbar {
  width: 4px;
}

#site-list::-webkit-scrollbar-track {
  background: transparent;
}

#site-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

/* ---- Responsive ---- */

@media (max-width: 600px) {
  #topbar, #bottombar {
    padding: 12px 14px;
  }

  #bottombar {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .logo {
    font-size: 12px;
    letter-spacing: 1.5px;
  }

  #site-url {
    font-size: 11px;
    max-width: 140px;
  }

  .nav-controls button {
    width: 36px;
    height: 36px;
  }

  #btn-shuffle {
    width: 40px;
    height: 40px;
  }

  #list-panel {
    width: 100%;
    max-width: 100%;
  }
}
