:root {
  --page: #f7f7f3;
  --surface: #ffffff;
  --surface-subtle: #f0f1ed;
  --ink: #202124;
  --muted: #686b70;
  --rule: #dadce0;
  --focus: #1a73e8;
  --green: #0f9d78;
  --red: #d9304f;
  --terminal: #0d1017;
  --terminal-rule: #242936;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family:
    "Avenir Next",
    "PingFang TC",
    "Noto Sans TC",
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
a {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(26, 115, 232, .35);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  text-decoration: none;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.product-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto minmax(180px, 1fr);
  min-height: 64px;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--rule);
  background: rgba(247, 247, 243, .94);
  backdrop-filter: blur(18px);
}

.product-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  width: max-content;
  color: var(--ink);
  font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.02em;
  text-decoration: none;
}

.product-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 16px;
  font-weight: 900;
}

.product-nav {
  display: flex;
  align-self: stretch;
  gap: 6px;
}

.nav-link {
  position: relative;
  display: flex;
  min-width: 104px;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.nav-link::after {
  position: absolute;
  right: 18px;
  bottom: -1px;
  left: 18px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
  content: "";
}

.nav-link:hover {
  background: rgba(32, 33, 36, .045);
  color: var(--ink);
}

.nav-link--active {
  color: var(--ink);
}

.nav-link--active::after {
  background: var(--focus);
}

.market-status {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.market-status__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b7b9bd;
}

.market-status[data-state="ready"] .market-status__dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(15, 157, 120, .12);
}

.market-status[data-state="error"] .market-status__dot {
  background: var(--red);
}

.product-main {
  position: relative;
  width: min(100%, 1800px);
  margin: 0 auto;
}

.market-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 32px;
  padding: 34px 32px 26px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--focus);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .11em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: "Avenir Next Condensed", "DIN Condensed", "PingFang TC", sans-serif;
  font-size: clamp(32px, 4vw, 54px);
  font-weight: 750;
  letter-spacing: -.045em;
  line-height: 1;
}

.market-subtitle {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.index-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
  min-width: 340px;
  margin: 0;
}

.index-summary div {
  padding: 4px 22px;
}

.index-summary div + div {
  border-left: 1px solid var(--rule);
}

.index-summary dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .1em;
}

.index-summary dd {
  margin: 0;
  font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.035em;
  font-variant-numeric: tabular-nums;
}

.value-up {
  color: var(--green);
}

.value-down {
  color: var(--red);
}

.market-tools {
  position: relative;
  z-index: 25;
  display: grid;
  grid-template-columns: minmax(240px, 420px) 1fr auto;
  align-items: end;
  gap: 26px;
  padding: 0 32px 18px;
}

.search-wrap {
  position: relative;
}

.search-wrap label {
  display: block;
  margin: 0 0 7px 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.search-control {
  display: flex;
  height: 46px;
  align-items: center;
  gap: 11px;
  padding: 0 15px;
  border: 1px solid var(--rule);
  border-radius: 23px;
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.search-control:focus-within {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(26, 115, 232, .12);
}

.search-control svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: var(--muted);
  stroke-linecap: round;
  stroke-width: 2;
}

.search-control input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
}

.search-control input::placeholder {
  color: #8d9095;
}

.search-results {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  left: 0;
  overflow: auto;
  max-height: min(360px, 52vh);
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(32, 33, 36, .17);
}

.search-result {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  width: 100%;
  align-items: center;
  gap: 11px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.search-result:hover,
.search-result[aria-selected="true"] {
  background: #eef3fc;
}

.search-result img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
}

.search-result strong,
.search-result span {
  display: block;
}

.search-result strong {
  font-size: 13px;
}

