:root {
  --paper: #EDEFE7;      /* 통장 종이 */
  --sheet: #F7F8F3;
  --ink: #1E2A26;
  --ink-2: #56625C;
  --line: #C8CFC2;
  --rule: #DCE1D6;
  --pink: #F4ADA6;       /* 모니 */
  --pink-deep: #C24E5E;
  --pink-text: #A33447;  /* 분홍 글자용(대비 4.5:1 이상) */
  --up: #D0312D;         /* 오름: 빨강 (국내 관례) */
  --down: #1F55C7;       /* 내림: 파랑 */
  --live: #B3261E;
  --ok: #2E7D4F;
  --sans: "SUIT Variable", "SUIT", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --print: "D2 coding", "D2Coding", "Consolas", monospace;
  --r: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  font-feature-settings: "tnum";
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 18px; font-weight: 750; }
h2 small { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-left: 6px; }
a { color: var(--pink-text); }
small { font-size: 12.5px; }

button {
  font: inherit; font-weight: 650;
  background: var(--ink); color: var(--sheet);
  border: 0; border-radius: 999px; padding: 9px 18px;
  cursor: pointer;
}
button:hover { background: #33433d; }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
button.ghost:hover { box-shadow: inset 0 0 0 1.5px var(--ink); }
button.danger { background: var(--live); }
:focus-visible { outline: 3px solid var(--pink-text); outline-offset: 0; }

input, select {
  font: inherit; color: var(--ink);
  background: var(--sheet); border: 1.5px solid var(--line); border-radius: 8px;
  padding: 7px 10px;
}
input:focus, select:focus { border-color: var(--ink); outline: none; }

/* ── 상단 ─────────────────────────────── */
.bar {
  display: flex; align-items: center; gap: 20px;
  padding: 14px clamp(16px, 4vw, 48px);
  border-bottom: 1.5px solid var(--ink);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.01em; color: var(--ink); text-decoration: none; }
.tabs { display: flex; gap: 4px; margin-right: auto; margin-left: 12px; }
.tabs a { color: var(--ink-2); text-decoration: none; font-weight: 650; padding: 7px 14px; border-radius: 999px; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--sheet); box-shadow: inset 0 0 0 1.5px var(--ink); }
.modes { display: flex; background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 999px; padding: 3px; }
.modes button { background: transparent; color: var(--ink-2); padding: 6px 16px; }
.modes button[aria-checked="true"] { background: var(--ink); color: var(--sheet); }
.modes button[data-mode="live"][aria-checked="true"] { background: var(--live); }
body.is-live .bar { border-bottom-color: var(--live); }
.live-strip {
  background: var(--live); color: #fff; text-align: center;
  font-weight: 700; font-size: 13.5px; padding: 5px;
}

main { padding: 0 clamp(16px, 4vw, 48px) 64px; max-width: 1280px; margin: 0 auto; }
.view > h2:first-child, .view > .section-head:first-child { margin-top: 32px; }

/* ── 첫 화면 ──────────────────────────── */
.hero {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
  gap: 40px; padding: 36px 0 32px; border-bottom: 1.5px solid var(--line);
}
.hero h1 { font-size: clamp(26px, 3.4vw, 40px); font-weight: 800; letter-spacing: -.02em; margin: 18px 0 8px; max-width: 22ch; }
.hero-sub { margin: 0; color: var(--ink-2); }
.hero-actions { display: flex; align-items: center; gap: 14px; margin-top: 22px; flex-wrap: wrap; }
.hint { color: var(--ink-2); font-size: 13.5px; }
.warn { margin: 16px 0 0; padding: 10px 14px; border-left: 4px solid var(--live); background: #F6E4E1; border-radius: 0 8px 8px 0; font-size: 14px; }

.switch { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 62px; height: 34px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .2s;
}
.switch .knob {
  position: absolute; top: 4px; left: 4px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--sheet); box-shadow: 0 1px 2px rgba(30,42,38,.3); transition: transform .2s;
}
.switch input:checked + .track { background: var(--pink-deep); }
.switch input:checked + .track .knob { transform: translateX(28px); }
.switch input:focus-visible + .track { outline: 3px solid var(--pink-deep); outline-offset: 2px; }
.switch-label { font-weight: 750; font-size: 17px; }
.switch-state { color: var(--ink-2); font-weight: 600; margin-left: -4px; }
.switch-state.on { color: var(--pink-text); }
.switch input:disabled + .track { opacity: .6; }

