/*
  THESIS  은행 통장처럼 줄 친 기록장. 한 줄에 한 매매, 오른쪽 끝에 잔고.
          금액보다 R과 규칙 준수가 먼저 보이고, 준수 여부는 채점 도장(O/X)으로 찍힌다.
  WORLD   흰 종이 + 옅은 청회색 괘선 바탕, 남색 잉크가 주 액션·선택·오늘을 맡는다.
          규칙 위반·한도는 주황 도장, 손익은 초록/빨강(국내식 선택 시 빨강/파랑).
          칸은 괘선으로 나누고 카드를 겹치지 않는다.
  TYPE    Wanted Sans 하나. 표·달력 숫자만 tabular.
*/

:root {
  --ink: #121A2B;
  --text: #2C3648;
  --slate: #475266;
  --muted: #5E687A;
  --paper: #FFFFFF;
  --wash: #EFF3F7;
  --wash-2: #E4EAF1;
  --line: #DCE3EC;
  --line-strong: #8A96A8;
  --primary: #1F3A7A;
  --primary-hover: #182F66;
  --primary-press: #13275A;
  --on-primary: #FFFFFF;
  --primary-wash: #E7EDFA;
  --warn: #B93F12;
  --warn-wash: #FDF0E8;
  --on-warn: #FFFFFF;
  --danger: #B42318;
  --danger-wash: #FDECEA;
  --up: #0F7A55;
  --up-wash: #E6F4EE;
  --down: #C53030;
  --down-wash: #FCECEC;
  --focus: #1F3A7A;
  --chart-line: #1F3A7A;
  --shadow-pop: 0 12px 32px rgba(18, 26, 43, 0.16), 0 2px 6px rgba(18, 26, 43, 0.08);
  --tabbar-h: 64px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #EEF2F7;
    --text: #CDD5E0;
    --slate: #B4BECB;
    --muted: #8E99A8;
    --paper: #0F141C;
    --wash: #161D28;
    --wash-2: #1E2633;
    --line: #273142;
    --line-strong: #5B6B82;
    --primary: #8FB0FF;
    --primary-hover: #A7C1FF;
    --primary-press: #7A9EF0;
    --on-primary: #0B1220;
    --primary-wash: #1A2540;
    --warn: #FF9B5E;
    --warn-wash: #2A1A10;
    --on-warn: #1A0E06;
    --danger: #FF7A70;
    --danger-wash: #2B1616;
    --up: #3DBFB0;
    --up-wash: #0F2522;
    --down: #FF6F61;
    --down-wash: #2C1715;
    --focus: #8FB0FF;
    --chart-line: #8FB0FF;
    --shadow-pop: 0 12px 32px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

/* 손익 색: 기본은 해외 거래소식(상승 초록·하락 빨강), 국내식을 고르면 상승 빨강·하락 파랑 */
:root { --gain: var(--up); --gain-wash: var(--up-wash); --loss: var(--down); --loss-wash: var(--down-wash); }
:root[data-updown="kr"] { --gain: #C8322B; --gain-wash: #FCECEC; --loss: #1F5FD1; --loss-wash: #EAF0FC; }
@media (prefers-color-scheme: dark) {
  :root[data-updown="kr"] { --gain: #FF7A70; --gain-wash: #2B1616; --loss: #6FA0FF; --loss-wash: #141E33; }
}

/* ---------- 바탕 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scrollbar-color: var(--line-strong) transparent; }
body {
  margin: 0;
  font-family: 'Wanted Sans Variable', 'Wanted Sans', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--paper);
  word-break: keep-all;
  overflow-wrap: anywhere;
  accent-color: var(--primary);
  caret-color: var(--primary);
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--primary-wash); color: var(--ink); }
h1, h2, h3 { color: var(--ink); margin: 0; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }
b, strong { color: var(--ink); font-weight: 650; }
small { font-size: 13px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.is-gain { color: var(--gain); }
.is-loss { color: var(--loss); }
.is-warn { color: var(--warn); }
.is-flat, .is-open { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.ico { flex: none; }

.skip { position: absolute; left: 12px; top: -48px; z-index: 50; background: var(--primary); color: var(--on-primary); padding: 8px 14px; border-radius: 6px; font-weight: 600; text-decoration: none; }
.skip:focus { top: 12px; }

/* ---------- 상단 바 ---------- */
.topbar { background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 0 16px; min-height: 56px; display: flex; align-items: center; gap: 16px; }
.brand { display: inline-flex; align-items: center; min-height: 44px; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; font-size: 16px; white-space: nowrap; letter-spacing: -0.01em; }
.hdr-balance { margin-left: auto; font-size: 13px; color: var(--muted); white-space: nowrap; display: flex; align-items: baseline; gap: 4px; }
.hdr-balance strong { color: var(--ink); font-size: 15px; }
.hdr-balance .num { color: var(--ink); }
.hb-unit { font-size: 12px; }
.hb-sep { width: 1px; height: 12px; background: var(--line); margin: 0 8px; align-self: center; }

/* 주요 메뉴: 휴대폰은 하단 탭, 넓은 화면은 상단 바 안 */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--paper); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tabbar-h); color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
.nav a .ico { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--primary); }
.nav a[aria-current="page"]::before { content: ''; position: absolute; top: -1px; left: 50%; width: 28px; height: 2px; margin-left: -14px; background: var(--primary); }

