:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bg-start: var(--color-neutral-900);
  --bg-end: var(--color-neutral-950);
  --panel: rgba(35, 38, 41, 0.72);
  --panel-strong: rgba(35, 38, 41, 0.86);
  --text: var(--color-primary-100);
  --subtle: var(--color-primary-300);
  --border: rgba(148, 196, 229, 0.24);
  --accent: var(--color-primary-500);
  --accent-2: var(--color-primary-main);
  --menu-btn-bg: rgba(35, 97, 146, 0.2);
  --menu-btn-hover-bg: rgba(35, 97, 146, 0.3);
  --menu-btn-active-bg: rgba(208, 16, 58, 0.2);
  --menu-btn-color: var(--color-primary-100);
  --menu-btn-active-color: var(--color-background-white);
}

body[data-theme='dark'] {
  --bg-start: var(--color-neutral-900);
  --bg-end: var(--color-neutral-950);
  --panel: rgba(35, 38, 41, 0.8);
  --panel-strong: rgba(35, 38, 41, 0.9);
  --text: var(--color-primary-50);
  --subtle: var(--color-primary-200);
  --border: rgba(148, 196, 229, 0.28);
  --accent: var(--color-primary-500);
  --accent-2: var(--color-primary-main);
  --menu-btn-bg: rgba(35, 97, 146, 0.28);
  --menu-btn-hover-bg: rgba(35, 97, 146, 0.4);
  --menu-btn-active-bg: rgba(208, 16, 58, 0.34);
  --menu-btn-color: var(--color-primary-50);
  --menu-btn-active-color: var(--color-background-white);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  font-family: var(--font-geist-sans);
  color: var(--text);
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 14% 16%, rgba(208, 16, 58, 0.1), transparent 36%),
    radial-gradient(circle at 82% 20%, rgba(35, 97, 146, 0.14), transparent 34%),
    linear-gradient(160deg, var(--bg-start), var(--bg-end));
}

body[data-theme='dark'] {
  background:
    radial-gradient(circle at 12% 18%, rgba(208, 16, 58, 0.14), transparent 38%),
    radial-gradient(circle at 84% 14%, rgba(35, 97, 146, 0.2), transparent 36%),
    linear-gradient(160deg, var(--color-neutral-900), var(--color-neutral-950));
}

.mobile-sheet-toggle,
.mobile-sheet-handle {
  display: none;
}

.mobile-sheet-panel {
  display: contents;
}

.heading-banner {
  display: contents;
}

#scene {
  display: block;
  width: 50vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  cursor: default;
}

#scene:active {
  cursor: default;
}

