/* ==========================================================================
   MAGNE.AI Portal Shell - Terminal Web Style
   Multilingual Unified Shell Prototype

   Design Principle: All visual tokens are scoped to .portal-shell.
   Shell components MUST NOT depend on page-level variables.
   Font sizes use px for pixel-perfect consistency across pages.
   ========================================================================== */

/* ── Global Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

/* ── Shell Design Tokens (scoped to .portal-shell) ── */
.portal-shell {
  /* Shell-only color palette - DO NOT reference page-level variables */
  --ps-bg: #070910;
  --ps-surface: #0d1520;
  --ps-surface-2: #111d2e;
  --ps-border: rgba(57, 208, 214, 0.12);
  --ps-border-bright: rgba(57, 208, 214, 0.32);
  --ps-text: #e6edf3;
  --ps-text-secondary: #8b949e;
  --ps-text-muted: rgba(139, 148, 158, 0.65);
  --ps-accent: #39d0d6;
  --ps-accent-dim: rgba(57, 208, 214, 0.15);
  --ps-accent-glow: rgba(57, 208, 214, 0.2);
  --ps-purple: #a371f7;
  --ps-green: #3fb950;
  --ps-yellow: #d29922;
  --ps-red: #f85149;

  /* Shell-only design tokens - explicit names */
  --portal-shell-bg: #070910;
  --portal-shell-bg-elevated: rgba(9, 13, 22, 0.96);
  --portal-shell-border: rgba(148, 163, 184, 0.16);
  --portal-shell-border-accent: rgba(57, 208, 214, 0.28);
  --portal-shell-text: #e6edf3;
  --portal-shell-text-secondary: #8b949e;
  --portal-shell-text-muted: rgba(139, 148, 158, 0.65);
  --portal-shell-accent: #39d0d6;
  --portal-shell-accent-strong: #35c8d4;
  --portal-shell-accent-soft: rgba(65, 217, 230, 0.12);
  --portal-shell-accent-border: rgba(65, 217, 230, 0.28);
  --portal-shell-surface: #0d1520;
  --portal-shell-surface-2: #111d2e;

  /* Shell font stack - explicit, no page overrides */
  --portal-shell-font: 'Inter', 'Noto Sans TC', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --portal-shell-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --portal-shell-logo-font: 'Space Grotesk', var(--portal-shell-font);

  /* Base font size for the shell - fixed at 16px */
  font-family: var(--portal-shell-font);
  font-size: 16px;
  line-height: 1.5;

  background: var(--portal-shell-bg);
  color: var(--portal-shell-text);
  min-height: 100vh;
  position: relative;
}

/* Grid Background */
.portal-shell-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(rgba(57, 208, 214, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 208, 214, 0.025) 1px, transparent 1px);
  background-size: 60px 60px;
}

/* Radial Glow */
.portal-shell-glow {
  position: fixed;
  top: -10%;
  left: 50%;
  transform: translateX(-50%);
  width: 100vw;
  height: 70vh;
  background: radial-gradient(ellipse at center, rgba(57, 208, 214, 0.05) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
  animation: ps-glow-pulse 8s ease-in-out infinite;
}

/* ==========================================================================
   HEADER
   ========================================================================== */

.portal-shell-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 60px;
  background: var(--portal-shell-bg-elevated);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--portal-shell-border);
}

.portal-shell-header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 32px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Brand / Logo */
.portal-shell-brand {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

.portal-shell-logo {
  height: 28px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

/* Navigation */
.portal-shell-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.portal-shell-nav-link {
  display: block;
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  font-weight: 600;
  letter-spacing: 0.2px;
  padding: 6px 10px;
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  white-space: nowrap;
}

.portal-shell-nav-link:hover {
  color: var(--portal-shell-text);
  background: rgba(255, 255, 255, 0.06);
}

.portal-shell-nav-link.active {
  color: var(--portal-shell-accent);
  background: transparent;
}

/* Actions Area */
.portal-shell-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

/* Language Dropdown */
.portal-shell-language {
  position: relative;
}

.portal-shell-language-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  border: 1px solid var(--portal-shell-border);
  color: var(--portal-shell-text-secondary);
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.portal-shell-language-btn:hover {
  border-color: var(--portal-shell-border-accent);
  color: var(--portal-shell-text);
}

.portal-shell-language-btn .ps-chevron {
  font-size: 10px;
  transition: transform 0.2s;
}

.portal-shell-language.open .ps-chevron {
  transform: rotate(180deg);
}

.portal-shell-language-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--portal-shell-surface);
  border: 1px solid var(--portal-shell-border);
  border-radius: 6px;
  padding: 6px 0;
  list-style: none;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 1001;
}

