:root {
  --portal-bg: #090c11;
  --portal-surface: #11161d;
  --portal-surface-raised: #151c24;
  --portal-border: #27303b;
  --portal-border-soft: rgba(148, 163, 184, 0.14);
  --portal-text: #edf2f7;
  --portal-muted: #8f9baa;
  --portal-blue: #4f7cff;
  --portal-blue-strong: #2962ff;
  --portal-teal: #28c6a4;
  --portal-amber: #f5a524;
  --portal-red: #f04438;
  --portal-header: rgba(9, 12, 17, 0.84);
  --portal-shadow: 0 28px 80px rgba(0, 0, 0, 0.34);
  --portal-grid: rgba(148, 163, 184, 0.055);
}

:is(html[data-theme="light"], html.theme-light) {
  --portal-bg: #f5f7fb;
  --portal-surface: #ffffff;
  --portal-surface-raised: #f8faff;
  --portal-border: #d6deea;
  --portal-border-soft: rgba(71, 85, 105, 0.13);
  --portal-text: #152033;
  --portal-muted: #657286;
  --portal-header: rgba(248, 250, 253, 0.88);
  --portal-shadow: 0 24px 60px rgba(49, 65, 90, 0.14);
  --portal-grid: rgba(71, 85, 105, 0.06);
}

body.portal-body {
  min-height: 100vh;
  color: var(--portal-text);
  background:
    radial-gradient(circle at 12% -10%, rgba(79, 124, 255, 0.17), transparent 34rem),
    radial-gradient(circle at 96% 24%, rgba(40, 198, 164, 0.09), transparent 28rem),
    var(--portal-bg);
}

.portal-container {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.portal-header {
  position: sticky;
  z-index: 50;
  top: 0;
  border-bottom: 1px solid var(--portal-border-soft);
  background: var(--portal-header);
  backdrop-filter: blur(18px);
}

.portal-header-inner {
  min-height: 72px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
}

.portal-logo {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--portal-text);
}

.portal-logo-mark {
  position: relative;
  width: 34px;
  height: 34px;
  overflow: hidden;
  border: 1px solid rgba(79, 124, 255, 0.56);
  border-radius: 10px;
  background:
    linear-gradient(145deg, rgba(79, 124, 255, 0.3), rgba(40, 198, 164, 0.08)),
    var(--portal-surface);
  box-shadow: inset 0 0 18px rgba(79, 124, 255, 0.14);
}

.portal-logo-mark::before,
.portal-logo-mark::after {
  position: absolute;
  content: "";
  left: 7px;
  width: 19px;
  height: 2px;
  border-radius: 999px;
  background: var(--portal-blue);
  transform-origin: left center;
}

.portal-logo-mark::before {
  top: 20px;
  transform: rotate(-25deg);
}

.portal-logo-mark::after {
  top: 13px;
  background: var(--portal-teal);
  transform: rotate(22deg);
}

.portal-logo-copy {
  display: grid;
  gap: 1px;
}

.portal-logo-copy strong {
  font-size: 15px;
  letter-spacing: 0.02em;
}

.portal-logo-copy small {
  color: var(--portal-muted);
  font-size: 11px;
}

.portal-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}

.portal-nav a {
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--portal-muted);
  font-size: 14px;
  transition: color 160ms ease, background 160ms ease;
}

.portal-nav a:hover,
.portal-nav a:focus-visible {
  color: var(--portal-text);
  background: var(--portal-border-soft);
}

.portal-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.portal-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border: 1px solid var(--portal-border);
  border-radius: 9px;
  color: var(--portal-text);
  background: var(--portal-surface);
  font-size: 14px;
  font-weight: 650;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.portal-button:hover {
  border-color: rgba(79, 124, 255, 0.55);
  transform: translateY(-1px);
}

.portal-button.primary {
  border-color: var(--portal-blue-strong);
  color: #ffffff;
  background: var(--portal-blue-strong);
  box-shadow: 0 10px 24px rgba(41, 98, 255, 0.24);
}