.money { margin: 0; display: grid; grid-template-columns: repeat(3, auto); gap: 14px 24px; align-content: start; }
.money div { min-width: 0; }
.money dt { font-size: 13px; color: var(--ink-2); }
.money dd { margin: 2px 0 0; font-weight: 700; font-size: 16px; white-space: nowrap; }
.money-total { grid-column: 1 / -1; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.money-total dd:first-of-type { font-size: clamp(30px, 3.6vw, 42px); font-weight: 800; letter-spacing: -.02em; }
.money .delta { font-size: 14px; font-weight: 650; }

.up { color: var(--up); }
.down { color: var(--down); }

/* ── 지켜보는 종목 ────────────────────── */
.holdings { padding-top: 40px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; width: min(420px, 100%); }
.search input { width: 100%; border-radius: 999px; padding: 9px 16px; }
.search-results {
  position: absolute; z-index: 5; top: calc(100% + 6px); left: 0; right: 0;
  list-style: none; margin: 0; padding: 6px; background: var(--sheet);
  border: 1.5px solid var(--ink); border-radius: var(--r); max-height: 340px; overflow: auto;
}
.search-results button {
  width: 100%; display: flex; justify-content: space-between; gap: 10px; text-align: left;
  background: transparent; color: var(--ink); border-radius: 6px; padding: 8px 10px; font-weight: 600;
}
.search-results button:hover, .search-results button:focus-visible { background: var(--paper); }
.search-results small { color: var(--ink-2); font-weight: 500; }
.search-hint { font-size: 12.5px; color: var(--ink-2); padding: 4px 10px 6px; }

.watch-cols, .w-row {
  display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(110px, .9fr) 150px minmax(200px, 1.8fr) minmax(110px, .9fr);
  gap: 18px; align-items: center;
}
.watch-cols { font-size: 12.5px; color: var(--ink-2); padding: 0 14px 8px; border-bottom: 1.5px solid var(--ink); }
.watch-list { list-style: none; margin: 0; padding: 0; }
.w { border-bottom: 1px solid var(--line); }
.w.off { opacity: .5; }
.w-row {
  width: 100%; text-align: left; background: transparent; color: var(--ink);
  border-radius: 0; padding: 14px; font-weight: 500;
}
.w-row:hover { background: var(--sheet); }
.w-row[aria-expanded="true"] { background: var(--sheet); }
.w-name, .w-price, .w-signal { display: flex; flex-direction: column; min-width: 0; }
.w-name b { font-size: 16px; }
.w-name small, .w-price small, .w-signal small, .w-mine { color: var(--ink-2); }
.w-price b { font-size: 16px; }
.w-price small.up { color: var(--up); }
.w-price small.down { color: var(--down); }
.w-signal em { font-style: normal; font-weight: 750; }
.w-signal small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sig-buy em { color: var(--up); }
.sig-sell em { color: var(--down); }
.sig-hold em { color: var(--ink); }
.w-mine { font-size: 13.5px; }
.w-mine b { color: var(--ink); }
.w-spark svg { display: block; }

.w-detail { background: var(--sheet); padding: 6px 14px 22px; border-top: 1px dashed var(--line); }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(240px, 1fr); gap: 28px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 14px; height: 3px; vertical-align: middle; margin-right: 5px; border-radius: 2px; }
.facts { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; font-weight: 600; }
.bt { margin-top: 18px; padding: 14px 16px; border-radius: var(--r); background: var(--paper); font-size: 14px; }
.bt h3 { font-size: 14.5px; margin-bottom: 6px; }
.bt p { margin: 4px 0; }
.bt .note { color: var(--ink-2); font-size: 13px; }
.detail-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.detail-actions button { padding: 7px 14px; font-size: 13.5px; }