.graph-loading {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 30;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(148, 196, 229, 0.28);
  background: rgba(35, 38, 41, 0.72);
  color: rgba(229, 239, 249, 0.95);
  font-family: var(--font-geist-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  pointer-events: none;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.graph-loading.hidden {
  opacity: 0;
  visibility: hidden;
}

.brand-logo {
  position: fixed;
  top: calc(28px + var(--safe-top));
  left: 16px;
  z-index: 17;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body[data-theme='dark'] .brand-logo {
  background: transparent;
  box-shadow: none;
}

.brand-logo img {
  display: none;
  width: clamp(128px, 14vw, 168px);
  max-height: 30px;
  height: auto;
}

body[data-theme='dark'] .brand-logo .logo-light {
  display: block;
}

body:not([data-theme='dark']) .brand-logo .logo-dark {
  display: block;
}

.cta-button {
  position: fixed;
  left: 50%;
  bottom: calc(62px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 14;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 0;
  padding: 12px 28px;
  border-radius: 10px;
  border: 1px solid var(--color-secondary-400);
  background: var(--color-secondary-main);
  color: var(--color-text-on-accent);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  text-decoration: none;
  box-shadow: 0 12px 24px rgba(208, 16, 58, 0.32);
  transition: filter 180ms ease;
  white-space: nowrap;
}

.cta-button:hover {
  filter: brightness(1.05);
}

.cta-button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.9);
  outline-offset: 2px;
}

.cta-description {
  position: fixed;
  top: 1px;
  left: 0;
  transform: none;
  z-index: 15;
  margin: 0;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-on-accent);
  text-align: center;
  width: 100vw;
  line-height: 1.4;
  white-space: normal;
  padding: 12px 180px;
  border: none;
  border-radius: 0;
  background:
    linear-gradient(135deg, rgba(35, 97, 146, 0.16), rgba(208, 16, 58, 0.12)),
    rgba(35, 38, 41, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: none;
  text-shadow: 
    0 0 12px rgba(35, 97, 146, 0.46),
    0 0 20px rgba(208, 16, 58, 0.34),
    0 2px 4px rgba(0, 0, 0, 0.42);
}

.cta-description strong {
  font-size: 1.2em;
  font-weight: 500;
}

.cta-description em {
  font-size: 0.84em;
  font-style: normal;
  font-weight: 300;
  text-transform: none;
}

body[data-theme='dark'] .cta-description {
  color: var(--color-text-on-accent);
  background:
    linear-gradient(135deg, rgba(35, 97, 146, 0.16), rgba(208, 16, 58, 0.12)),
    rgba(35, 38, 41, 0.42);
  box-shadow: none;
  text-shadow: 
    0 0 12px rgba(35, 97, 146, 0.46),
    0 0 20px rgba(208, 16, 58, 0.34),
    0 2px 4px rgba(0, 0, 0, 0.42);
}

.menu {
  position: fixed;
  top: calc(114px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(456px, 94vw);
  padding: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border: none;
  border-radius: 14px;
  background:
    linear-gradient(
      to right,
      rgba(208, 16, 58, 0) 0%,
      rgba(208, 16, 58, 0) 26%,
      rgba(208, 16, 58, 0.14) 34%,
      rgba(208, 16, 58, 0.28) 50%,
      rgba(208, 16, 58, 0.14) 66%,
      rgba(208, 16, 58, 0) 74%,
      rgba(208, 16, 58, 0) 100%
    ),
    var(--panel);
  backdrop-filter: blur(7px);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0,
    #000 24px,
    #000 calc(100% - 24px),
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0,
    #000 24px,
    #000 calc(100% - 24px),
    transparent 100%
  );
}

.menu::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: linear-gradient(
    to right,
    rgba(208, 16, 58, 0) 0%,
    rgba(208, 16, 58, 0) 29%,
    rgba(208, 16, 58, 0.08) 37%,
    rgba(208, 16, 58, 0.18) 50%,
    rgba(208, 16, 58, 0.08) 63%,
    rgba(208, 16, 58, 0) 71%,
    rgba(208, 16, 58, 0) 100%
  );
  pointer-events: none;
}

.menu::after {
  content: none;
}

.menu::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.ip-score-bar {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translateX(calc(-170% - 300px)) translateY(-50%);
  z-index: 11;
  width: 216px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  pointer-events: none;
  color: var(--color-primary-300);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  font-family: var(--font-geist-mono);
  background: rgba(35, 97, 146, 0.12);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  border-radius: 8px;
  border: 1px solid rgba(35, 97, 146, 0.4);
  box-shadow:
    0 0 8px rgba(35, 97, 146, 0.25),
    0 0 24px rgba(35, 97, 146, 0.12),
    inset 0 0 8px rgba(35, 97, 146, 0.06);
}

body[data-theme='dark'] .ip-score-bar {
  background: rgba(35, 38, 41, 0.34);
  border: 1px solid rgba(35, 97, 146, 0.35);
  box-shadow:
    0 0 10px rgba(35, 97, 146, 0.35),
    0 0 30px rgba(35, 97, 146, 0.18),
    inset 0 0 10px rgba(35, 97, 146, 0.08);
}

.ip-score-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 4px;
  text-align: left;
}

.ip-score-row + .ip-score-row {
  margin-top: 10px;
}

.graph-info-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 2px;
  text-align: left;
  margin-top: 8px;
}

.graph-info-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: rgba(229, 239, 249, 0.72);
  text-transform: uppercase;
}

.graph-info-value {
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.01em;
  color: rgba(229, 239, 249, 0.9);
}

body[data-theme='dark'] .graph-info-label {
  color: rgba(229, 239, 249, 0.72);
}

body[data-theme='dark'] .graph-info-value {
  color: rgba(229, 239, 249, 0.9);
}