@media (min-width: 720px) {
  .nav { position: static; display: flex; gap: 2px; background: none; border: 0; padding: 0; margin-left: 12px; }
  .nav a { flex-direction: row; gap: 6px; min-height: 56px; padding: 0 12px; font-size: 15px; color: var(--slate); }
  .nav a .ico { width: 18px; height: 18px; }
  .nav a:hover { color: var(--ink); }
  .nav a[aria-current="page"] { color: var(--primary); }
  .nav a[aria-current="page"]::before { top: auto; bottom: -1px; left: 12px; right: 12px; width: auto; margin: 0; height: 2px; }
}
@media (max-width: 719px) {
  .brand-name { font-size: 15px; }
  .hdr-balance .hb-label:first-child, .hb-unit { display: none; }
}
@media (max-width: 380px) {
  .hdr-balance .hb-sep, .hdr-balance .hb-sep ~ * { display: none; }
}

/* ---------- 백업 알림 ---------- */
.banner { background: var(--primary-wash); border-bottom: 1px solid var(--line); }
.banner-inner { max-width: 1280px; margin: 0 auto; padding: 12px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; color: var(--ink); font-size: 15px; }
.banner-inner > .ico { color: var(--primary); }
.banner-inner p { flex: 1 1 280px; }
.banner-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- 본문 틀 ---------- */
main { max-width: 1280px; margin: 0 auto; padding: 20px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); outline: none; }
.foot { max-width: 1280px; margin: 0 auto; padding: 0 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); font-size: 13px; color: var(--muted); }
@media (min-width: 720px) {
  main { padding: 28px 24px 40px; }
  .foot { padding: 0 24px 32px; }
}
.noscript { padding: 24px 16px; }

.view-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; margin-bottom: 16px; }
.view-title { font-size: 24px; }
.lede { color: var(--slate); max-width: 62ch; margin: -6px 0 24px; }
.section-title { font-size: 18px; }
.section-sub { color: var(--muted); font-size: 14px; margin-top: 4px; max-width: 70ch; }
.sub-title { font-size: 16px; margin: 28px 0 12px; }
.block { padding-top: 32px; margin-top: 32px; border-top: 1px solid var(--line); }
.view-head + .block, .settings > .block:first-child { margin-top: 0; border-top: 0; padding-top: 8px; }
.block-head { margin-bottom: 16px; }
.block-head-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.note { font-size: 14px; color: var(--muted); margin-top: 12px; max-width: 70ch; }
.hint { display: block; color: var(--muted); font-size: 13px; margin-top: 6px; }
.hint.is-loss, .hint.is-warn { color: var(--warn); }
.err { display: block; color: var(--danger); font-size: 13px; margin-top: 6px; font-weight: 500; }
.err:empty { display: none; }
.empty { padding: 32px 0; display: grid; gap: 8px; justify-items: start; }
.empty .btn { margin-top: 12px; }