.portal-button.primary:hover {
  background: #3f70ff;
}

.portal-button.ghost {
  border-color: transparent;
  background: transparent;
}

.theme-toggle,
.nav-toggle,
.password-toggle {
  width: 40px;
  min-width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--portal-border);
  border-radius: 9px;
  color: var(--portal-muted);
  background: var(--portal-surface);
}

.theme-toggle::before {
  content: "☾";
  font-size: 18px;
  line-height: 1;
}

.theme-toggle[data-theme-state="light"]::before {
  content: "☀";
}

.nav-toggle {
  display: none;
  font-size: 20px;
}

.portal-hero {
  position: relative;
  overflow: hidden;
  padding: 92px 0 70px;
}

.portal-hero::before {
  position: absolute;
  inset: 0;
  content: "";
  pointer-events: none;
  background-image:
    linear-gradient(var(--portal-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--portal-grid) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

.portal-hero-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.03fr) minmax(430px, 0.97fr);
  align-items: center;
  gap: 64px;
}

.portal-kicker,
.section-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--portal-blue);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.portal-kicker::before,
.section-kicker::before {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  content: "";
  background: var(--portal-teal);
  box-shadow: 0 0 0 5px rgba(40, 198, 164, 0.1);
}

.portal-hero h1 {
  max-width: 720px;
  margin: 22px 0 20px;
  color: var(--portal-text);
  font-size: clamp(42px, 5.3vw, 70px);
  font-weight: 760;
  letter-spacing: -0.055em;
  line-height: 1.02;
}

.portal-hero h1 span {
  color: var(--portal-blue);
}

.portal-hero-copy > p {
  max-width: 650px;
  margin: 0;
  color: var(--portal-muted);
  font-size: 18px;
  line-height: 1.75;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
}

.hero-note {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 20px;
  color: var(--portal-muted);
  font-size: 13px;
}

.hero-note::before {
  width: 7px;
  height: 7px;
  flex: 0 0 auto;
  border-radius: 999px;
  content: "";
  background: var(--portal-amber);
}

.market-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--portal-border);
  border-radius: 16px;
  background: rgba(14, 19, 25, 0.92);
  box-shadow: var(--portal-shadow);
}

:is(html[data-theme="light"], html.theme-light) .market-stage {
  background: rgba(255, 255, 255, 0.94);
}

.market-stage::after {
  position: absolute;
  inset: 48px 0 0;
  content: "";
  pointer-events: none;
  background-image:
    linear-gradient(var(--portal-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--portal-grid) 1px, transparent 1px);
  background-size: 42px 42px;
}

.market-stage-head {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 16px;
  border-bottom: 1px solid var(--portal-border-soft);
}

.market-pair {
  display: grid;
  gap: 2px;
}

.market-pair strong {
  font-size: 13px;
}

.market-pair small {
  color: var(--portal-muted);
  font-size: 10px;
}

.stage-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--portal-teal);
  font-size: 11px;
  font-weight: 700;
}

.stage-status::before {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  content: "";
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(40, 198, 164, 0.1);
}

.candle-board {
  position: relative;
  z-index: 1;
  min-height: 315px;
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 42px 20px 58px;
}

.candle {
  position: relative;
  width: 10px;
  height: var(--height, 80px);
  margin-top: var(--top, 0);
  border-radius: 2px;
  background: var(--portal-teal);
  opacity: 0.92;
}

.candle.down {
  background: var(--portal-red);
}

.candle::before {
  position: absolute;
  top: -14px;
  bottom: -16px;
  left: 50%;
  width: 1px;
  content: "";
  background: inherit;
  transform: translateX(-50%);
}

