/* ═══════════════════════════════════════════════
   NAL BROWSER — Base Styles
   ═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --nal-purple: hsl(263 22% 54%);
  --nal-purple-light: hsl(263 22% 68%);
  --nal-purple-dark: hsl(263 22% 40%);
  --nal-sage: hsl(158 27% 65%);
  --nal-sage-dark: hsl(158 27% 45%);
  --nal-rose: hsl(316 30% 77%);
  --chrome-bg: hsl(263 15% 14%);
  --chrome-border: hsl(263 12% 22%);
  --chrome-text: hsl(263 10% 88%);
  --chrome-dim: hsl(263 8% 52%);
  --address-bg: hsl(263 18% 9%);
  --address-border: hsl(263 10% 28%);
  --accent: var(--nal-sage);
  --accent-hover: var(--nal-sage-dark);
  --content-bg: #ffffff;
  --dot-red: #f38ba8;
  --dot-yellow: #f9e2af;
  --dot-green: var(--nal-sage);
  --preset-bg: hsl(263 12% 20%);
  --preset-hover: hsl(263 12% 28%);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: hsl(263 18% 8%);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: var(--chrome-text);
}

/* ─── Browser Shell ─── */

#browser-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: 10px;
  overflow: hidden;
  margin: 4px;
  border: 1px solid var(--chrome-border);
}

/* ─── Title Bar ─── */

#title-bar {
  display: flex;
  align-items: center;
  height: 38px;
  min-height: 38px;
  background: var(--chrome-bg);
  padding: 0 12px;
  gap: 8px;
  -webkit-user-select: none;
  user-select: none;
  border-bottom: 1px solid var(--chrome-border);
}

.window-dots {
  display: flex;
  gap: 6px;
}

.window-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.window-dot.red { background: var(--dot-red); }
.window-dot.yellow { background: var(--dot-yellow); }
.window-dot.green { background: var(--dot-green); }

#title-text {
  flex: 1;
  text-align: center;
  font-size: 12px;
  color: var(--chrome-dim);
  letter-spacing: 0.5px;
}

/* ─── Address Bar ─── */

#address-bar {
  display: flex;
  align-items: center;
  height: 44px;
  min-height: 44px;
  background: var(--chrome-bg);
  padding: 0 10px;
  gap: 8px;
  border-bottom: 1px solid var(--chrome-border);
}

#nav-buttons {
  display: flex;
  gap: 4px;
}

.nav-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--chrome-dim);
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.nav-btn:hover {
  background: var(--preset-bg);
  color: var(--chrome-text);
}

#url-container {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--address-bg);
  border: 1px solid var(--address-border);
  border-radius: 20px;
  padding: 0 14px;
  height: 30px;
  transition: border-color 0.2s;
}

#url-container:focus-within {
  border-color: var(--accent);
}

#url-icon {
  color: var(--chrome-dim);
  font-size: 12px;
  margin-right: 8px;
  flex-shrink: 0;
}

#url-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--chrome-text);
  font-size: 13px;
  font-family: inherit;
}

#url-input::placeholder {
  color: var(--chrome-dim);
}

#go-btn {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--accent);
  color: var(--address-bg);
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

#go-btn:hover {
  background: var(--accent-hover);
}

/* ─── Preset Bar ─── */

#preset-bar {
  display: flex;
  align-items: center;
  height: 36px;
  min-height: 36px;
  background: var(--chrome-bg);
  padding: 0 10px;
  gap: 6px;
  border-bottom: 1px solid var(--chrome-border);
  overflow-x: auto;
  scrollbar-width: none;
}

#preset-bar::-webkit-scrollbar { display: none; }

.preset-btn {
  flex-shrink: 0;
  height: 24px;
  padding: 0 12px;
  border: none;
  background: var(--preset-bg);
  color: var(--chrome-text);
  font-size: 11px;
  cursor: pointer;
  border-radius: 12px;
  transition: background 0.15s;
  white-space: nowrap;
}

.preset-btn:hover {
  background: var(--preset-hover);
}

/* ─── Content Area ─── */

#content-area {
  flex: 1;
  position: relative;
  background: var(--content-bg);
  overflow: hidden;
}

#site-container {
  width: 100%;
  height: 100%;
  overflow: auto;
  position: relative;
  z-index: 1;
}

#site-container * {
  max-width: 100%;
}

/* ─── Overlay Layers (stacked above content) ─── */

#canvas-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

#dom-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 11;
  pointer-events: none;
}

#css-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 12;
  pointer-events: none;
}

/* ─── Loading Indicator ─── */

#loading-indicator {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  text-align: center;
  color: var(--chrome-dim);
}