/* ---------- 채점 도장 O/X ---------- */
.stamp { display: inline-flex; align-items: center; gap: 4px; font-weight: 650; font-size: 13px; white-space: nowrap; }
.stamp svg { width: 16px; height: 16px; flex: none; }
.stamp-o { color: var(--primary); }
.stamp-x { color: var(--warn); }
.stamp-none { color: var(--muted); font-weight: 500; }

/* ---------- 버튼 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px; border-radius: 8px; border: 1px solid transparent; background: none; font-weight: 600; font-size: 15px; line-height: 1.2; text-decoration: none; white-space: nowrap; transition: background-color 150ms var(--ease-out), border-color 150ms var(--ease-out), color 150ms var(--ease-out); }
.btn .ico { width: 18px; height: 18px; }
.btn:disabled { cursor: not-allowed; background: var(--wash-2); color: var(--muted); border-color: transparent; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-press); }
.btn-line { border-color: var(--line-strong); color: var(--ink); background: var(--paper); }
.btn-line:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.btn-ghost { color: var(--slate); }
.btn-ghost:hover:not(:disabled) { background: var(--wash-2); color: var(--ink); }
.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn-danger:hover { filter: brightness(0.94); }
.btn-danger-line { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn-danger-line:hover { background: var(--danger-wash); }
.btn-sm { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
@media (pointer: coarse) { .btn-sm { min-height: 44px; } }
@media (prefers-color-scheme: dark) { .btn-danger { color: #1A0B0A; } }

.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; border: 0; background: none; color: var(--slate); }
.icon-btn:hover { background: var(--wash-2); color: var(--ink); }
.link { border: 0; background: none; padding: 0; color: var(--primary); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--primary) 35%, transparent); }
.link:hover { text-decoration-color: var(--primary); }
.link.small { font-size: 13px; margin-top: 6px; }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--wash-2); border-radius: 9px; }
.seg-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 0 14px; border: 0; border-radius: 7px; background: none; color: var(--slate); font-weight: 600; font-size: 14px; }
.seg-btn .ico { width: 16px; height: 16px; }
.seg-btn[aria-pressed="true"] { background: var(--paper); color: var(--primary); box-shadow: 0 1px 2px rgba(18, 26, 43, 0.14); }
@media (pointer: coarse) { .seg-btn { min-height: 42px; } }

/* ---------- 입력 ---------- */
.form { display: grid; gap: 16px; }
.field { display: block; min-width: 0; margin: 0; padding: 0; border: 0; }
.label { display: block; font-size: 14px; font-weight: 600; color: var(--slate); margin-bottom: 6px; padding: 0; }
.label em { font-style: normal; font-weight: 500; color: var(--muted); margin-left: 2px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 359px) { .field-row { grid-template-columns: 1fr; } }
input:not([type="checkbox"]):not([type="radio"]) {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--paper); color: var(--ink); font-size: 16px;
  transition: border-color 150ms var(--ease-out), box-shadow 150ms var(--ease-out);
}
input::placeholder { color: var(--muted); opacity: 0.85; }
input:not([type="checkbox"]):not([type="radio"]):hover { border-color: var(--slate); }
input:not([type="checkbox"]):not([type="radio"]):focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
input[aria-invalid="true"] { border-color: var(--danger) !important; }
input[type="date"] { appearance: none; -webkit-appearance: none; min-width: 0; }
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="checkbox"] { accent-color: var(--primary); }
input[list]::-webkit-calendar-picker-indicator { display: none !important; }

.with-sign { display: flex; gap: 6px; }
.sign-btn { flex: none; width: 52px; min-height: 44px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--wash); color: var(--ink); font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.sign-btn:hover { border-color: var(--primary); color: var(--primary); }

.choice { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-opt { position: relative; flex: 1 1 0; min-width: 88px; }
.choice-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.choice-opt span { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--paper); font-weight: 600; color: var(--slate); transition: background-color 150ms var(--ease-out), color 150ms var(--ease-out); }
.choice-opt span svg { width: 16px; height: 16px; }
.choice-opt:hover span { border-color: var(--primary); }
.choice-opt input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.choice-opt.opt-x input:checked + span { background: var(--warn); border-color: var(--warn); color: var(--on-warn); }
.choice-opt input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }

