:root {
  --bg: #f2f4f6;
  --card: #ffffff;
  --fill: #f2f4f6;
  --fill-2: #e5e8eb;
  --text: #191f28;
  --text-2: #4e5968;
  --text-3: #8b95a1;
  --line: #f2f4f6;
  --blue: #3182f6;
  --red: #f04452;
  --down: #3182f6;
  --green: #03b26c;
  --dim: rgba(0, 0, 0, .45);
  --radius: 22px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171c;
    --card: #202027;
    --fill: #2c2c35;
    --fill-2: #3c3c47;
    --text: #e4e4e5;
    --text-2: #c3c3c6;
    --text-3: #9e9ea4;
    --line: #2c2c35;
    --blue: #4c95ff;
    --red: #f5525f;
    --down: #4c95ff;
    --green: #1fc47d;
    --dim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px; line-height: 1.45; letter-spacing: -0.01em;
  font-feature-settings: "tnum";
}
button { font: inherit; color: inherit; }

.app { max-width: 600px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

/* 헤더 */
.head { padding: 28px 4px 16px; }
.head h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.modes { display: flex; gap: 16px; }
.modes button { border: 0; background: none; padding: 0; font: inherit; font-size: 26px; font-weight: 800; letter-spacing: -0.03em; color: var(--text-3); cursor: pointer; }
.modes button[aria-selected="true"] { color: var(--text); }
.chips[hidden] { display: none; }
.sh-unit { width: 84px; margin: 12px 0 0 auto; padding: 3px; border-radius: 10px; }
.sh-unit button { padding: 4px 0; font-size: 13px; border-radius: 7px; }
.head-sub { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--text-3); font-size: 14px; font-weight: 500; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.dot.on { background: var(--green); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(3, 178, 108, .45); } 70% { box-shadow: 0 0 0 7px rgba(3, 178, 108, 0); } 100% { box-shadow: 0 0 0 0 rgba(3, 178, 108, 0); } }