.engine-float {
  position: absolute;
  z-index: 2;
  right: 18px;
  bottom: 18px;
  width: min(265px, calc(100% - 36px));
  padding: 15px;
  border: 1px solid rgba(79, 124, 255, 0.32);
  border-radius: 12px;
  background: color-mix(in srgb, var(--portal-surface) 92%, transparent);
  backdrop-filter: blur(12px);
}

.engine-float-head,
.engine-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.engine-float-head {
  margin-bottom: 12px;
}

.engine-float-head strong {
  font-size: 13px;
}

.engine-row {
  padding: 7px 0;
  border-top: 1px solid var(--portal-border-soft);
  color: var(--portal-muted);
  font-size: 11px;
}

.engine-row b {
  color: var(--portal-text);
  font-weight: 650;
}

.portal-status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 8px;
  border: 1px solid var(--portal-border);
  border-radius: 13px;
  background: var(--portal-surface);
}

.portal-status-item {
  min-height: 88px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 16px 20px;
  border-right: 1px solid var(--portal-border-soft);
}

.portal-status-item:last-child {
  border-right: 0;
}

.portal-status-item span {
  color: var(--portal-muted);
  font-size: 12px;
}

.portal-status-item strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--portal-teal);
}

.status-dot.locked {
  background: var(--portal-amber);
}

.status-dot.off {
  background: var(--portal-muted);
}

.portal-section {
  padding: 92px 0;
}

.portal-section.alt {
  border-top: 1px solid var(--portal-border-soft);
  border-bottom: 1px solid var(--portal-border-soft);
  background: color-mix(in srgb, var(--portal-surface) 55%, transparent);
}

.section-heading {
  max-width: 720px;
  margin-bottom: 42px;
}

.section-heading h2 {
  margin: 14px 0 12px;
  color: var(--portal-text);
  font-size: clamp(30px, 4vw, 46px);
  letter-spacing: -0.035em;
  line-height: 1.12;
}

.section-heading p {
  margin: 0;
  color: var(--portal-muted);
  font-size: 16px;
  line-height: 1.7;
}

.capability-grid,
.safety-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.capability-card,
.safety-card {
  position: relative;
  min-height: 230px;
  padding: 24px;
  border: 1px solid var(--portal-border);
  border-radius: 13px;
  background: var(--portal-surface);
}

.capability-number {
  color: var(--portal-blue);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.12em;
}

.capability-card h3,
.safety-card h3 {
  margin: 38px 0 11px;
  color: var(--portal-text);
  font-size: 19px;
}

.capability-card p,
.safety-card p {
  margin: 0;
  color: var(--portal-muted);
  font-size: 14px;
  line-height: 1.7;
}

.capability-state {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 5px 8px;
  border: 1px solid rgba(40, 198, 164, 0.24);
  border-radius: 999px;
  color: var(--portal-teal);
  background: rgba(40, 198, 164, 0.08);
  font-size: 10px;
  font-weight: 700;
}

.capability-state.readonly {
  border-color: rgba(245, 165, 36, 0.26);
  color: var(--portal-amber);
  background: rgba(245, 165, 36, 0.08);
}

.flow-track {
  display: grid;
  grid-template-columns: repeat(9, auto);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 30px;
  border: 1px solid var(--portal-border);
  border-radius: 14px;
  background: var(--portal-surface);
}

.flow-node {
  min-width: 128px;
  display: grid;
  gap: 6px;
  padding: 15px;
  border: 1px solid var(--portal-border-soft);
  border-radius: 10px;
  background: var(--portal-surface-raised);
}

.flow-node small {
  color: var(--portal-blue);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.1em;
}

.flow-node strong {
  font-size: 13px;
}

.flow-arrow {
  color: var(--portal-muted);
  font-size: 18px;
}

.safety-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.safety-card {
  min-height: 200px;
}

.safety-card h3 {
  margin-top: 18px;
}

.safety-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(79, 124, 255, 0.28);
  border-radius: 11px;
  color: var(--portal-blue);
  background: rgba(79, 124, 255, 0.09);
  font-size: 13px;
  font-weight: 800;
}

