@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+KR:wght@400;500;600&display=swap");

:root {
  color-scheme: light dark;
  --bg: #f6f8fb;
  --ink: #202124;
  --muted: #5f6368;
  --line: #dfe5ee;
  --panel: #ffffff;
  --panel-soft: #f5f7fa;
  --metric-bg: #f7f9fc;
  --metric-line: #edf1f7;
  --green: #0b8043;
  --green-soft: #e6f4ea;
  --red: #b3261e;
  --red-soft: #fceeee;
  --accent: #1967d2;
  --accent-soft: #e8f0fe;
  --shadow: 0 2px 8px rgba(60, 64, 67, 0.12), 0 1px 2px rgba(60, 64, 67, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124;
    --ink: #e8eaed;
    --muted: #9aa0a6;
    --line: #3c4043;
    --panel: #292a2d;
    --panel-soft: #303134;
    --metric-bg: #242528;
    --metric-line: #34383d;
    --green: #81c995;
    --green-soft: #17351f;
    --red: #f2a39b;
    --red-soft: #3a1f1c;
    --accent: #8ab4f8;
    --accent-soft: #1b2f4a;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans KR", ui-sans-serif, system-ui, sans-serif;
  font-weight: 400;
  letter-spacing: 0;
}

html {
  font-family: "IBM Plex Sans KR", ui-sans-serif, system-ui, sans-serif;
}

body,
button,
input,
select,
textarea {
  font-family: "IBM Plex Sans KR", ui-sans-serif, system-ui, sans-serif !important;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 68px;
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 1.48rem;
  line-height: 1.25;
  font-weight: 500;
}

.refresh-state {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.refresh-state[data-connection="error"] {
  color: var(--red);
}

.market-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.market-card {
  min-height: 278px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  display: grid;
  gap: 14px;
  min-width: 0;
  overflow: hidden;
}

.market-head {
  display: block;
  min-width: 0;
}

.market-title-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.market-title-line > div {
  min-width: 0;
}

.chart-select {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
}

.chart-select[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: var(--accent-soft);
  color: var(--accent);
}

h2 {
  margin-bottom: 3px;
  font-size: 1.26rem;
  line-height: 1.2;
  font-weight: 500;
}

.label,
.metrics dt {
  color: var(--muted);
}

.label {
  margin-bottom: 0;
  font-size: 0.9rem;
  line-height: 1.25;
}

.price-row {
  display: grid;
  gap: 6px;
  min-height: 96px;
  min-width: 0;
  align-content: center;
  justify-items: center;
  margin: 4px 0;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.price-label {
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1;
  text-transform: uppercase;
}

.price {
  max-width: 100%;
  font-size: clamp(1.72rem, 3vw, 2.18rem);
  line-height: 1;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.usd-price {
  max-width: 100%;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.change {
  width: auto;
  min-width: 88px;
  padding: 0;
  background: transparent;
  color: var(--red);
  font-size: 0.92rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.change[data-trend="up"] {
  color: var(--green);
}

.source-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.source-pill {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  overflow: hidden;
}

.source-label {
  display: block;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-pill strong {
  display: block;
  margin-top: 5px;
  max-width: 100%;
  color: var(--ink);
  font-size: clamp(0.8rem, 1.05vw, 0.9rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.source-pill small {
  display: block;
  margin-top: 4px;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-pill[data-status="live"] {
  border-color: color-mix(in srgb, var(--green) 42%, var(--line));
}

.source-pill[data-status="connecting"],
.source-pill[data-status="waiting"],
.source-pill[data-status="missing"] {
  border-color: var(--line);
}

.source-pill[data-status="connecting"] strong,
.source-pill[data-status="waiting"] strong,
.source-pill[data-status="missing"] strong {
  color: var(--muted);
  font-weight: 500;
}

.spread-pill {
  background: var(--accent-soft);
  grid-column: 1 / -1;
}

.spread-pill strong {
  color: var(--accent);
}

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

.metrics div {
  min-height: 56px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  min-width: 0;
  overflow: hidden;
}

.metrics dt {
  font-size: 0.75rem;
  font-weight: 400;
}

.metrics dd {
  margin: 5px 0 0;
  max-width: 100%;
  font-size: 0.98rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.chart-panel {
  min-width: 0;
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  overflow: hidden;
}

.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.chart-title-block {
  min-width: 0;
}

.chart-title-block h2 {
  margin-bottom: 0;
  font-size: 1.12rem;
  line-height: 1.2;
}

.chart-title-block h2 span {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.interval-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(38px, 1fr));
  gap: 5px;
  min-width: min(100%, 200px);
}

.interval-button {
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}

.interval-button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: var(--accent-soft);
  color: var(--accent);
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  margin-top: 12px;
}

.chart-legend button {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
  white-space: nowrap;
}

.chart-legend button {
  cursor: pointer;
}

.chart-legend button[aria-pressed="false"] {
  opacity: 0.45;
}

.chart-legend button:disabled {
  cursor: not-allowed;
  opacity: 0.34;
}

.chart-legend button::before {
  content: "";
  width: 9px;
  height: 2px;
  margin-right: 6px;
  border-radius: 1px;
  background: currentColor;
}

.chart-legend [data-chart-toggle="hyperliquid"] {
  color: var(--green);
}

.chart-legend [data-chart-toggle="consensus"] {
  color: var(--accent);
}

.chart-legend [data-chart-toggle="binance"] {
  color: #c58af9;
}

.chart-legend [data-chart-toggle="sma"] {
  color: #fbbc04;
}

.chart-legend [data-chart-toggle="ema"] {
  color: #fdd663;
}

.chart-stage {
  position: relative;
  min-width: 0;
  height: clamp(620px, 68vh, 760px);
  min-height: 600px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--metric-bg);
  overflow: hidden;
}

.chart-canvas {
  width: 100%;
  height: 100%;
  min-width: 0;
  overflow: hidden;
  touch-action: none;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--panel) 82%, transparent);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.chart-empty[hidden] {
  display: none;
}

@media (max-width: 980px) {
  .market-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-stage {
    height: clamp(560px, 64vh, 680px);
    min-height: 540px;
  }
}

@media (max-width: 640px) {
  body {
    min-height: 100svh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .shell {
    width: min(100% - 20px, 1120px);
    min-height: 100svh;
    padding: 10px 0 18px;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 0;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
  }

  h1 {
    margin-bottom: 0;
    font-size: 1.12rem;
  }

  .market-grid {
    min-height: 0;
    margin-top: 8px;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    gap: 8px;
  }

  .market-card {
    min-height: 0;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: minmax(136px, 0.9fr) minmax(0, 1.1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "head price"
      "sources sources";
    column-gap: 13px;
    row-gap: 10px;
    align-content: center;
    align-items: center;
    overflow: hidden;
  }

  .market-card:last-child {
    border-bottom: 1px solid var(--line);
  }

  .market-head {
    grid-area: head;
    display: block;
    min-width: 0;
  }

  .market-title-line {
    gap: 8px;
  }

  .chart-select {
    min-height: 26px;
    padding: 0 8px;
    border-radius: 8px;
    font-size: 0.68rem;
  }

  h2 {
    margin-bottom: 5px;
    font-size: 1.08rem;
    line-height: 1.16;
    word-break: keep-all;
    overflow-wrap: normal;
  }

  .label {
    display: block;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  .price-row {
    margin: 0;
    padding: 0;
    border: 0;
    grid-area: price;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "label label"
      "price price"
      "usd change";
    justify-items: end;
    align-content: center;
    gap: 5px 10px;
  }

  .price-label {
    grid-area: label;
    align-self: end;
    color: var(--muted);
    font-size: 0.58rem;
    letter-spacing: 0;
  }

  .price {
    grid-area: price;
    min-width: 0;
    font-size: clamp(1.48rem, 6.3vw, 1.84rem);
    line-height: 1.1;
    text-align: right;
  }

  .usd-price {
    grid-area: usd;
    min-width: 0;
    font-size: 0.76rem;
    line-height: 1.2;
    text-align: right;
  }

  .change {
    grid-area: change;
    min-width: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--red);
    font-size: 0.76rem;
    line-height: 1.2;
    text-align: right;
  }

  .change[data-trend="up"] {
    background: transparent;
    color: var(--green);
  }

  .source-strip {
    grid-area: sources;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .spread-pill {
    grid-column: auto;
  }

  .source-pill {
    padding: 7px 6px;
    border-radius: 9px;
    text-align: center;
  }

  .source-label {
    font-size: 0.56rem;
    white-space: nowrap;
  }

  .source-pill strong {
    margin-top: 4px;
    font-size: clamp(0.64rem, 2.35vw, 0.76rem);
  }

  .source-pill small {
    margin-top: 3px;
    font-size: 0.55rem;
  }

  .metrics {
    grid-area: metrics;
    display: none;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    padding: 8px 6px;
    border: 1px solid var(--metric-line);
    border-radius: 10px;
    background: var(--metric-bg);
  }

  .metrics div {
    min-height: 0;
    padding: 0 5px;
    border: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    background: transparent;
    text-align: center;
    display: block;
  }

  .metrics div:last-child {
    border-right: 0;
  }

  .metrics dt {
    font-size: 0.58rem;
    line-height: 1.15;
    white-space: nowrap;
  }

  .metrics dd {
    margin: 3px 0 0;
    font-size: clamp(0.67rem, 2.62vw, 0.77rem);
    line-height: 1.15;
    white-space: nowrap;
  }

  .refresh-state {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    font-size: 0.84rem;
  }

  .chart-panel {
    margin-top: 10px;
    padding: 12px;
    border-radius: 14px;
    background: linear-gradient(180deg, var(--panel) 0%, var(--panel-soft) 100%);
    box-shadow: var(--shadow);
  }

  .chart-head {
    display: grid;
    gap: 10px;
  }

  .chart-title-block h2 {
    font-size: 1rem;
  }

  .interval-tabs {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .interval-button {
    min-height: 32px;
    padding: 0 4px;
    border-radius: 8px;
    font-size: 0.72rem;
  }

  .chart-legend {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 9px;
  }

  .chart-legend button {
    justify-content: center;
    min-height: 28px;
    padding: 0 5px;
    border-radius: 8px;
    font-size: 0.66rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chart-stage {
    height: clamp(390px, calc(100svh - 318px), 500px);
    min-height: 390px;
    margin-top: 9px;
    border-radius: 12px;
  }

}

@media (max-width: 640px) and (max-height: 720px) {
  .shell {
    width: min(100% - 18px, 1120px);
    padding: 7px 0;
  }

  .market-grid {
    gap: 5px;
  }

  .market-card {
    padding: 10px 11px;
    grid-template-columns: minmax(128px, 0.88fr) minmax(0, 1.12fr);
    column-gap: 11px;
    row-gap: 7px;
    border-radius: 12px;
  }

  h2 {
    font-size: 1.02rem;
  }

  .label {
    min-height: 0;
    padding: 0;
    font-size: 0.72rem;
  }

  .price {
    font-size: clamp(1.27rem, 5.5vw, 1.52rem);
  }

  .price-label {
    font-size: 0.56rem;
  }

  .usd-price {
    font-size: 0.66rem;
  }

  .change {
    padding: 0;
    font-size: 0.66rem;
  }

  .metrics {
    padding: 6px 5px;
    border-radius: 8px;
  }

  .metrics dt {
    font-size: 0.58rem;
  }

  .metrics dd {
    font-size: clamp(0.62rem, 2.45vw, 0.72rem);
  }

  .source-pill {
    padding: 6px 5px;
  }

  .source-pill strong {
    font-size: clamp(0.6rem, 2.2vw, 0.7rem);
  }

  .chart-stage {
    height: 370px;
    min-height: 370px;
  }
}
