:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1b1f27;
  --panel-soft: #222833;
  --text: #f4f7fb;
  --muted: #9aa7b8;
  --border: rgba(255, 255, 255, 0.12);
  --up: #ff4f64;
  --down: #4e8dff;
  --flat: #c6ccd6;
  --shadow: rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 79, 100, 0.18), transparent 28rem),
    radial-gradient(circle at 80% 18%, rgba(78, 141, 255, 0.16), transparent 26rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Noto Sans KR", system-ui, sans-serif;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 16px 0 36px;
}

.stock-page {
  padding-top: 20px;
}

.page-nav {
  display: flex;
  margin-bottom: 12px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 8px 13px;
  text-decoration: none;
  font-weight: 800;
}

.back-link:hover {
  border-color: color-mix(in srgb, var(--tone) 50%, var(--border));
}

.hero {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.eyebrow,
.label,
.metric span,
.section-head p,
.notice,
.metric small {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.82rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.2rem, 6vw, 5.6rem);
  font-weight: 700;
  line-height: 0.98;
}

h2 {
  font-size: 1.25rem;
  font-weight: 650;
}

.subcopy {
  margin-top: 12px;
  color: #cdd5e2;
  font-size: 1rem;
}

.status {
  display: none;
  min-width: 148px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--flat);
  text-align: center;
  font-weight: 700;
}

.market-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 6px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.market-tab,
.range-tab {
  min-width: 92px;
}

.market-tab.is-selected,
.range-tab.is-selected {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.chart-actions,
.range-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.range-tabs {
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.range-tab {
  min-width: 72px;
  padding: 8px 10px;
}

.ticker-card,
.metric,
.chart-section,
.map-section,
.stock-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(27, 31, 39, 0.86);
  box-shadow: 0 22px 60px var(--shadow);
  backdrop-filter: blur(18px);
}

.ticker-card {
  position: relative;
  overflow: hidden;
  height: 256px;
  padding: 28px;
  margin-bottom: 16px;
  background: #151a22;
}

.ticker-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--tone) 26%, transparent), transparent 64%);
  pointer-events: none;
}

.ticker-top,
.range-row,
.section-head,
.metric-grid {
  position: relative;
}

.ticker-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  height: 164px;
}

.ticker-main {
  min-width: 0;
}

.label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

#price {
  display: block;
  font-size: clamp(6rem, 12vw, 8.75rem);
  letter-spacing: 0;
  line-height: 0.9;
  color: var(--tone);
  font-variant-numeric: tabular-nums;
}

.delta {
  color: var(--tone);
  font-size: clamp(2.7rem, 5vw, 4rem);
  line-height: 1.12;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.delta span {
  display: block;
}

.range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 700;
}

.range-row b {
  color: var(--text);
  font-weight: 700;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.metric {
  padding: 20px;
}

.metric span,
.metric small {
  display: block;
}

.metric strong {
  display: block;
  margin: 10px 0 6px;
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.chart-section,
.map-section,
.stock-section {
  padding: 22px;
}

.map-section,
.stock-section {
  margin-top: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

button {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  border-color: color-mix(in srgb, var(--tone) 50%, var(--border));
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

#chart {
  display: block;
  width: 100%;
  height: 380px;
  overflow: visible;
}

.market-map {
  position: relative;
  width: 100%;
  height: 680px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: #242936;
}

.sector-label {
  position: absolute;
  z-index: 2;
  padding: 3px 6px;
  color: rgba(244, 247, 251, 0.68);
  font-size: 0.74rem;
  pointer-events: none;
}

.stock-tile {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(19, 22, 30, 0.78);
  color: #fff;
  text-align: center;
  font-weight: 800;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.34);
  line-height: 1;
  padding: 0;
  border-radius: 0;
  cursor: pointer;
}

.stock-tile:hover {
  outline: 2px solid rgba(255, 255, 255, 0.68);
  outline-offset: -2px;
}

.stock-tile small {
  display: block;
  margin-top: 2px;
  font-size: 0.78em;
}

.stock-name {
  display: -webkit-box;
  max-width: calc(100% - 3px);
  max-height: calc(100% - 3px);
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow-wrap: anywhere;
}

.stock-name.is-tight small {
  display: none;
}

.stock-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-search label {
  color: var(--muted);
  font-weight: 700;
}

.stock-search input {
  width: 120px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  font-weight: 700;
}

.stock-detail {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(360px, 1.4fr);
  gap: 16px;
}

.stock-status,
.orderbook,
.minute-chart-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  padding: 18px;
}

.minute-chart-card {
  margin-top: 16px;
}

.minute-chart-tools {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.minute-chart-tools button {
  min-width: 36px;
  height: 32px;
  padding: 0;
}

.minute-chart-tools button#minute-zoom-fit {
  min-width: 48px;
  padding: 0 10px;
}

.minute-chart-tools button.is-selected {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.minute-chart-tools span {
  min-width: 52px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}

.flow-signal {
  display: grid;
  grid-template-columns: minmax(150px, 0.8fr) minmax(160px, 1fr) minmax(320px, 1.2fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
}

.flow-signal.is-hidden {
  display: none;
}

.flow-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.flow-signal strong {
  color: var(--tone);
  font-size: 1.35rem;
}

.flow-meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--down), rgba(255, 255, 255, 0.14), var(--up));
}

.flow-meter span {
  display: block;
  width: 50%;
  height: 100%;
  border-right: 3px solid var(--text);
}

.flow-signal dl {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.flow-signal dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.flow-signal dd {
  margin: 2px 0 0;
  font-weight: 900;
}

.flow-signal.up {
  --tone: var(--up);
}

.flow-signal.down {
  --tone: var(--down);
}

.flow-signal.flat {
  --tone: var(--flat);
}

.minute-chart-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  background: rgba(17, 19, 24, 0.28);
}