.portal-cta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 30px;
  padding: 38px;
  border: 1px solid rgba(79, 124, 255, 0.34);
  border-radius: 16px;
  background:
    linear-gradient(110deg, rgba(79, 124, 255, 0.14), rgba(40, 198, 164, 0.04)),
    var(--portal-surface);
}

.portal-cta h2 {
  margin: 0 0 8px;
  color: var(--portal-text);
  font-size: 30px;
  letter-spacing: -0.03em;
}

.portal-cta p {
  margin: 0;
  color: var(--portal-muted);
  line-height: 1.7;
}

.portal-footer {
  padding: 34px 0;
  border-top: 1px solid var(--portal-border-soft);
  color: var(--portal-muted);
  font-size: 12px;
}

.portal-footer-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 30px;
}

.portal-footer p {
  max-width: 720px;
  margin: 8px 0 0;
  line-height: 1.65;
}

/* Login */
.portal-login {
  display: grid;
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(420px, 0.92fr) minmax(480px, 1.08fr);
}

.login-intro {
  position: relative;
  overflow: hidden;
  display: grid;
  align-content: space-between;
  padding: 42px clamp(36px, 6vw, 86px);
  border-right: 1px solid var(--portal-border-soft);
  background:
    linear-gradient(160deg, rgba(79, 124, 255, 0.16), transparent 46%),
    color-mix(in srgb, var(--portal-surface) 84%, transparent);
}

.login-intro::after {
  position: absolute;
  right: -120px;
  bottom: -160px;
  width: 420px;
  height: 420px;
  border: 1px solid rgba(79, 124, 255, 0.18);
  border-radius: 999px;
  content: "";
  box-shadow: 0 0 0 80px rgba(79, 124, 255, 0.035), 0 0 0 160px rgba(40, 198, 164, 0.025);
}

.login-intro-copy {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: auto 0;
}

.login-intro h1 {
  margin: 22px 0 18px;
  color: var(--portal-text);
  font-size: clamp(38px, 4.8vw, 62px);
  letter-spacing: -0.05em;
  line-height: 1.04;
}

.login-intro p {
  margin: 0;
  color: var(--portal-muted);
  font-size: 16px;
  line-height: 1.75;
}

.login-guardrails {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 36px;
}

.login-guardrail {
  padding: 13px;
  border: 1px solid var(--portal-border-soft);
  border-radius: 10px;
  background: color-mix(in srgb, var(--portal-surface) 84%, transparent);
}

.login-guardrail strong,
.login-guardrail span {
  display: block;
}

.login-guardrail strong {
  font-size: 12px;
}

.login-guardrail span {
  margin-top: 4px;
  color: var(--portal-muted);
  font-size: 10px;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 40px;
}

.portal-login .login-card {
  width: min(440px, 100%);
  display: grid;
  gap: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.login-card-head {
  margin-bottom: 4px;
}

.login-card-head h2 {
  margin: 12px 0 8px;
  color: var(--portal-text);
  font-size: 30px;
  letter-spacing: -0.035em;
}

.login-card-head p {
  margin: 0;
  color: var(--portal-muted);
  line-height: 1.65;
}

.environment-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 13px;
  border: 1px solid rgba(245, 165, 36, 0.24);
  border-radius: 9px;
  color: color-mix(in srgb, var(--portal-amber) 86%, var(--portal-text));
  background: rgba(245, 165, 36, 0.07);
  font-size: 12px;
  line-height: 1.55;
}