.search-result span {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result__change {
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.search-empty {
  padding: 18px 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.map-key {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 8px;
  padding-bottom: 11px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.map-key__gradient {
  width: 116px;
  height: 7px;
  border-radius: 7px;
  background: linear-gradient(90deg, #e6463b, #454b57 50%, #2bc962);
}

.archive-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 16px;
  color: var(--focus);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.archive-link svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 160ms ease;
}

.archive-link:hover svg {
  transform: translateX(3px);
}

.map-region {
  position: relative;
  min-height: min(72vh, 930px);
  overflow: hidden;
  border-top: 1px solid var(--terminal-rule);
  border-bottom: 1px solid var(--terminal-rule);
  background: var(--terminal);
}

.market-map {
  width: 100%;
  height: min(72vh, 930px);
  min-height: 580px;
}

.map-loading,
.map-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  padding: 32px;
  color: #eef1f7;
  text-align: center;
}

.map-loading strong,
.map-error strong {
  margin-top: 8px;
  font-size: 16px;
}

.map-loading > span:last-child,
.map-error p {
  margin: 0;
  color: #969dab;
  font-size: 13px;
}

.loading-orbit {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, .14);
  border-top-color: #8ab4f8;
  border-radius: 50%;
  animation: orbit 900ms linear infinite;
}

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

.secondary-button {
  min-height: 42px;
  margin-top: 10px;
  padding: 0 18px;
  border: 1px solid #5f6673;
  border-radius: 21px;
  background: transparent;
  color: #e6e9ef;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.secondary-button:hover {
  background: rgba(255, 255, 255, .08);
}

.stock-detail {
  position: fixed;
  top: 80px;
  right: 18px;
  z-index: 35;
  width: min(360px, calc(100vw - 36px));
  padding: 24px;
  border: 1px solid var(--rule);
  border-radius: 20px;
  background: rgba(255, 255, 255, .97);
  box-shadow: 0 22px 64px rgba(24, 28, 36, .24);
  backdrop-filter: blur(16px);
}

.detail-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.detail-close:hover {
  background: var(--surface-subtle);
}

.detail-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.detail-identity {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 15px;
  padding-right: 32px;
}

.detail-identity img {
  width: 52px;
  height: 52px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
}

.detail-identity p {
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-identity h2 {
  margin: 2px 0;
  font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif;
  font-size: 30px;
  line-height: 1;
}

.detail-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 24px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--rule);
}

.detail-metrics div {
  min-width: 0;
}

.detail-metrics div + div {
  padding-left: 14px;
  border-left: 1px solid var(--rule);
}

.detail-metrics dt {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 10px;
}

.detail-metrics dd {
  overflow: hidden;
  margin: 0;
  font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif;
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-note {
  margin: 20px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.product-footer {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  width: min(100%, 1800px);
  margin: 0 auto;
  padding: 16px 32px 22px;
  color: var(--muted);
  font-size: 10px;
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

/* Homepage: keep the heatmap as the primary, edge-to-edge product surface. */
.home-page {
  height: 100dvh;
  overflow: hidden;
  background: var(--terminal);
}

.home-page .product-header {
  min-height: 52px;
  padding: 0 16px;
}

.home-page .product-brand {
  gap: 9px;
  font-size: 18px;
}

.home-page .product-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  font-size: 14px;
}

.home-page .nav-link {
  min-width: 92px;
  padding: 0 12px;
  font-size: 13px;
}

.home-page .product-main {
  width: 100%;
  height: calc(100dvh - 52px);
  margin: 0;
}

.home-page .map-region {
  width: 100vw;
  height: 100%;
  min-height: 0;
  border: 0;
}

.home-page .market-map {
  width: 100vw;
  height: 100%;
  min-height: 0;
}

.market-overview {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
  color: #fff;
}

.market-overview summary {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 13px;
  padding: 5px 9px 5px 14px;
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 23px;
  background: rgba(12, 16, 23, .76);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .16);
  backdrop-filter: blur(14px);
  cursor: pointer;
  list-style: none;
}

.market-overview summary::-webkit-details-marker {
  display: none;
}

.market-overview summary > svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: rgba(255, 255, 255, .72);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform 160ms ease;
}

.market-overview[open] summary > svg {
  transform: rotate(180deg);
}

.overview-label {
  color: rgba(255, 255, 255, .7);
  font-size: 11px;
  font-weight: 700;
}

.overview-index {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding-left: 13px;
  border-left: 1px solid rgba(255, 255, 255, .15);
  font-variant-numeric: tabular-nums;
}

.overview-index > span {
  color: rgba(255, 255, 255, .58);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .05em;
}

.overview-index strong {
  font-family: "Avenir Next Condensed", "DIN Condensed", sans-serif;
  font-size: 14px;
  font-weight: 800;
}

.market-overview__panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: min(440px, calc(100vw - 28px));
  padding: 20px 22px;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 16px;
  background: rgba(12, 16, 23, .93);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
  backdrop-filter: blur(18px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-5px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.market-overview[open] .market-overview__panel,
.market-overview:hover .market-overview__panel,
.market-overview:focus-within .market-overview__panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.market-overview__panel .eyebrow {
  color: #8ab4f8;
}

.market-overview__panel h1 {
  font-size: clamp(30px, 4vw, 46px);
}

.market-overview__panel .market-subtitle {
  color: rgba(255, 255, 255, .66);
}

.home-page .market-tools {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 32;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
}

.home-page .search-wrap {
  width: 44px;
  transition: width 180ms ease;
}

.home-page .search-wrap:hover,
.home-page .search-wrap:focus-within {
  width: min(320px, calc(100vw - 230px));
}

.home-page .search-control {
  height: 42px;
  padding: 0 12px;
  border-color: rgba(255, 255, 255, .15);
  background: rgba(12, 16, 23, .78);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .15);
  backdrop-filter: blur(14px);
}

.home-page .search-control svg {
  flex: 0 0 18px;
  stroke: rgba(255, 255, 255, .76);
}

.home-page .search-control input {
  min-width: 0;
  color: #fff;
  opacity: 0;
  transition: opacity 120ms ease;
}

.home-page .search-wrap:hover input,
.home-page .search-wrap:focus-within input {
  opacity: 1;
}

.home-page .search-control input::placeholder {
  color: rgba(255, 255, 255, .5);
}

.home-page .search-results {
  right: 0;
  left: auto;
  width: min(340px, calc(100vw - 28px));
}

.home-page .map-key {
  gap: 6px;
  height: 42px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 22px;
  background: rgba(12, 16, 23, .72);
  color: rgba(255, 255, 255, .62);
  backdrop-filter: blur(14px);
  opacity: .42;
  transition: opacity 160ms ease;
}

.home-page .map-key:hover {
  opacity: 1;
}

.home-page .map-key__gradient {
  width: 70px;
  height: 5px;
}

.home-page .archive-link {
  display: grid;
  width: 42px;
  min-height: 42px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .15);
  border-radius: 50%;
  background: rgba(12, 16, 23, .78);
  color: rgba(255, 255, 255, .82);
  box-shadow: 0 8px 26px rgba(0, 0, 0, .15);
  backdrop-filter: blur(14px);
}