.portal-shell-language.open .portal-shell-language-menu {
  display: block;
}

.portal-shell-language-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  transition: all 0.15s;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.portal-shell-language-option:hover {
  background: var(--portal-shell-surface-2);
  color: var(--portal-shell-text);
}

.portal-shell-language-option.active {
  color: var(--portal-shell-accent);
}

.portal-shell-language-option.disabled {
  color: var(--portal-shell-text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.portal-shell-language-option .ps-soon {
  font-size: 10px;
  color: var(--portal-shell-text-muted);
  background: var(--portal-shell-surface-2);
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: 500;
}

/* CTA Button */
.portal-shell-cta {
  display: inline-block;
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  font-weight: 700;
  padding: 10px 16px;
  min-height: 40px;
  border-radius: 8px;
  color: #061014;
  background: var(--portal-shell-accent);
  border: 1px solid var(--portal-shell-accent);
  text-decoration: none;
  transition: opacity 0.2s;
  white-space: nowrap;
  box-sizing: border-box;
}

.portal-shell-cta:hover {
  opacity: 0.85;
}

/* Phone Portal Link */
.portal-shell-phone {
  display: block;
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  padding: 6px 8px;
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.2s;
  white-space: nowrap;
}

.portal-shell-phone:hover {
  color: var(--portal-shell-text);
}

/* GitHub Icon */
.portal-shell-github {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid var(--portal-shell-border);
  background: var(--portal-shell-surface);
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  flex-shrink: 0;
  box-sizing: border-box;
}

.portal-shell-github:hover {
  border-color: var(--portal-shell-border-accent);
  color: var(--portal-shell-text);
}

/* Mobile Toggle Button */
.portal-shell-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: transparent;
  border: 1px solid var(--portal-shell-border);
  color: var(--portal-shell-text);
  font-size: 20px;
  padding: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s;
  flex-shrink: 0;
  box-sizing: border-box;
}

.portal-shell-toggle:hover {
  border-color: var(--portal-shell-border-accent);
}

/* ==========================================================================
   MOBILE MENU
   ========================================================================== */

.portal-shell-mobile {
  display: none;
  position: fixed;
  top: 60px;
  left: 0;
  right: 0;
  height: calc(100dvh - 60px);
  background: rgba(7, 9, 16, 0.98);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  z-index: 999;
  overflow-y: auto;
  padding: 24px 18px 32px;
  flex-direction: column;
  gap: 0;
}

.portal-shell-mobile.open {
  display: flex;
}

.portal-shell-mobile-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
}

.portal-shell-mobile-link {
  display: block;
  font-family: var(--portal-shell-font);
  font-size: 15px;
  line-height: 24px;
  font-weight: 500;
  padding: 10px 8px;
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
  border-bottom: 1px solid var(--portal-shell-border);
}

.portal-shell-mobile-link:last-child {
  border-bottom: none;
}

.portal-shell-mobile-link:hover,
.portal-shell-mobile-link.active {
  color: var(--portal-shell-accent);
  background: var(--portal-shell-accent-soft);
}

.portal-shell-mobile-divider {
  height: 1px;
  background: var(--portal-shell-border);
  margin: 12px 0;
}

.portal-shell-mobile-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 12px;
}