.environment-banner::before {
  flex: 0 0 auto;
  content: "TEST";
  color: var(--portal-amber);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.portal-login .field {
  gap: 8px;
  margin: 0;
}

.portal-login .field > span {
  color: var(--portal-muted);
  font-size: 12px;
  font-weight: 650;
}

.portal-login .field input {
  min-height: 48px;
  border-color: var(--portal-border);
  border-radius: 9px;
  background: var(--portal-surface);
}

.password-field-wrap {
  position: relative;
  width: 100%;
  display: block;
}

.password-field-wrap input {
  width: 100%;
  padding-right: 58px;
}

.password-toggle {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 40px;
  height: 40px;
  border: 0;
  background: transparent;
  font-size: 11px;
}

.login-submit {
  min-height: 48px;
  margin-top: 4px;
  border-radius: 9px;
  color: #ffffff;
  background: var(--portal-blue-strong);
  font-weight: 750;
}

.login-submit:disabled {
  cursor: wait;
  opacity: 0.62;
}

.login-meta,
.login-help-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  color: var(--portal-muted);
  font-size: 12px;
}

.login-help-row a,
.login-meta a {
  color: var(--portal-blue);
}

.caps-warning {
  min-height: 18px;
  color: var(--portal-amber);
  font-size: 11px;
}

.portal-login .error {
  min-height: 20px;
  margin: -4px 0;
  color: var(--portal-red);
  font-size: 12px;
}

.login-panel-tools {
  position: absolute;
  top: 20px;
  right: 22px;
}

@media (max-width: 1000px) {
  .portal-header-inner {
    grid-template-columns: auto 1fr auto;
    gap: 12px;
  }

  .nav-toggle {
    display: inline-grid;
  }

  .portal-nav {
    position: absolute;
    top: 72px;
    right: 20px;
    left: 20px;
    display: none;
    flex-direction: column;
    align-items: stretch;
    padding: 10px;
    border: 1px solid var(--portal-border);
    border-radius: 12px;
    background: var(--portal-surface);
    box-shadow: var(--portal-shadow);
  }

  .portal-nav.is-open {
    display: flex;
  }

  .portal-nav a {
    padding: 12px;
  }

  .portal-hero-grid {
    grid-template-columns: 1fr;
    gap: 42px;
  }

  .market-stage {
    max-width: 680px;
  }

  .capability-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .flow-track {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    transform: rotate(90deg);
    justify-self: center;
  }

  .login-page {
    grid-template-columns: 1fr;
  }

  .login-intro {
    min-height: 420px;
    border-right: 0;
    border-bottom: 1px solid var(--portal-border-soft);
  }
}

@media (max-width: 720px) {
  .portal-container {
    width: min(100% - 28px, 1180px);
  }

  .portal-header-inner {
    min-height: 64px;
  }

  .portal-logo-copy small,
  .portal-actions > .portal-button.ghost {
    display: none;
  }

  .portal-nav {
    top: 64px;
    right: 14px;
    left: 14px;
  }

  .portal-hero {
    padding: 62px 0 46px;
  }

  .portal-hero h1 {
    font-size: 42px;
  }

  .portal-hero-copy > p {
    font-size: 16px;
  }

  .market-stage {
    border-radius: 12px;
  }

  .candle-board {
    min-height: 270px;
    gap: 5px;
    padding-inline: 14px;
  }

  .candle:nth-child(n + 15) {
    display: none;
  }

  .portal-status-strip,
  .capability-grid,
  .safety-grid {
    grid-template-columns: 1fr;
  }

  .portal-status-item {
    min-height: 72px;
    border-right: 0;
    border-bottom: 1px solid var(--portal-border-soft);
  }

  .portal-status-item:last-child {
    border-bottom: 0;
  }

  .portal-section {
    padding: 66px 0;
  }

  .portal-cta {
    grid-template-columns: 1fr;
    padding: 26px;
  }

  .portal-footer-grid {
    flex-direction: column;
  }

  .login-intro {
    min-height: 360px;
    padding: 30px 24px;
  }

  .login-intro h1 {
    font-size: 40px;
  }

  .login-guardrails {
    grid-template-columns: 1fr;
  }

  .login-panel {
    min-height: 600px;
    padding: 72px 24px 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