.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.calc-line { font-size: 14px; color: var(--slate); line-height: 1.7; }
.calc-line:empty { display: none; }
.warn { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; background: var(--primary-wash); color: var(--ink); font-size: 14px; line-height: 1.5; font-weight: 500; }
.warn .ico { width: 18px; height: 18px; margin-top: 1px; color: var(--primary); }
.warn-danger { background: var(--warn-wash); color: var(--warn); }
.warn-danger .ico { color: var(--warn); }
.warn + .warn { margin-top: 8px; }
.form-warn:empty { display: none; }

.more { border-top: 1px solid var(--line); padding-top: 12px; }
.more summary { cursor: pointer; font-size: 14px; font-weight: 600; color: var(--slate); min-height: 32px; display: flex; align-items: center; gap: 6px; list-style: none; }
.more summary::-webkit-details-marker { display: none; }
.more summary::before { content: ''; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); margin-right: 4px; transition: transform 150ms var(--ease-out); }
.more[open] summary::before { transform: rotate(45deg); }
.more[open] summary { margin-bottom: 12px; }

/* ---------- 첫 설정 ---------- */
.setup { max-width: 560px; padding-top: 8px; }
.setup .view-title { margin-bottom: 12px; }
.setup .lede { margin: 0 0 24px; }
.setup-form { padding: 20px; background: var(--wash); border-radius: 12px; }
.setup-restore { margin-top: 20px; font-size: 15px; color: var(--slate); }

/* ---------- 캘린더 ---------- */
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-title { font-size: 22px; font-weight: 700; color: var(--ink); min-width: 7.2em; text-align: center; font-variant-numeric: tabular-nums; }
.month-nav .btn { margin-left: 8px; }