.portal-shell-mobile-lang {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.portal-shell-mobile-lang-btn {
  display: inline-block;
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  padding: 6px 10px;
  color: var(--portal-shell-text-muted);
  text-decoration: none;
  border: 1px solid var(--portal-shell-border);
  border-radius: 4px;
  transition: all 0.2s;
  box-sizing: border-box;
}

.portal-shell-mobile-lang-btn:hover,
.portal-shell-mobile-lang-btn.active {
  color: var(--portal-shell-accent);
  border-color: var(--portal-shell-accent);
}

.portal-shell-mobile-lang-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ==========================================================================
   FOOTER
   ========================================================================== */

.portal-shell-footer {
  border-top: 1px solid var(--portal-shell-border);
  padding: 48px 0 32px;
  position: relative;
  z-index: 1;
}

.portal-shell-footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 32px;
}

.portal-shell-footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr 1fr;
  gap: 32px;
}

/* Footer Brand */
.portal-shell-footer-brand {
  /* brand area */
}

.portal-shell-footer-logo {
  height: 24px;
  width: auto;
  margin-bottom: 12px;
  display: block;
}

.portal-shell-footer-tagline {
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 1.5;
  color: var(--portal-shell-text-muted);
  max-width: 280px;
  margin: 0;
}

/* Footer Columns */
.portal-shell-footer-col-title {
  font-family: var(--portal-shell-font);
  font-size: 12px;
  font-weight: 700;
  color: var(--portal-shell-text);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 16px 0;
}

.portal-shell-footer-col-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.portal-shell-footer-link {
  font-family: var(--portal-shell-font);
  font-size: 13px;
  line-height: 20px;
  color: var(--portal-shell-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.portal-shell-footer-link:hover {
  color: var(--portal-shell-accent);
}

/* Footer Social */
.portal-shell-social {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.portal-shell-social-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--portal-shell-border);
  background: var(--portal-shell-surface);
  color: var(--portal-shell-text-secondary);
  text-decoration: none;
  transition: all 0.2s;
  box-sizing: border-box;
}

.portal-shell-social-link:hover {
  border-color: var(--portal-shell-accent);
  color: var(--portal-shell-accent);
}

/* Footer Bottom */
.portal-shell-footer-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 32px;
  margin-top: 32px;
  border-top: 1px solid var(--portal-shell-border);
  gap: 24px;
  flex-wrap: nowrap;
}

.portal-shell-footer-bottom .portal-shell-legal + .portal-shell-legal,
.portal-shell-footer-bottom .portal-shell-legal + .portal-shell-legal-links {
  margin-left: 8px;
}

.portal-shell-legal {
  font-family: var(--portal-shell-font);
  font-size: 12px;
  line-height: 1.5;
  color: var(--portal-shell-text-muted);
  margin: 0;
}