.ip-score-label {
  display: block;
  width: 100%;
  color: var(--color-secondary-300);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.ip-score-separator {
  display: none;
}

.ip-score-suffix {
  color: var(--color-primary-300);
}

.ip-score-row:first-child {
  flex-direction: column;
}

.ip-score-option {
  display: block;
  color: var(--color-primary-300);
}

.ip-score-option.active {
  color: var(--color-secondary-300);
}

.ip-score-value {
  color: var(--color-secondary-300);
}

body[data-theme='dark'] .ip-score-separator {
  display: none;
}

body[data-theme='dark'] .ip-score-bar,
body[data-theme='dark'] .ip-score-suffix,
body[data-theme='dark'] .ip-score-option {
  color: var(--color-primary-300);
}

body[data-theme='dark'] .ip-score-label {
  color: var(--color-secondary-300);
}

body[data-theme='dark'] .ip-score-option.active,
body[data-theme='dark'] .ip-score-value {
  color: var(--color-secondary-300);
}

.layout-dock {
  position: fixed;
  right: 10px;
  bottom: 12px;
  z-index: 12;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
}

.layout-toggle {
  width: 0;
  height: 0;
  padding: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 12px solid rgba(148, 196, 229, 0.62);
  background: transparent;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 180ms ease;
}

.layout-toggle:hover {
  opacity: 0.88;
}

.layout-menu {
  position: absolute;
  right: 0;
  bottom: 18px;
  z-index: 13;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  min-width: 210px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-strong);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.24);
}

.layout-menu.open {
  display: flex;
}

.menu-btn {
  flex: 0 0 auto;
  width: 220px;
  border: none;
  background: transparent;
  color: var(--menu-btn-color);
  padding: 8px 11px;
  border-radius: 0;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  text-align: center;
  cursor: pointer;
  transition:
    background-color 240ms ease,
    color 240ms ease,
    opacity 240ms ease;
  will-change: transform;
}

.menu-btn:hover {
  background: transparent;
}

.layout-menu .menu-btn {
  width: 100%;
  border: 1px solid rgba(148, 196, 229, 0.22);
}

.layout-menu .menu-btn:hover {
  border-color: rgba(35, 97, 146, 0.46);
}

.menu-btn.active {
  background: transparent;
  color: var(--color-secondary-400);
  border: none;
  box-shadow: none;
}

.menu .menu-btn,
.menu .menu-btn:hover,
.menu .menu-btn:active,
.menu .menu-btn:focus,
.menu .menu-btn:focus-visible,
.menu .menu-btn.active {
  appearance: none;
  -webkit-appearance: none;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
}

.menu .menu-btn::-moz-focus-inner {
  border: 0;
}

.layout-btn {
  background: rgba(35, 38, 41, 0.92);
  border-color: rgba(148, 196, 229, 0.28);
}

.graph-help {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 15;
  width: min(64vw, 546px);
  text-align: center;
  color: rgba(255, 255, 255, 0.96);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.01em;
  pointer-events: none;
  padding: 0;
}

.graph-help .help-desktop {
  display: inline;
}

.graph-help .help-mobile {
  display: none;
}

body[data-theme='dark'] .graph-help {
  color: rgba(255, 255, 255, 0.96);
}

@media (pointer: coarse) {
  #scene {
    cursor: default;
  }
}

.theme-toggle {
  position: fixed;
  right: 14px;
  top: calc(14px + var(--safe-top));
  z-index: 12;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  backdrop-filter: blur(7px);
  display: none;
}

.theme-toggle:hover {
  border-color: rgba(35, 97, 146, 0.5);
}

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

body[data-theme='dark'] .theme-toggle::before {
  content: '☾';
}

@keyframes mobile-handle-pulse {
  0% {
    box-shadow:
      0 0 0 0 rgba(208, 16, 58, 0.45),
      0 0 0 0 rgba(35, 97, 146, 0.35);
  }
  70% {
    box-shadow:
      0 0 0 8px rgba(208, 16, 58, 0),
      0 0 0 16px rgba(35, 97, 146, 0);
  }
  100% {
    box-shadow:
      0 0 0 0 rgba(208, 16, 58, 0),
      0 0 0 0 rgba(35, 97, 146, 0);
  }
}