.home-page .archive-link span {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
}

.home-page .archive-link svg {
  width: 18px;
  height: 18px;
}

.home-page .stock-detail {
  top: 66px;
}

.home-page .product-footer {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 28;
  display: flex;
  width: auto;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 16px;
  background: rgba(12, 16, 23, .66);
  color: rgba(255, 255, 255, .52);
  backdrop-filter: blur(12px);
  opacity: .22;
  transition: opacity 160ms ease;
}

.home-page .product-footer:hover,
.home-page .product-footer:focus-within {
  opacity: 1;
}

@media (max-width: 820px) {
  .product-header {
    grid-template-columns: 1fr auto;
    min-height: 60px;
    padding: 0 16px;
  }

  .product-brand {
    font-size: 18px;
  }

  .product-mark {
    width: 32px;
    height: 32px;
  }

  .product-nav {
    gap: 0;
  }

  .nav-link {
    min-width: auto;
    padding: 0 10px;
    font-size: 12px;
  }

  .nav-link::after {
    right: 9px;
    left: 9px;
  }

  .market-status {
    grid-column: 1 / -1;
    display: none;
  }

  .market-heading {
    grid-template-columns: 1fr;
    gap: 22px;
    padding: 25px 18px 20px;
  }

  .market-subtitle {
    max-width: 34ch;
  }

  .index-summary {
    min-width: 0;
  }

  .index-summary div {
    padding: 0 16px 0 0;
  }

  .index-summary div + div {
    padding: 0 0 0 16px;
  }

  .index-summary dd {
    font-size: 27px;
  }

  .market-tools {
    grid-template-columns: 1fr auto;
    gap: 12px;
    padding: 0 18px 16px;
  }

  .search-wrap {
    grid-column: 1 / -1;
  }

  .map-key {
    justify-self: start;
    padding: 0;
  }

  .archive-link {
    min-height: 40px;
    padding-right: 0;
  }

  .map-region {
    min-height: 66vh;
  }

  .market-map {
    height: 66vh;
    min-height: 560px;
  }

  .stock-detail {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: none;
    padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
    border-width: 1px 0 0;
    border-radius: 22px 22px 0 0;
  }

  .detail-identity {
    padding-right: 44px;
  }

  .product-footer {
    display: grid;
    padding: 14px 18px 22px;
  }

  .home-page .product-header {
    min-height: 52px;
    padding: 0 10px;
  }

  .home-page .product-brand > span:last-child {
    display: none;
  }

  .home-page .product-nav {
    justify-self: end;
  }

  .home-page .nav-link {
    min-width: auto;
    padding: 0 8px;
    font-size: 11px;
  }

  .home-page .product-main {
    height: calc(100dvh - 52px);
  }

  .market-overview {
    top: 8px;
    left: 8px;
  }

  .market-overview summary {
    min-height: 40px;
    gap: 8px;
    padding: 4px 8px 4px 10px;
  }

  .overview-label,
  .overview-index:nth-of-type(3) {
    display: none;
  }

  .overview-index {
    gap: 5px;
    padding-left: 0;
    border-left: 0;
  }

  .market-overview__panel {
    width: min(350px, calc(100vw - 16px));
    padding: 18px;
  }

  .market-overview__panel h1 {
    font-size: 30px;
  }

  .home-page .market-tools {
    top: 8px;
    right: 8px;
    gap: 6px;
  }

  .home-page .search-wrap:hover,
  .home-page .search-wrap:focus-within {
    width: calc(100vw - 72px);
  }

  .home-page .search-wrap:focus-within {
    position: fixed;
    top: 60px;
    right: 8px;
  }

  .home-page .map-key {
    display: none;
  }

  .home-page .stock-detail {
    top: auto;
  }

  .home-page .product-footer {
    right: 8px;
    bottom: 7px;
    display: block;
    max-width: calc(100vw - 16px);
    padding: 5px 8px;
  }

  .home-page .product-footer span:last-child {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .loading-orbit {
    animation-duration: 1600ms;
  }
}