#loading-indicator.active {
  display: block;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--chrome-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* ─── Landing Screen ─── */

#landing-screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--content-bg);
  color: #1e1e2e;
  text-align: center;
  transition: opacity 0.5s;
}

#landing-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.landing-title {
  font-size: 48px;
  font-weight: 200;
  letter-spacing: 12px;
  text-transform: uppercase;
  margin-bottom: 8px;
  color: #1e1e2e;
}

.landing-subtitle {
  font-size: 12px;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: #6c7086;
  margin-bottom: 40px;
}

.landing-hint {
  font-size: 13px;
  color: #6c7086;
  line-height: 1.8;
}

.landing-hint kbd {
  background: #e6e9ef;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: inherit;
  border: 1px solid #ccd0da;
}

/* ─── Phase Indicator (subtle) ─── */

#phase-indicator {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 10px;
  color: var(--chrome-dim);
  z-index: 5;
  opacity: 0.4;
  font-family: monospace;
  display: none;
}

/* ─── Error Screen ─── */

.error-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #6c7086;
  font-size: 14px;
  text-align: center;
  padding: 40px;
}

.error-screen .error-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.error-screen .error-text {
  max-width: 400px;
  line-height: 1.6;
}

/* ─── Theme Toggle ─── */

#theme-toggle {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--chrome-dim);
  font-size: 16px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

#theme-toggle:hover {
  background: var(--preset-bg);
  color: var(--chrome-text);
}

.theme-icon-dark { display: none; }
.theme-icon-light { display: inline; }

html.dark-theme .theme-icon-dark { display: inline; }
html.dark-theme .theme-icon-light { display: none; }

/* ─── Dark Theme Overrides ─── */

html.dark-theme {
  --content-bg: #1a1a22;
  --content-text: #cdd6f4;
  --content-muted: #6c7086;
  --landing-text: #cdd6f4;
}

html.dark-theme #landing-screen {
  background: var(--content-bg);
  color: var(--landing-text);
}

html.dark-theme .landing-subtitle {
  color: var(--content-muted);
}

html.dark-theme .landing-hint {
  color: var(--content-muted);
}

html.dark-theme .landing-hint kbd {
  background: hsl(263 12% 22%);
  border-color: hsl(263 12% 30%);
  color: var(--content-text);
}

html.dark-theme #content-area {
  background: var(--content-bg);
}

html.dark-theme .error-screen {
  color: var(--content-muted);
}

/* ─── Dark Theme: NAL site inner content (infoboxes, categories, etc.) ─── */

html.dark-theme #site-container [style*="background:#f8f9fa"],
html.dark-theme #site-container [style*="background: #f8f9fa"] {
  background: #1e1e28 !important;
  color: #c8c8c8 !important;
  border-color: #333 !important;
}

html.dark-theme #site-container [style*="background:#f8f9fa"] [style*="border-bottom:1px solid #eee"],
html.dark-theme #site-container [style*="border-bottom:1px solid #eee"] {
  border-color: #333 !important;
}

html.dark-theme #site-container [style*="border-top:1px solid #ccc"] {
  border-color: #333 !important;
}

html.dark-theme #site-container [style*="border:1px solid #ccc"] {
  border-color: #333 !important;
}

html.dark-theme #site-container [style*="background:#fff3cd"] {
  background: #2a2500 !important;
  color: #f9e2af !important;
  border-color: #665500 !important;
}

html.dark-theme #site-container [style*="background:#fff5f5"] {
  background: #2a0a0a !important;
  color: #f38ba8 !important;
  border-color: #660000 !important;
}

html.dark-theme #site-container [style*="background:#fff3f3"] {
  background: #2a0a0a !important;
  color: #f38ba8 !important;
}

/* ─── Mobile Responsive ─── */

@media (max-width: 640px) {
  .landing-title { font-size: 28px; letter-spacing: 6px; }
  #address-bar { padding: 0 6px; gap: 4px; }
  #url-container { padding: 0 10px; }
  .preset-btn { font-size: 10px; padding: 0 8px; }
}

/* ─── Reader Mode Banner ─── */

#reader-mode-banner {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 32px;
  background: linear-gradient(90deg, var(--nal-sage), hsl(158 27% 55%));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  z-index: 5;
  letter-spacing: 0.3px;
}

.landing-logo {
  display: flex;
  align-items: baseline;
  margin-bottom: 12px;
}

/* NAL preset highlight */
.nal-preset {
  border: 1px solid var(--nal-purple);
  background: rgba(126, 105, 155, 0.15);
}
.nal-preset:hover {
  background: rgba(126, 105, 155, 0.3);
}