@media (max-width: 900px) {
  #scene {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
  }

  .mobile-sheet-toggle {
    display: none;
  }

  .mobile-sheet-handle {
    display: none;
  }

  .mobile-sheet-handle::before {
    content: none;
  }

  .mobile-sheet-panel {
    display: contents;
  }

  .mobile-sheet-toggle:checked + .mobile-sheet-handle {
    border-color: rgba(208, 16, 58, 0.46);
    background: rgba(35, 38, 41, 0.88);
  }

  .mobile-sheet-toggle:checked ~ .mobile-sheet-panel {
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }

  .mobile-sheet-panel .menu {
    display: none;
  }

  .mobile-sheet-panel .ip-score-bar {
    position: fixed;
    top: calc(144px + var(--safe-top));
    left: 10px;
    right: auto;
    transform: none;
    width: fit-content;
    max-width: min(62vw, 240px);
    margin: 0;
    padding: 9px 10px;
    text-align: left;
    background: rgba(35, 38, 41, 0.82);
    border: 1px solid rgba(148, 196, 229, 0.22);
    border-radius: 10px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
    z-index: 15;
  }

  .mobile-sheet-panel .ip-score-bar .graph-info-row {
    display: none;
  }

  .mobile-sheet-panel .ip-score-label {
    font-size: 8.4px;
  }

  .mobile-sheet-panel .graph-info-label {
    font-size: 7.2px;
  }

  .mobile-sheet-panel .graph-info-value {
    font-size: 9.6px;
  }

  .mobile-sheet-panel .ip-score-bar .ip-score-row,
  .mobile-sheet-panel .ip-score-bar .graph-info-row {
    align-items: flex-start;
    justify-content: flex-start;
    text-align: left;
  }

  .mobile-sheet-panel .graph-help {
    display: block;
    position: fixed;
    right: 10px;
    left: auto;
    bottom: calc(120px + var(--safe-bottom));
    transform: none;
    z-index: 15;
    width: fit-content;
    max-width: min(58vw, 230px);
    margin-top: 0;
    font-size: 7.2px;
    line-height: 1.35;
    font-family: var(--font-geist-mono);
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 9px 10px;
    text-align: left;
    color: rgba(229, 239, 249, 0.9);
    background:
      linear-gradient(
        to right,
        rgba(208, 16, 58, 0) 0%,
        rgba(208, 16, 58, 0) 26%,
        rgba(208, 16, 58, 0.14) 34%,
        rgba(208, 16, 58, 0.24) 50%,
        rgba(208, 16, 58, 0.14) 66%,
        rgba(208, 16, 58, 0) 74%,
        rgba(208, 16, 58, 0) 100%
      ),
      var(--panel);
    border: none;
    border-radius: 14px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
  }

  .mobile-sheet-panel .graph-help .help-desktop {
    display: none;
  }

  .mobile-sheet-panel .graph-help .help-mobile {
    display: inline;
  }

  .mobile-sheet-panel .graph-help strong {
    display: inline-block;
    min-width: 40px;
    font-size: 7.2px;
    letter-spacing: 0.08em;
    color: rgba(229, 239, 249, 0.78);
  }

  .ip-score-bar {
    font-size: 7.2px;
  }

  .brand-logo {
    position: static;
    top: auto;
    left: auto;
    transform: none;
    padding: 0;
    z-index: auto;
  }

  .cta-description {
    position: static;
    top: auto;
    left: auto;
    transform: none;
    margin: 0;
    font-size: 11px;
    width: auto;
    padding: 0;
    border: 0;
    border-radius: 0;
    line-height: 1.2;
    text-align: right;
    background: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    box-shadow: none;
    text-shadow: none;
  }

  .heading-banner {
    position: fixed;
    top: calc(14px + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 17;
    width: min(94vw, 560px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 10px;
    background:
      linear-gradient(135deg, rgba(35, 97, 146, 0.16), rgba(208, 16, 58, 0.12)),
      rgba(35, 38, 41, 0.42);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  .heading-banner .brand-logo img {
    width: 112px;
    max-height: 24px;
  }

  .heading-banner .cta-description strong {
    font-size: 1.08em;
  }

  .heading-banner .cta-description em {
    font-size: 0.82em;
  }

  .menu {
    top: calc(64px + var(--safe-top));
    width: min(94vw, 680px);
    left: 50%;
    transform: translateX(-50%);
    justify-content: flex-start;
    padding: 8px 10px;
    gap: 6px;
  }

  .menu-btn {
    width: auto;
    min-width: max-content;
    padding: 8px 12px;
    min-height: 44px;
    font-size: 11px;
  }

  .theme-toggle {
    top: calc(10px + var(--safe-top));
    right: 10px;
    width: 44px;
    height: 44px;
  }

  .cta-button {
    font-size: 13px;
    padding: 11px 16px;
    min-height: 46px;
    width: calc(100vw - 22px);
    max-width: 360px;
    left: 50%;
    bottom: calc(64px + var(--safe-bottom));
    transform: translateX(-50%);
    text-align: center;
  }

  .layout-dock {
    right: 8px;
    bottom: calc(66px + 44px + var(--safe-bottom));
  }

  .graph-loading {
    top: calc(56% + var(--safe-top));
    font-size: 11px;
    padding: 5px 8px;
  }
}