/* 홈 화면에 추가 안내 */
.install { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 18px; padding: 12px 12px 12px 14px; margin-bottom: 12px; }
.install[hidden] { display: none; }
.install img { border-radius: 10px; flex: none; }
.install-text { flex: 1; min-width: 0; }
.install-title { font-weight: 700; font-size: 15px; }
.install-sub { font-size: 13px; color: var(--text-3); }
.install-btn { border: 0; background: var(--blue); color: #fff; font-weight: 700; font-size: 14px; padding: 9px 16px; border-radius: 10px; cursor: pointer; flex: none; }
.install-x { border: 0; background: none; color: var(--text-3); width: 28px; height: 28px; display: grid; place-items: center; cursor: pointer; flex: none; }

/* 토스트 */
.toast { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: rgba(25, 31, 40, .92); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 1000; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 카드 */
.card { background: var(--card); border-radius: var(--radius); padding: 22px 20px; margin-bottom: 12px; }

/* 히어로 */
.hero-label { color: var(--text-2); font-size: 15px; font-weight: 600; }
.hero-body { margin-top: 8px; cursor: pointer; }
.hero-name { font-size: 15px; color: var(--text-3); font-weight: 500; }
.hero-price { font-size: 32px; font-weight: 800; letter-spacing: -0.03em; margin-top: 2px; }
.hero-chg { font-size: 17px; font-weight: 700; margin-top: 2px; }
.hero-chg small { color: var(--text-3); font-weight: 500; font-size: 14px; margin-left: 6px; }
.hero-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.hchip { background: var(--fill); border: 0; border-radius: 16px; padding: 12px; text-align: left; cursor: pointer; min-width: 0; }
.hchip:active { transform: scale(.98); }
.hchip-name { font-size: 13px; color: var(--text-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hchip-price { font-size: 16px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hchip-chg { font-size: 13px; font-weight: 600; }

.up { color: var(--red); }
.down { color: var(--down); }
.flat { color: var(--text-3); }

/* 검색 */
.list-card { padding: 16px 0 8px; }
.search { display: flex; align-items: center; gap: 8px; margin: 0 16px; padding: 0 14px; height: 46px; border-radius: 14px; background: var(--fill); color: var(--text-3); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 16px; }
.search input::placeholder { color: var(--text-3); }

/* 분류 칩 */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 16px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 0; background: var(--fill); color: var(--text-2); font-weight: 600; font-size: 15px; padding: 9px 15px; border-radius: 999px; cursor: pointer; }
.chips button[aria-pressed="true"] { background: var(--text); color: var(--card); }

/* 정렬 */
.sorts { display: flex; gap: 16px; padding: 14px 20px 6px; }
.sorts button { border: 0; background: none; padding: 0; font-size: 15px; font-weight: 600; color: var(--text-3); cursor: pointer; }
.sorts button[aria-selected="true"] { color: var(--text); }

/* 리스트 */
.rows { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 20px; cursor: pointer; }
.row:active, .row:hover { background: var(--fill); }
.rank { width: 18px; text-align: center; color: var(--blue); font-weight: 700; font-size: 15px; flex: none; }
.av { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #fff; font-weight: 800; font-size: 13px; letter-spacing: -0.04em; }
.av.logo { background: var(--fill); overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04); }
.av.logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-right { text-align: right; flex: none; border-radius: 8px; padding: 2px 4px; }
.row-price { font-size: 16px; font-weight: 600; }
.row-chg { font-size: 13px; font-weight: 600; }
.flash-up { animation: fu .8s; }
.flash-down { animation: fd .8s; }
@keyframes fu { 0% { background: rgba(240, 68, 82, .16); } 100% { background: transparent; } }
@keyframes fd { 0% { background: rgba(49, 130, 246, .16); } 100% { background: transparent; } }
.more { display: block; width: calc(100% - 32px); margin: 8px 16px; height: 48px; border: 0; border-radius: 14px; background: var(--fill); color: var(--text-2); font-weight: 600; cursor: pointer; }
.empty { padding: 36px 20px; text-align: center; color: var(--text-3); }

/* 스켈레톤 */
.sk { background: linear-gradient(90deg, var(--fill) 25%, var(--fill-2) 50%, var(--fill) 75%); background-size: 200% 100%; animation: sh 1.3s infinite; border-radius: 8px; }
.sk-line { height: 18px; margin: 8px 0; }
.sk-av { width: 40px; height: 40px; border-radius: 50%; flex: none; }
.w40 { width: 40%; } .w50 { width: 50%; } .w60 { width: 60%; }
@keyframes sh { to { background-position: -200% 0; } }

/* 광고 자리: 높이를 미리 잡아 늦게 떠도 화면이 밀리지 않게 */
.ad { display: flex; flex-direction: column; align-items: center; }
.ad[hidden] { display: none; }
.ad-label { align-self: stretch; font-size: 11px; color: var(--text-3); margin: 0 4px 4px; }
.ad-top { min-height: 118px; margin: 4px 0 16px; }
.ad-mid { min-height: 268px; margin: 12px 20px 16px; padding-top: 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.ad-mid .ad-label { margin-left: 0; }

.foot { color: var(--text-3); font-size: 12px; padding: 8px 6px; }
.foot p { margin: 0 0 6px; }

/* 차트 시트 */
.sheet {
  border: 0; padding: 8px 20px calc(20px + env(safe-area-inset-bottom)); margin: auto auto 0;
  width: 100%; max-width: 600px; max-height: 92vh; overflow: auto;
  background: var(--card); color: var(--text);
  border-radius: 24px 24px 0 0;
}
.sheet[open] { animation: up .25s cubic-bezier(.2, .8, .2, 1); }
.sheet::backdrop { background: var(--dim); }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 24px; max-width: 640px; padding-bottom: 20px; }
  .sheet-grip { display: none; }
}
.sheet-grip { width: 40px; height: 4px; border-radius: 4px; background: var(--fill-2); margin: 4px auto 12px; }
.sh-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sh-id { display: flex; align-items: center; gap: 10px; min-width: 0; }
.sh-name { font-size: 17px; font-weight: 700; }
.sh-sym { font-size: 13px; color: var(--text-3); }
#sh-share { margin-left: auto; }
.sh-top { gap: 8px; }
.sh-close { border: 0; background: var(--fill); width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--text-2); flex: none; }
.sh-price { font-size: 30px; font-weight: 800; letter-spacing: -0.03em; margin-top: 16px; }
.sh-price small { font-size: 16px; color: var(--text-3); font-weight: 600; margin-left: 6px; }
.sh-chg { font-size: 15px; font-weight: 600; margin-top: 2px; }
.sh-chg .lbl { color: var(--text-3); font-weight: 500; margin-right: 4px; }
.sh-canvas { height: 320px; margin: 16px -8px 8px; }
.seg { display: flex; background: var(--fill); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 0; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--text-3); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.sh-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin: 20px 0 4px; }
.sh-stats div { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.sh-stats dt { color: var(--text-3); }
.sh-stats dd { margin: 0; font-weight: 600; }
.sh-foot { color: var(--text-3); font-size: 12px; margin-top: 14px; display: flex; align-items: center; gap: 6px; }

@media (max-width: 380px) {
  .hero-price { font-size: 28px; }
  .hchip { padding: 10px; }
  .hchip-price { font-size: 14px; }
}