/* ── 아래 두 칸 ───────────────────────── */
.passbook h2, .holdings h2, .diary h2 { margin-bottom: 12px; }
.passbook { padding-top: 32px; max-width: 760px; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { text-align: right; font-size: 12.5px; font-weight: 500; color: var(--ink-2); padding: 0 8px 8px; border-bottom: 1.5px solid var(--ink); }
td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
td small { display: block; color: var(--ink-2); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; color: var(--pink-text); margin-left: 4px; }

/* 통장: 은행 통장처럼 줄 쳐진 종이에 찍힌 글씨 */
.book {
  font-family: var(--print); font-size: 13.5px;
  background:
    linear-gradient(90deg, transparent 87px, var(--rule) 87px, var(--rule) 88px, transparent 88px),
    repeating-linear-gradient(var(--sheet) 0 33px, var(--rule) 33px 34px);
  border: 1.5px solid var(--ink); border-radius: 4px;
  max-height: 420px; overflow: auto;
}
.book-head, .book li {
  display: grid; grid-template-columns: 80px minmax(0, 1fr) 54px 96px 112px; gap: 10px;
  padding: 0 12px; line-height: 34px; height: 34px;
}
.book-head { font-family: var(--sans); font-size: 12px; color: var(--ink-2); position: sticky; top: 0; background: var(--sheet); border-bottom: 1.5px solid var(--ink); }
.book ol { list-style: none; margin: 0; padding: 0; }
.book li span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book li span:nth-child(n+3), .book-head span:nth-child(n+3) { text-align: right; }
.book li.buy .amt { color: var(--up); }
.book li.sell .amt { color: var(--down); }
.book li.failed { color: var(--ink-2); text-decoration: line-through; }
.book .empty { font-family: var(--sans); padding: 16px; margin: 0; background: var(--sheet); }

.diary { padding-top: 40px; }
.diary .diary-list { max-width: 80ch; }

.empty { color: var(--ink-2); font-size: 14px; }

/* ── 설정 시트 ────────────────────────── */
dialog { border: 1.5px solid var(--ink); border-radius: 14px; background: var(--sheet); color: var(--ink); padding: 0; }
dialog::backdrop { background: rgba(30, 42, 38, .35); }
.sheet { width: min(620px, 94vw); max-height: 90vh; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 24px; border-bottom: 1.5px solid var(--ink); position: sticky; top: 0; background: var(--sheet); z-index: 1; }
.sheet section { padding: 20px 24px; border-bottom: 1px solid var(--line); }
.settings { max-width: 720px; }
.settings > section { padding: 22px 0; border-bottom: 1px solid var(--line); }
.settings h3 { font-size: 16px; margin-bottom: 6px; }
.sheet h3 { font-size: 16px; margin-bottom: 6px; }
.help { margin: 0 0 12px; font-size: 13.5px; color: var(--ink-2); max-width: 64ch; }
.fields { display: grid; gap: 10px; }
.fields label { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 14.5px; }
.fields label > span { display: grid; grid-template-columns: 180px 110px; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13.5px; }
.fields label > span input[type="number"] { justify-self: end; }
.fields input[type="number"] { width: 120px; text-align: right; }
.fields label > input { flex: 1; max-width: 360px; }
.sheet-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.confirm { width: min(460px, 92vw); padding: 24px; }
.confirm h2 { margin-bottom: 10px; }
.confirm p { font-size: 14.5px; }
.confirm input { width: 100%; margin: 4px 0 6px; }
#askBody p { font-size: 14.5px; }

/* ── 좁은 화면 ────────────────────────── */
@media (max-width: 900px) {
  .hero, .detail-grid { grid-template-columns: 1fr; gap: 28px; }
  .watch-cols { display: none; }
  .w-row { grid-template-columns: 1fr auto; gap: 8px 14px; }
  .w-spark { display: none; }
  .w-signal, .w-mine { grid-column: 1 / -1; }

}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}