.minute-chart-scroll::-webkit-scrollbar {
  height: 10px;
}

.minute-chart-scroll::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.05);
}

.minute-chart-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(154, 167, 184, 0.55);
}

#minute-chart {
  display: block;
  min-width: 100%;
  height: 320px;
  overflow: visible;
}

.minute-volume-bar {
  opacity: 0.5;
}

.minute-volume-bar.up {
  fill: var(--up);
}

.minute-volume-bar.down {
  fill: var(--down);
}

.minute-candle line {
  stroke-width: 1.5;
}

.minute-candle rect {
  stroke-width: 1;
}

.minute-candle.up line,
.minute-candle.up rect {
  fill: var(--up);
  stroke: var(--up);
}

.minute-candle.down line,
.minute-candle.down rect {
  fill: var(--down);
  stroke: var(--down);
}

.stock-status > span {
  color: var(--muted);
  font-weight: 700;
}

.stock-status > strong {
  display: block;
  margin-top: 8px;
  font-size: 1.7rem;
}

.stock-price-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(132px, auto);
  align-items: center;
  gap: 14px;
  margin: 16px 0 18px;
  color: var(--tone);
}

.stock-price-row b {
  font-size: clamp(2rem, 4.2vw, 3.35rem);
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.stock-price-row span {
  display: grid;
  justify-items: end;
  gap: 3px;
  min-width: 132px;
  font-size: 1.05rem;
  line-height: 1.08;
  font-weight: 800;
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stock-price-row span span {
  min-width: 0;
  font-size: inherit;
}

.stock-facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.stock-facts div {
  min-width: 0;
}

.stock-facts dt {
  color: var(--muted);
  font-size: 0.82rem;
}

.stock-facts dd {
  margin: 4px 0 0;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  word-break: keep-all;
}

.orderbook-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.orderbook-table {
  display: grid;
  gap: 2px;
}

.orderbook-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr 46px;
  align-items: center;
  min-height: 28px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.035);
  padding: 0 8px;
  font-weight: 800;
}

.orderbook-row.ask {
  color: var(--up);
}

.orderbook-row.bid {
  color: var(--down);
}

.orderbook-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  opacity: 0.24;
  pointer-events: none;
}

.orderbook-row.ask .orderbook-bar {
  background: var(--up);
}

.orderbook-row.bid .orderbook-bar {
  background: var(--down);
}

.orderbook-qty,
.orderbook-price,
.orderbook-side {
  position: relative;
  z-index: 1;
}

.orderbook-price {
  text-align: right;
}

.orderbook-side {
  color: var(--muted);
  text-align: right;
  font-size: 0.78rem;
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.map-legend span::before {
  content: "";
  width: 18px;
  height: 10px;
  border-radius: 2px;
}

.legend-down::before {
  background: #4168c8;
}

.legend-flat::before {
  background: #93505c;
}

.legend-up::before {
  background: #f5263f;
}

.axis,
.grid {
  stroke: rgba(255, 255, 255, 0.13);
}

.date-grid {
  stroke: rgba(255, 255, 255, 0.08);
}

.line {
  fill: none;
  stroke: var(--tone);
  stroke-width: 3;
  stroke-dasharray: 7 7;
  stroke-linecap: round;
}

.area {
  fill: color-mix(in srgb, var(--tone) 18%, transparent);
}

.volume-bar {
  opacity: 0.46;
}

.volume-bar:hover {
  opacity: 0.9;
}

.daily-volume-bar.up {
  fill: var(--up);
}

.daily-volume-bar.down {
  fill: var(--down);
}

.daily-candle line {
  stroke-width: 1.5;
}

.daily-candle rect {
  stroke-width: 1;
}

.daily-candle.up line,
.daily-candle.up rect {
  fill: var(--up);
  stroke: var(--up);
}

.daily-candle.down line,
.daily-candle.down rect {
  fill: var(--down);
  stroke: var(--down);
}

.daily-point {
  fill: transparent;
  stroke: transparent;
  cursor: crosshair;
}

.daily-point:hover {
  fill: var(--tone);
  fill-opacity: 0.9;
  stroke: rgba(255, 255, 255, 0.7);
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
}

.date-label {
  font-weight: 700;
}

.notice {
  margin-top: 14px;
  font-size: 0.88rem;
}

.is-up {
  --tone: var(--up);
}

.is-down {
  --tone: var(--down);
}

.is-flat {
  --tone: var(--flat);
}

@media (max-width: 780px) {
  .shell {
    width: min(100% - 24px, 1180px);
    padding: 12px 0 24px;
  }

  .market-tabs,
  .chart-actions,
  .range-tabs,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .market-tabs,
  .chart-actions,
  .range-tabs {
    display: flex;
  }

  .delta {
    text-align: left;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .chart-section,
  .map-section,
  .stock-section {
    padding: 18px;
  }

  .stock-detail {
    grid-template-columns: 1fr;
  }

  .stock-price-row {
    grid-template-columns: minmax(0, 1fr) minmax(104px, auto);
    align-items: center;
  }

  .stock-price-row span {
    min-width: 104px;
    font-size: 0.95rem;
  }

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

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

  #minute-chart {
    height: 280px;
  }

  .ticker-card {
    height: 228px;
    padding: 22px;
  }

  .ticker-top {
    height: 142px;
  }

  #price {
    font-size: clamp(4.1rem, 17vw, 6rem);
  }

  .delta {
    font-size: clamp(1.55rem, 7vw, 2.5rem);
  }

  #chart {
    height: 340px;
  }

  .market-map {
    height: 600px;
  }

  .map-legend {
    flex-wrap: wrap;
  }
}