.strip { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 20px; border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line); }
.strip > div { padding: 10px 14px 10px 0; min-width: 0; }
.strip > div:nth-child(n + 4) { border-top: 1px solid var(--line); }
.strip > div:not(:nth-child(3n + 1)) { border-left: 1px solid var(--line); padding-left: 14px; }
.strip dt { font-size: 13px; color: var(--muted); }
.strip dt small { font-size: 11px; }
.strip dd { margin: 0; font-size: 17px; font-weight: 650; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip dd small { font-size: 12px; font-weight: 500; color: var(--muted); }
@media (min-width: 900px) {
  .strip { grid-template-columns: repeat(6, 1fr); }
  .strip > div:nth-child(n + 4) { border-top: 0; }
  .strip > div:not(:first-child) { border-left: 1px solid var(--line); padding-left: 16px; }
  .strip dd { font-size: 19px; }
}

/* 휴대폰보다 넓으면 달력과 일별 패널(기록·입력창)을 좌우로 둔다. 패널은 따라 내려오고 안에서 스크롤된다. */
.cal-body { display: grid; gap: 28px; }
.cal-main { container: cal / inline-size; min-width: 0; }
.day { container: day / inline-size; min-width: 0; }
@media (min-width: 720px) {
  .cal-body { grid-template-columns: minmax(0, 1fr) clamp(300px, 32vw, 380px); align-items: start; gap: 0; }
  .day { position: sticky; top: 72px; max-height: calc(100vh - 88px); max-height: calc(100dvh - 88px); overflow-y: auto; border-left: 1px solid var(--line); padding: 0 4px 16px 20px; margin-left: 20px; overscroll-behavior: contain; }
}
@media (min-width: 1080px) {
  .day { padding-left: 24px; margin-left: 24px; }
}

.cal-grid { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-grid th { font-size: 13px; font-weight: 600; color: var(--muted); padding: 8px 4px 8px 10px; text-align: left; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--wash); }
.cal-grid td { padding: 0; height: 1px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); vertical-align: top; }
.cal-grid td > .cell { height: 100%; }
.cal-grid .wk-head, .cal-grid .wk { width: 104px; }
.cell { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; min-height: 96px; padding: 8px 10px; border: 0; background: var(--paper); text-align: left; color: var(--ink); transition: background-color 150ms var(--ease-out); }
.cell:hover { background: var(--wash); }
.cell.is-out { color: var(--muted); }
.cell.is-out .cell-date { opacity: 0.6; }
.cell.has-gain { background: var(--gain-wash); }
.cell.has-loss { background: var(--loss-wash); }
.cell.is-selected { box-shadow: inset 0 0 0 2px var(--primary); z-index: 1; }
.cell:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--focus); }
.cell-date { display: inline-grid; place-items: center; min-width: 26px; height: 26px; margin: -3px 0 0 -5px; border-radius: 13px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cell.is-today .cell-date { background: var(--primary); color: var(--on-primary); }
.cell-r { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.3; }
.cell-r.is-open { font-size: 12px; font-weight: 600; }
.cell-count { font-size: 12px; color: var(--muted); }
.cell-flags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; }
.flag { display: inline-flex; align-items: center; gap: 2px; font-style: normal; font-size: 12px; line-height: 1.5; font-weight: 650; padding: 0 5px 0 3px; border-radius: 4px; background: var(--paper); color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.flag svg { width: 12px; height: 12px; }
.flag-stop { background: var(--warn); color: var(--on-warn); box-shadow: none; padding: 0 5px; }

.wk { background: var(--wash); padding: 8px 10px !important; font-size: 12px; color: var(--muted); line-height: 1.55; }
.wk-r { display: block; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.wk-line { display: flex; justify-content: space-between; gap: 4px; font-variant-numeric: tabular-nums; color: var(--ink); }
.wk-line span { color: var(--muted); }

.week-list { display: none; list-style: none; margin: 16px 0 0; padding: 0; border-top: 1px solid var(--line); }
.week-list li { display: grid; grid-template-columns: auto 1fr; gap: 0 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.wl-range { font-variant-numeric: tabular-nums; color: var(--slate); font-weight: 600; }
.wl-r { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.wl-stats { grid-column: 1 / -1; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.week-list li.is-empty .muted { text-align: right; font-size: 13px; }

/* 달력 칸 넓이에 맞춰 줄인다: 좁으면 주간 칸을 아래 목록으로, 더 좁으면 칸을 점 표시로 */
@container cal (max-width: 639px) {
  .cal-grid .wk-head, .cal-grid .wk { display: none; }
  .week-list:not([hidden]) { display: block; }
  .cell { min-height: 80px; padding: 6px 7px; }
  .cell-date { margin: -2px 0 0 -3px; }
  .cell-r { font-size: 13px; }
  .cell-count { display: none; }
}
@container cal (max-width: 479px) {
  .cal-grid th { padding: 6px 0; text-align: center; }
  .cell { min-height: 60px; padding: 5px 2px 4px; align-items: center; gap: 0; }
  .cell-date { margin: 0; min-width: 24px; height: 24px; font-size: 13px; }
  .cell-r { font-size: 11px; letter-spacing: -0.02em; }
  .cell-flags { justify-content: center; margin-top: 2px; gap: 2px; }
  .cell-flags .flag { width: 7px; height: 7px; padding: 0; font-size: 0; border-radius: 50%; background: var(--warn); box-shadow: none; }
  .cell-flags .flag svg { display: none; }
  .cell-flags .flag-stop { background: var(--paper); box-shadow: inset 0 0 0 2px var(--warn); }
}
/* 패널이 좁으면 날짜·종목, 리스크·결과 칸을 한 줄씩 */
@container day (max-width: 339px) {
  .trade-form { padding: 14px; }
  .trade-form .field-row { grid-template-columns: 1fr; }
  .trade-form .field-row.keep-2 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 719px) {
  .month-title { font-size: 18px; min-width: 0; padding: 0 2px; }
  .month-nav { gap: 0; }
  .month-nav .icon-btn { width: 40px; }
  .month-nav .btn { margin-left: 6px; padding: 0 10px; }
  .view-head { flex-wrap: nowrap; }
  .view-head .seg-btn { padding: 0 10px; }
  .view-head .seg-btn .ico { display: none; }
  .filters { width: 100%; justify-content: space-between; }
}
@media (max-width: 719px) {
  .view-head:has(.filters) { flex-wrap: wrap; }
}

.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.lg-gain { background: var(--gain-wash); box-shadow: inset 0 0 0 1px var(--gain); }
.lg-loss { background: var(--loss-wash); box-shadow: inset 0 0 0 1px var(--loss); }

/* 일별 패널 */
.day-head { margin-bottom: 12px; }
.day-head h2 { font-size: 20px; }
.day-sum { font-size: 15px; color: var(--slate); margin-top: 2px; font-variant-numeric: tabular-nums; }
#day-alerts:not(:empty) { margin-bottom: 12px; }
.trades { list-style: none; margin: 0 0 16px; padding: 0; }
.trades:not(:empty) { border-top: 2px solid var(--ink); }
.trade { padding: 12px 0; border-bottom: 1px solid var(--line); }
.trade-top { display: flex; align-items: center; gap: 8px; }
.sym { font-size: 17px; }
.side { font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--wash-2); color: var(--slate); }
.trade-r { margin-left: auto; font-size: 18px; font-weight: 700; }
.trade-r.is-open { font-size: 14px; }
.trade-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; font-size: 14px; color: var(--slate); margin-top: 2px; }
.trade-note { font-size: 14px; color: var(--text); margin-top: 6px; }
.trade-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 8px; margin-top: 6px; font-size: 13px; }
.trade-actions { display: flex; gap: 2px; margin-right: -8px; }
.trade-actions .ico { width: 16px; height: 16px; }

.trade-form { margin-top: 4px; padding: 16px; background: var(--wash); border-radius: 12px; gap: 14px; }
.form-title { font-size: 17px; }

/* 표 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll:focus-visible { outline-offset: 4px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; border-top: 2px solid var(--ink); }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table thead th { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--wash); white-space: nowrap; }
.data-table thead th small { font-weight: 500; }
.data-table tbody th { font-weight: 600; color: var(--ink); white-space: nowrap; }
.data-table td.num, .data-table th.num { font-variant-numeric: tabular-nums; }
.data-table tr.is-mine > * { background: var(--primary-wash); }
.ledger-table { min-width: 880px; }
.ledger-table td.num { text-align: right; white-space: nowrap; }
.ledger-table thead th:nth-child(n + 3):nth-child(-n + 5), .ledger-table thead th:nth-child(n + 8) { text-align: right; }
.ledger-table .rule-cell, .ledger-table thead th:nth-child(6) { text-align: center; }
.ledger-table .note-cell { min-width: 200px; color: var(--text); }
.ledger-table td:last-child { font-weight: 650; color: var(--ink); }
.tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--primary); color: var(--on-primary); font-size: 12px; font-weight: 650; line-height: 1.6; white-space: nowrap; vertical-align: 1px; }

/* ---------- 사이징 ---------- */
.sizing { display: grid; gap: 40px; }
@media (min-width: 1000px) { .sizing { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 48px; align-items: start; } }
.sizing-form { gap: 0; }
.step { margin: 0; padding: 20px 0; border: 0; border-top: 1px solid var(--line); min-width: 0; }
.step:first-child { border-top: 0; padding-top: 0; }
.step legend { float: left; width: 100%; padding: 0; font-size: 17px; font-weight: 700; color: var(--ink); display: flex; align-items: baseline; gap: 8px; }
.step-no { color: var(--primary); font-weight: 700; }
.step-hint { color: var(--muted); font-size: 14px; margin: 4px 0 14px; clear: both; }
.step .calc-line { margin-top: 12px; }
.sizing-form .form-actions { padding-top: 8px; }
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; margin: 0; }
.result-grid dt { font-size: 13px; color: var(--muted); }
.result-grid dt small { font-size: 12px; }
.result-grid dd { margin: 2px 0 0; font-size: 20px; font-weight: 650; color: var(--ink); overflow-wrap: anywhere; }
.result-grid dd small { font-size: 13px; color: var(--muted); font-weight: 500; }
.result-main { grid-column: 1 / -1; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.result-main dd { font-size: 36px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; color: var(--primary); }
.formula { margin-top: 14px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.result .warn { margin-top: 14px; }
.sizing-side .section-sub { margin-bottom: 14px; }

/* ---------- 분석 ---------- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.figures { display: grid; grid-template-columns: 1fr 1fr; margin: 0; border-top: 2px solid var(--ink); }
.figures > div { padding: 16px 16px 16px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.figures > div:nth-child(even) { padding-left: 16px; border-left: 1px solid var(--line); }
.figures dt { font-size: 14px; color: var(--muted); }
.figures dt small { font-size: 12px; }
.figures dd { margin: 0; font-size: 28px; font-weight: 700; color: var(--ink); line-height: 1.25; }
.figures dd.is-gain { color: var(--gain); }
.figures dd.is-loss { color: var(--loss); }
.figures .fig-sub { font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; line-height: 1.45; }
@media (min-width: 900px) {
  .figures { grid-template-columns: repeat(4, 1fr); }
  .figures > div { padding: 18px 20px; border-left: 1px solid var(--line); }
  .figures > div:first-child { padding-left: 0; border-left: 0; }
  .figures dd { font-size: 32px; }
}

.chart { position: relative; margin-top: 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart:focus-visible { outline-offset: 6px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-zero { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--chart-line); stroke: var(--paper); stroke-width: 2; }
.chart .cross { stroke: var(--line-strong); stroke-width: 1; }
.chart .end-label { fill: var(--ink); font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.chart .hit { cursor: crosshair; }
.tip { position: absolute; z-index: 2; pointer-events: none; display: grid; gap: 1px; padding: 8px 10px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow-pop); font-size: 13px; white-space: nowrap; }
.tip strong { font-size: 15px; }
.mini-stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 12px 0 0; }
.mini-stats dt { font-size: 13px; color: var(--muted); }
.mini-stats dd { margin: 0; font-size: 16px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.mini-stats dd.is-gain { color: var(--gain); }
.mini-stats dd.is-loss { color: var(--loss); }
.mini-stats small { font-size: 12px; color: var(--muted); font-weight: 500; }
.block .more { margin-top: 16px; }
.steps-table { min-width: 620px; }
.steps-table td:first-child { width: 48px; color: var(--muted); }
.steps-table td:nth-child(2) { color: var(--slate); }
.steps-table td:last-child { color: var(--ink); }
.two-col { display: grid; gap: 0 48px; }
@media (min-width: 1000px) { .two-col { grid-template-columns: 1fr 1.25fr; } }
.tier-table td:nth-child(2):not(:last-child) { white-space: nowrap; }
.verdict { margin-top: 16px; font-size: 15px; color: var(--ink); line-height: 1.65; max-width: 62ch; }
.apply { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; margin-top: 16px; }
.apply .field { flex: 1 1 200px; max-width: 320px; }

/* ---------- 점검 ---------- */
.habits { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--ink); max-width: 720px; }
.habit { display: grid; grid-template-columns: 24px 1fr; gap: 2px 14px; align-items: center; padding: 14px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.habit input { width: 22px; height: 22px; margin: 0; }
.habit-text { font-size: 16px; color: var(--ink); }
.habit-evidence { grid-column: 2; color: var(--muted); font-size: 13px; }
.habit:hover { background: var(--wash); }
.habit-count { margin-top: 14px; font-size: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.audit-table { min-width: 860px; }
.audit-table td { padding: 6px 8px; vertical-align: middle; }
.audit-table th { padding: 10px 8px; }
.cell-input { min-height: 40px !important; }
.audit-table td:nth-child(1) { width: 170px; }
.audit-table td:nth-child(2), .audit-table td:nth-child(3) { width: 140px; }
.audit-table td:nth-child(4) { width: 90px; text-align: right; font-weight: 650; }
.audit-table td:nth-child(5) { width: 90px; }
.audit-table td:nth-child(7) { width: 52px; }
.audit-table .cell-input.num { text-align: right; }
.audit-sum { margin-top: 14px; font-size: 16px; line-height: 1.7; }

/* ---------- 설정 ---------- */
.settings { max-width: 760px; }
.rules-form { grid-template-columns: 1fr; }
@media (min-width: 720px) { .rules-form { grid-template-columns: 1fr 1fr; gap: 20px 24px; } }
.bal-now { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; margin: 0 0 20px; }
.bal-now dt { font-size: 13px; color: var(--muted); }
.bal-now dd { margin: 0; font-size: 16px; font-weight: 650; color: var(--ink); }
.bal-now dd.is-gain { color: var(--gain); }
.bal-now dd.is-loss { color: var(--loss); }
.bal-now .bal-main { grid-column: 1 / -1; }
.bal-now .bal-main dd { font-size: 28px; font-weight: 700; font-variant-numeric: normal; }
.bal-now small { font-size: 14px; color: var(--muted); font-weight: 500; }
#start-form { margin-top: 8px; }
#sync-form { margin-top: 16px; gap: 0; }
.adj-form { grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 720px) { .adj-form { grid-template-columns: 170px 1fr 1fr auto; align-items: end; } .adj-form .err { grid-column: 1 / -1; margin-top: -4px; } }
.adj-list { list-style: none; margin: 16px 0 0; padding: 0; border-top: 1px solid var(--line); }
.adj-list li { display: grid; grid-template-columns: auto 1fr auto 44px; align-items: center; gap: 12px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 15px; min-height: 52px; }
.adj-list li.muted { display: block; padding: 14px 0; }
.adj-note { color: var(--slate); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adj-list .num { font-weight: 600; }
.bk-status { display: grid; gap: 6px; margin: 0 0 16px; font-size: 15px; }
.bk-status > div { display: grid; grid-template-columns: 96px 1fr; gap: 12px; }
.bk-status dt { color: var(--muted); }
.bk-status dd { margin: 0; color: var(--ink); }
.steps-list { margin: 0; padding-left: 22px; display: grid; gap: 4px; }
.ok-line { color: var(--primary); font-weight: 600; }
.block-danger .section-title { color: var(--danger); }

/* ---------- 토스트, 확인창 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); z-index: 60;
  width: min(560px, calc(100vw - 32px)); transform: translate(-50%, 12px); opacity: 0;
  display: flex; align-items: center; gap: 8px; padding: 10px 8px 10px 16px; border-radius: 10px;
  background: #121A2B; color: #EEF2F7; box-shadow: var(--shadow-pop); font-size: 15px; line-height: 1.5;
  transition: transform 220ms var(--ease-out), opacity 180ms var(--ease-out);
}
.toast.is-in { transform: translate(-50%, 0); opacity: 1; }
.toast.tone-danger { background: #4A1410; }
.toast-msg { flex: 1; }
.toast-action { border: 0; background: none; color: #A7C1FF; font-weight: 700; padding: 0 10px; min-height: 40px; border-radius: 6px; white-space: nowrap; }
.toast-action:hover { background: rgba(255, 255, 255, 0.08); }
.toast-close { display: grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; color: #AEB8C6; border-radius: 6px; flex: none; }
.toast-close:hover { color: #FFFFFF; background: rgba(255, 255, 255, 0.08); }
.toast :focus-visible { outline-color: #A7C1FF; }
@media (min-width: 720px) { .toast { bottom: 24px; } }
@media (prefers-color-scheme: dark) { .toast { background: #1E2738; border: 1px solid #334055; } }

.dialog { width: min(460px, calc(100vw - 32px)); padding: 24px; border: 0; border-radius: 14px; background: var(--paper); color: var(--text); box-shadow: var(--shadow-pop); }
.dialog::backdrop { background: rgba(18, 26, 43, 0.55); }
.dialog h2 { font-size: 19px; margin-bottom: 12px; }
.dialog-body { display: grid; gap: 8px; font-size: 15px; color: var(--slate); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.dialog[open] { animation: dialog-in 220ms var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 150ms linear; transform: translate(-50%, 0); }
  .dialog[open] { animation: none; }
  .btn, .cell, input, .choice-opt span { transition: none; }
}

@media print {
  .topbar, .nav, .banner, .toast, .foot, .trade-actions, #day-add, .trade-form, .toolbar, .form-actions { display: none !important; }
  main { padding: 0; }
}