.portal-shell-legal-links {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.portal-shell-legal-link {
  font-family: var(--portal-shell-font);
  font-size: 12px;
  line-height: 1.5;
  color: var(--portal-shell-text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.portal-shell-legal-link:hover {
  color: var(--portal-shell-text-secondary);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

/* Large Desktop: 1320px+ */
@media (min-width: 1320px) {
  .portal-shell-nav {
    display: flex;
  }
  .portal-shell-toggle {
    display: none;
  }
  .portal-shell-phone,
  .portal-shell-github {
    display: flex;
  }
}

/* Desktop to Medium: 1024px - 1319px */
@media (max-width: 1319px) and (min-width: 1024px) {
  .portal-shell-header-inner {
    max-width: 100%;
    padding: 0 24px;
  }

  .portal-shell-nav {
    display: flex;
    gap: 4px;
  }

  .portal-shell-nav-link {
    font-size: 12px;
    padding: 5px 8px;
  }

  .portal-shell-footer-grid {
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 24px;
  }

  .portal-shell-footer-brand {
    grid-column: 1 / -1;
    display: flex;
    align-items: flex-start;
    gap: 32px;
  }

  .portal-shell-footer-brand > * {
    flex: 1;
  }
}

/* Medium to Tablet: 900px - 1023px */
@media (max-width: 1023px) and (min-width: 900px) {
  .portal-shell-header-inner {
    padding: 0 20px;
    gap: 12px;
  }

  .portal-shell-nav {
    display: flex;
    gap: 2px;
  }

  .portal-shell-nav-link {
    font-size: 12px;
    padding: 4px 7px;
  }

  .portal-shell-phone {
    display: none;
  }

  .portal-shell-footer-grid {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
  }

  .portal-shell-footer-brand {
    grid-column: 1 / -1;
    display: flex;
    align-items: flex-start;
    gap: 24px;
  }
}

/* Tablet: 768px - 899px */
@media (max-width: 899px) and (min-width: 768px) {
  /* Hide desktop nav, phone, github in header actions */
  .portal-shell-header .portal-shell-actions .portal-shell-nav,
  .portal-shell-header .portal-shell-actions .portal-shell-phone,
  .portal-shell-header .portal-shell-actions .portal-shell-github {
    display: none;
  }

  .portal-shell-nav {
    display: none;
    width: 0;
    min-width: 0;
    max-width: 0;
    flex: 0 0 0;
    flex-basis: 0;
    flex-shrink: 1;
    overflow: hidden;
    pointer-events: none;
  }

  .portal-shell-phone {
    display: none;
    width: 0;
    min-width: 0;
    max-width: 0;
    flex: 0 0 0;
    flex-basis: 0;
    flex-shrink: 1;
    overflow: hidden;
    pointer-events: none;
  }

  .portal-shell-github {
    display: none;
    width: 0;
    min-width: 0;
    max-width: 0;
    flex: 0 0 0;
    flex-basis: 0;
    flex-shrink: 1;
    overflow: hidden;
    pointer-events: none;
  }

  /* Show phone/cta in mobile menu */
  .portal-shell-mobile .portal-shell-phone,
  .portal-shell-mobile .portal-shell-cta {
    display: flex;
    width: 100%;
    justify-content: center;
    align-items: center;
  }

  .portal-shell-toggle {
    display: flex;
  }

  .portal-shell-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 0 16px;
    overflow: hidden;
  }

  .portal-shell-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    flex: 0 0 44px;
    flex-shrink: 0;
    margin-left: auto;
    position: relative;
    right: auto;
    left: auto;
    transform: none;
    gap: 0;
    overflow: visible;
  }

  .portal-shell-footer-grid {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }

  .portal-shell-footer-brand {
    grid-column: 1 / -1;
    flex-direction: column;
  }
}

/* Mobile: < 768px */
@media (max-width: 767px) {
  .portal-shell-header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0 16px;
    height: 56px;
    box-sizing: border-box;
    overflow: hidden;
  }

  .portal-shell-nav {
    display: none;
    width: 0;
    min-width: 0;
    max-width: 0;
    flex: 0 0 0;
    flex-basis: 0;
    flex-shrink: 1;
    overflow: hidden;
    pointer-events: none;
  }

  .portal-shell-logo {
    height: 24px;
    max-width: 180px;
  }

  .portal-shell-brand {
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 60px);
    overflow: hidden;
  }

  .portal-shell-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
    flex: 0 0 44px;
    flex-shrink: 0;
    margin-left: auto;
    position: relative;
    right: auto;
    left: auto;
    transform: none;
    gap: 0;
    overflow: visible;
  }

  .portal-shell-actions > *:not(.portal-shell-toggle) {
    display: none;
  }

  .portal-shell-toggle {
    display: flex;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1002;
    right: auto;
    left: auto;
    transform: none;
  }

  /* Hide CTA in header actions only, not in mobile menu */
  .portal-shell-header .portal-shell-actions .portal-shell-cta,
  .portal-shell-header .portal-shell-actions .portal-shell-phone {
    display: none;
  }

  /* Show CTA in mobile menu */
  .portal-shell-mobile .portal-shell-cta,
  .portal-shell-mobile .portal-shell-phone {
    display: flex;
    width: 100%;
    justify-content: center;
    align-items: center;
  }

  .portal-shell-mobile {
    top: 56px;
    height: calc(100dvh - 56px);
  }

  .portal-shell-footer-grid {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .portal-shell-footer-inner {
    padding: 0 16px;
  }

  .portal-shell-footer-bottom {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .portal-shell-footer-bottom .portal-shell-legal + .portal-shell-legal,
  .portal-shell-footer-bottom .portal-shell-legal + .portal-shell-legal-links {
    margin-left: 0;
  }

  .portal-shell-legal-links {
    flex-wrap: wrap;
    gap: 16px;
  }
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

@keyframes ps-glow-pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}
