:root {
  color-scheme: dark;
  --ink: #edf5ff;
  --muted: #91a3bb;
  --line: rgba(148, 177, 215, .16);
  --panel: rgba(12, 29, 51, .9);
  --green: #38d7a0;
  --red: #ff7082;
  --blue: #63a8ff;
  --amber: #ffd56a;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, sans-serif;
}

* { box-sizing: border-box; min-width: 0; }
html { background: #06111f; }
body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: radial-gradient(circle at 100% 0, #16375d 0, transparent 38%), #06111f;
  color: var(--ink);
}
button, input, textarea, select { font: inherit; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(15px + env(safe-area-inset-top)) 16px 13px;
  background: rgba(6, 17, 31, .94);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.eyebrow, .kicker { margin: 0 0 4px; color: var(--blue); font-size: 9px; font-weight: 850; letter-spacing: .14em; }
h1 { margin: 0; font-size: 21px; letter-spacing: -.04em; }
.readonly, .badge, .origin, .side {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 10px;
  font-weight: 850;
  white-space: nowrap;
}
.readonly { color: #9ff4d2; background: rgba(56, 215, 160, .13); border: 1px solid rgba(56, 215, 160, .3); }
.tabs {
  position: sticky;
  top: calc(66px + env(safe-area-inset-top));
  z-index: 19;
  display: flex;
  gap: 7px;
  width: 100%;
  overflow-x: auto;
  padding: 9px 12px;
  scrollbar-width: none;
  background: rgba(6, 17, 31, .94);
  border-bottom: 1px solid var(--line);
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: #aebed2;
  background: rgba(16, 36, 62, .7);
  font-size: 11px;
  font-weight: 800;
}
.tab.is-active { color: white; border-color: rgba(99, 168, 255, .72); background: #276bcb; box-shadow: 0 5px 16px rgba(39, 107, 203, .3); }
main { width: min(760px, 100%); margin: 0 auto; padding: 12px 11px 42px; }
.notice, .loading, .panel, .hero { border: 1px solid var(--line); border-radius: 17px; }
.notice { padding: 10px 12px; margin-bottom: 11px; color: #b8c8dc; background: rgba(26, 54, 88, .5); font-size: 11px; line-height: 1.55; }
.loading, .empty { padding: 25px 12px; text-align: center; color: var(--muted); background: rgba(5, 18, 33, .52); font-size: 12px; }
.view { display: none; }
.view.is-active { display: block; }
.hero {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 11px;
  background: var(--line);
}
.metric { padding: 15px; background: linear-gradient(150deg, rgba(15, 38, 66, .98), rgba(8, 24, 43, .98)); }
.metric.primary { grid-column: 1 / -1; padding: 20px 15px; }
.label { color: var(--muted); font-size: 10px; font-weight: 750; }
.value { margin-top: 6px; font-size: 18px; font-weight: 850; letter-spacing: -.04em; overflow-wrap: anywhere; }
.metric.primary .value { font-size: 29px; }
.sub { margin-top: 5px; color: var(--muted); font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }
.panel { margin-top: 11px; padding: 14px 12px; background: var(--panel); box-shadow: 0 14px 38px rgba(0,0,0,.18); }
.panel.flush-top { margin-top: 0; }
.section-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 11px; }
.section-title h2 { margin: 0; font-size: 16px; letter-spacing: -.03em; }
.section-title > span { color: var(--muted); font-size: 10px; text-align: right; }
.section-note { margin: -2px 0 12px; padding: 10px; border-radius: 11px; color: #afc1d8; background: rgba(99, 168, 255, .08); font-size: 10px; line-height: 1.55; }
.paper-grid, .detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.account-card, .detail { padding: 12px; border: 1px solid var(--line); border-radius: 13px; background: rgba(5, 18, 33, .52); }
.account-label { color: #c8d7e9; font-size: 11px; font-weight: 800; }
.account-card .big { margin-top: 9px; font-size: 19px; font-weight: 850; letter-spacing: -.04em; }
.detail dt { color: var(--muted); font-size: 9px; }
.detail dd { margin: 5px 0 0; font-size: 12px; font-weight: 780; overflow-wrap: anywhere; }
.badge.ok { color: var(--green); background: rgba(56, 215, 160, .12); }
.badge.warn { color: var(--amber); background: rgba(255, 196, 54, .12); }
.badge.user, .origin.user { color: #d6b5ff; background: rgba(164, 96, 255, .14); }
.badge.ai, .origin.ai { color: #9ec9ff; background: rgba(99, 168, 255, .14); }
.badge.neutral, .origin.rule { color: #b6c5d8; background: rgba(158, 177, 201, .11); }
.holdings, .stack { display: grid; gap: 8px; }
.holding, .fill-card, .provider-card, .validation-card, .decision-card {
  padding: 12px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: rgba(5, 18, 33, .52);
}
.holding-head, .holding-numbers, .decision-head, .provider-card, .validation-card, .fill-card > div:first-child, .fill-card > .right { display: flex; justify-content: space-between; gap: 9px; }
.holding-head strong, .fill-card strong { font-size: 13px; }
.symbol, .fill-card span, .validation-card span, .decision-head span { margin-left: 5px; color: var(--muted); font-size: 9px; }
.holding-numbers { align-items: flex-end; margin-top: 10px; }
.holding-price { font-size: 14px; font-weight: 800; }
.holding-pnl { text-align: right; font-size: 12px; font-weight: 800; }
.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 9px; color: #b6c5d8; font-size: 10px; }
.mini-grid span { overflow-wrap: anywhere; }
.holding-ai { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); color: #afc1d8; font-size: 10px; line-height: 1.45; }
.holding-ai strong { margin-left: 6px; color: var(--ink); }
.holding-ai p, .decision-card p, .review-summary, .fill-card p { margin: 6px 0 0; overflow-wrap: anywhere; }
.pipeline { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 5px; scrollbar-width: thin; }
.pipeline-step { position: relative; flex: 0 0 94px; min-height: 79px; padding: 10px; border: 1px solid var(--line); border-radius: 13px; background: rgba(5, 18, 33, .52); }
.pipeline-step:not(:last-child)::after { content: '›'; position: absolute; right: -7px; top: 29px; z-index: 1; color: var(--blue); font-size: 16px; }
.step-number { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 6px; color: var(--blue); background: rgba(99,168,255,.13); font-size: 9px; font-weight: 900; }
.pipeline-step strong, .pipeline-step span, .pipeline-step small { display: block; }
.pipeline-step strong { margin-top: 7px; font-size: 16px; }
.pipeline-step span { color: #c2d0e2; font-size: 9px; }
.pipeline-step small { color: var(--muted); font-size: 8px; }
.decision-card { margin-top: 9px; color: #b7c7db; font-size: 10px; line-height: 1.5; }
.decision-head { align-items: center; color: var(--ink); }
.decision-card small { display: block; margin-top: 7px; color: var(--muted); }
.info-strip { display: grid; gap: 4px; margin-top: 9px; padding: 11px; border-radius: 12px; background: rgba(99,168,255,.09); color: #b8c8dc; font-size: 10px; line-height: 1.5; }
.info-strip strong { color: #d9e7f7; }
.position-card, .ranking-card { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: rgba(5, 18, 33, .52); }
.position-card summary, .ranking-card summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px; padding: 12px; cursor: pointer; list-style: none; }
.ranking-card summary { grid-template-columns: 24px minmax(0, 1fr) auto; }
.position-card summary::-webkit-details-marker, .ranking-card summary::-webkit-details-marker { display: none; }
.position-card summary strong, .ranking-card summary strong { display: block; font-size: 12px; }
.position-card summary span, .ranking-card summary span { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; overflow-wrap: anywhere; }
.position-card .right, .ranking-card .right, .validation-card .right { text-align: right; }
.position-body, .ranking-body { padding: 0 12px 12px; border-top: 1px solid var(--line); }
.provenance { display: flex; align-items: center; gap: 6px; margin-top: 11px; }
.provenance strong { font-size: 11px; }
.provenance small { margin-left: auto; color: var(--muted); font-size: 8px; text-align: right; }
.explain { display: grid; grid-template-columns: 70px minmax(0, 1fr); gap: 7px 8px; margin: 11px 0 0; font-size: 10px; line-height: 1.5; }
.explain dt { color: var(--muted); }
.explain dd { margin: 0; overflow-wrap: anywhere; }
.review-summary { color: #c1d0e2; font-size: 10px; line-height: 1.55; }
.horizon { display: grid; gap: 5px; margin-top: 8px; color: #aebed2; font-size: 9px; }
.fill-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 5px 8px; font-size: 10px; }
.fill-card > div:first-child { justify-content: flex-start; align-items: center; }
.fill-card > .right { display: grid; justify-items: end; }
.fill-card p, .fill-card small { grid-column: 1 / -1; color: #b6c5d8; line-height: 1.45; }
.fill-card small { color: var(--muted); }
.side.buy { color: #ff9cac; background: rgba(255,112,130,.12); }
.side.sell { color: #82e5c0; background: rgba(56,215,160,.12); }
.timeline { display: grid; gap: 7px; margin-top: 10px; }
.timeline article { display: flex; gap: 8px; padding: 10px; border-radius: 11px; background: rgba(5,18,33,.45); }
.timeline strong { font-size: 10px; }
.timeline p { margin: 3px 0 0; color: var(--muted); font-size: 9px; line-height: 1.45; }
.status-dot { flex: 0 0 8px; height: 8px; margin-top: 3px; border-radius: 50%; background: #60738c; }
.status-dot.done, .status-dot.ok, .status-dot.complete { background: var(--green); }
.status-dot.running, .status-dot.active { background: var(--blue); }
.rank { display: grid !important; place-items: center; width: 24px; height: 24px; margin: 0 !important; border-radius: 8px; color: var(--blue) !important; background: rgba(99,168,255,.12); font-weight: 900; }
.ranking-body p { color: #b8c8dc; font-size: 9px; line-height: 1.5; }
.ranking-body h4 { margin: 10px 0 4px; color: var(--muted); font-size: 9px; }
.ranking-body ul { margin: 0; padding-left: 17px; color: #b8c8dc; font-size: 9px; line-height: 1.5; }
.provider-card, .validation-card { align-items: center; font-size: 10px; }
.provider-card strong, .provider-card span, .validation-card strong, .validation-card span { display: block; }
.provider-card span { margin-top: 3px; color: var(--muted); }
.security-note { color: #b8c8dc; font-size: 10px; line-height: 1.55; }
.security-note strong { color: var(--amber); }
.security-note p { margin: 7px 0 0; }
footer { display: grid; gap: 4px; padding: 16px 14px calc(22px + env(safe-area-inset-bottom)); text-align: center; color: var(--muted); font-size: 9px; border-top: 1px solid var(--line); }
footer strong { color: #c5d5e9; font-size: 10px; }

@media (max-width: 420px) {
  .paper-grid { grid-template-columns: 1fr; }
  .metric.primary .value { font-size: 26px; }
  .position-card summary { grid-template-columns: minmax(0, 1fr) 83px; }
}

@media (max-width: 350px) {
  .topbar { padding-left: 12px; padding-right: 12px; }
  h1 { font-size: 19px; }
  .detail-grid { grid-template-columns: 1fr; }
  .fill-card { grid-template-columns: 1fr; }
  .fill-card > .right { justify-items: start; }
  .fill-card p, .fill-card small { grid-column: 1; }
}

/* 잠금 화면. 인증 전에는 이 파일과 로그인 폼 외에 아무것도 응답하지 않는다. */
body.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 360px;
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
}
.gate-card h1 { margin: 0 0 12px; font-size: 22px; letter-spacing: .02em; }
.gate-card p { margin: 0 0 14px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.gate-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.gate-card input {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(6, 17, 31, .85);
  color: var(--ink);
  font-size: 16px; /* 16px 미만이면 iOS 사파리가 입력 시 확대한다 */
}
.gate-card input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.gate-card button {
  padding: 13px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #04121f;
  font-size: 16px;
  font-weight: 600;
}
.gate-card a { color: var(--blue); }
.gate-error { color: var(--red); font-size: 14px; }

/* 계정 관리 화면. 이 PC 브라우저에서만 열린다. */
.gate-card h2 { margin: 24px 0 8px; font-size: 16px; color: var(--ink); }
.account-list { list-style: none; margin: 16px 0 0; padding: 0; text-align: left; }
.account-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.account-name { flex: 1; font-weight: 600; color: var(--ink); }
.account-seen { font-size: 12px; color: var(--muted); }
.account-list form { margin: 0; }
.account-list button.danger {
  padding: 7px 12px;
  font-size: 13px;
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
  border-radius: 9px;
}