/* ── 홈 아래쪽 ────────────────────────── */
.home-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 36px; padding-top: 32px; }
.home-grid h2 { margin-bottom: 12px; }
.home-grid .section-head { margin-bottom: 0; }
.more { font-size: 13.5px; color: var(--ink-2); }
.market-list, .apply-mini { list-style: none; margin: 0; padding: 0; }
.market-list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.market-list span:last-child { color: var(--ink-2); text-align: right; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line); margin-right: 8px; vertical-align: middle; }
.dot.on { background: var(--ok); }
.apply-mini li a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.apply-mini small { color: var(--ink-2); grid-column: 1; }
.dday { font-weight: 800; font-size: 15px; grid-row: 1 / span 2; grid-column: 2; align-self: center; color: var(--pink-text); }
.dday.today { color: var(--up); }
.diary-list { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.diary-list li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px dotted var(--line); }
.diary-list time { color: var(--ink-2); font-size: 13px; }
.diary-list li.warn-ev { color: var(--live); }
.diary-list li.trade-ev, .diary-list li.apply-ev { font-weight: 650; }
#eventsMini li { grid-template-columns: 1fr; gap: 0; }

/* ── 청약 ─────────────────────────────── */
.apply-top { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-top: 32px; }
.apply-top h2 { margin-bottom: 2px; }
.notice { margin: 16px 0 0; padding: 10px 14px; border-left: 4px solid var(--pink-deep); background: #F7E6E3; border-radius: 0 8px 8px 0; font-size: 14px; }
.prefs-line { color: var(--ink-2); font-size: 14px; margin: 14px 0; }
.seg { display: inline-flex; background: var(--sheet); border: 1.5px solid var(--ink); border-radius: 999px; padding: 3px; margin-bottom: 18px; flex-wrap: wrap; }
.seg button { background: transparent; color: var(--ink-2); padding: 6px 14px; font-size: 14px; }
.seg button[aria-selected="true"] { background: var(--ink); color: var(--sheet); }
.apply-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; max-width: 860px; }
.ap { background: var(--sheet); border: 1.5px solid var(--line); border-radius: 12px; }
.ap.now { border-color: var(--ink); }
.ap.done { opacity: .6; }
.ap-head { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 16px; padding: 16px 18px; align-items: center; cursor: pointer; }
.ap-when { grid-row: 1 / span 2; text-align: center; width: 104px; }
.ap-when b { display: block; font-size: 22px; font-weight: 800; line-height: 1.1; color: var(--pink-text); }
.ap.now .ap-when b { color: var(--up); }
.ap.done .ap-when b { color: var(--ink-2); font-size: 15px; }
.ap-when small { color: var(--ink-2); font-size: 12px; }
.ap-title { font-size: 17px; font-weight: 750; grid-column: 2; }
.ap-sub { color: var(--ink-2); font-size: 13.5px; grid-column: 2; }
.ap-actions { grid-row: 1 / span 2; grid-column: 3; display: flex; gap: 8px; }
.star { background: transparent; color: var(--ink-2); box-shadow: inset 0 0 0 1.5px var(--line); padding: 7px 14px; }
.star:hover { background: transparent; box-shadow: inset 0 0 0 1.5px var(--ink); }
.star[aria-pressed="true"] { color: var(--pink-text); box-shadow: inset 0 0 0 1.5px var(--pink-text); }
.star { min-width: 44px; min-height: 40px; }
.badge { display: inline-block; font-size: 12px; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--paper); color: var(--ink-2); margin-left: 6px; vertical-align: 2px; }
.ap-why { font-size: 13px; color: var(--ink-2); padding: 0 18px 12px; margin: 0; }
.ap-body { border-top: 1px dashed var(--line); padding: 14px 18px 18px; }
.steps { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 6px; }
.steps li { display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; font-size: 14px; }
.steps li.past { color: var(--ink-2); }
.steps li.past span:first-child { text-decoration: line-through; }
.steps li.today { font-weight: 750; color: var(--up); }
.models { font-size: 13.5px; margin-top: 6px; }
.models td, .models th { padding: 6px; }
.ap-facts { margin: 12px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; }
.ap-facts dt { color: var(--ink-2); }
.ap-facts dd { margin: 0; }
.ap-links { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; }
.ap-links a { font-size: 14px; font-weight: 650; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { cursor: pointer; position: relative; }
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chips span { display: inline-block; padding: 6px 14px; border-radius: 999px; box-shadow: inset 0 0 0 1.5px var(--line); font-size: 14px; font-weight: 600; }
.chips input:checked + span { background: var(--ink); color: var(--sheet); box-shadow: none; }
.chips input:focus-visible + span { outline: 3px solid var(--pink-deep); outline-offset: 2px; }
.checks { display: grid; gap: 8px; font-size: 14.5px; }
.checks label { display: flex; gap: 8px; align-items: center; }
.fields label > span.range { grid-template-columns: 80px auto 80px auto; }
.range input[type="number"] { width: 80px; }

/* ── 잠금 ─────────────────────────────── */
.lock { position: fixed; inset: 0; z-index: 50; background: var(--paper); display: grid; place-items: center; padding: 24px; }
.lock[hidden] { display: none; }
.lock-box { display: grid; gap: 12px; justify-items: center; width: min(320px, 100%); text-align: center; }
.lock-box h1 { font-size: 24px; }
.lock-box p { margin: 0; }
.lock-box input { width: 100%; text-align: center; font-size: 22px; letter-spacing: .3em; }
.lock-box button { width: 100%; padding: 12px; }

/* ── 폰 ───────────────────────────────── */
@media (max-width: 900px) {
  input, select { font-size: 16px; }   /* 아이폰이 입력칸을 누를 때 화면을 확대하지 않게 */
  .hero .money { order: -1; }          /* 폰에서는 자산을 먼저 */
  .hero { display: flex; flex-direction: column; }
  .tabs a { min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .home-grid { grid-template-columns: 1fr; gap: 28px; }
  .tabs {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; margin: 0;
    background: var(--sheet); border-top: 1.5px solid var(--ink);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around; gap: 4px;
  }
  .tabs a { flex: 1; text-align: center; padding: 10px 0; font-size: 14px; border-radius: 10px; }
  .tabs a[aria-current="page"] { box-shadow: none; background: var(--ink); color: var(--sheet); }
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
  .bar { padding-top: calc(12px + env(safe-area-inset-top)); padding-bottom: 12px; }
  .brand { margin-right: auto; font-size: 17px; }
  .modes button { padding: 5px 11px; font-size: 13.5px; }
  .hero { padding-top: 24px; }
  .money { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 14px; }
  .money dd { font-size: 14.5px; }
  .ap-head { padding: 14px; gap: 4px 12px; }
  .ap-actions { grid-row: 1; align-self: start; }
  .ap-sub { grid-column: 2 / -1; }
  .ap-when { width: 76px; }
  .ap-why { padding: 0 14px 12px; }
  .ap-body { padding: 14px; }
  .steps li { grid-template-columns: 1fr auto; gap: 8px; padding: 4px 0; border-bottom: 1px dotted var(--line); }
  .steps li span:nth-child(2) { text-align: right; }
  .steps li span:last-child { display: none; }
  .w-mine::before { content: "모니가 산 것 · "; }
  .w-mine br { display: none; }
  .apply-top { align-items: center; }
  .fields label { flex-wrap: wrap; }
  .fields label > span { grid-template-columns: 1fr auto; }
  .fields label > input { max-width: none; width: 100%; }
  .book-head, .book li { grid-template-columns: 62px minmax(0, 1fr) 40px 84px; font-size: 12.5px; }
  .book-head span:nth-child(4), .book li span:nth-child(4) { display: none; }
  .book { background: repeating-linear-gradient(var(--sheet) 0 33px, var(--rule) 33px 34px); }
  .diary-list li { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
}
[hidden] { display: none !important; }
