/* 주식계산서 — 한 단, 조용한 화면, 결과는 계산서 한 장 */
:root {
  --bg: #F1F2F4;
  --surface: #E4E7EC;
  --paper: #FFFFFF;
  --ink: #16213A;
  --muted: #586175;
  --accent: #D93636;      /* 계산서의 답 한 곳에만 */
  --gain: #C62828;        /* 국내 표기: 이익 빨강 */
  --loss: #1D5BBF;        /* 손실 파랑 */
  --step-small: 0.875rem;                                   /* 14 */
  --step-body: 1.0625rem;                                   /* 17 */
  --step-lead: 1.25rem;                                     /* 20 */
  --step-head: clamp(1.625rem, 1.25rem + 1.4vw, 2.25rem);   /* 26–36 */
  --step-display: clamp(2rem, 1.3rem + 2.8vw, 3.25rem);     /* 32–52 */
  --margin: clamp(20px, 4vw, 48px);
  --ease: cubic-bezier(.2, .7, .2, 1);
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: var(--step-body); line-height: 1.6; letter-spacing: -0.01em;
  word-break: keep-all; overflow-wrap: break-word;
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
::selection { background: var(--ink); color: var(--paper); }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.03em; line-height: 1.2; margin: 0; }
p { margin: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: var(--paper); padding: 8px 14px; }
.skip:focus { left: 8px; z-index: 10; }
.skip:hover { color: var(--paper); }
input, select { caret-color: var(--accent); }
html { scrollbar-color: #B9C0CC var(--bg); }

/* 머리 줄 */
.bar {
  display: flex; align-items: baseline; gap: 32px;
  padding: 22px var(--margin); max-width: 1240px; margin: 0 auto;
}
.mark { font-weight: 800; font-size: var(--step-lead); text-decoration: none; letter-spacing: -0.04em; }
.mark:hover { color: var(--ink); }
.bar nav { display: flex; flex-wrap: wrap; gap: 0 22px; }
.bar nav a { text-decoration: none; color: var(--muted); font-size: var(--step-body); white-space: nowrap; padding: 6px 0; }
.bar nav a:hover { color: var(--ink); }
.bar nav a[aria-current="page"] { color: var(--ink); font-weight: 700; }

main { max-width: 1240px; margin: 0 auto; padding: 0 var(--margin); }

/* 계산기 첫 화면 */
.calc-head { padding: clamp(32px, 7vh, 72px) 0 32px; max-width: 760px; }
.calc-head h1 { font-size: var(--step-display); }
.calc-head .answer { margin-top: 20px; font-size: var(--step-lead); line-height: 1.55; }
.calc-head .answer b { font-weight: 700; }
.calc-head .when { margin-top: 12px; font-size: var(--step-small); color: var(--muted); }

.tool { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 420px); gap: clamp(24px, 4vw, 64px); align-items: start; }
.tool > * { min-width: 0; }

/* 예시 버튼 */
.presets h2 { font-size: 1.5rem; margin-bottom: 14px; }
.presets ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.preset {
  width: 100%; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  background: var(--surface); border: 0; border-radius: 0; padding: 14px 18px; line-height: 1.45;
  transition: background-color .15s var(--ease), transform .15s var(--ease);
}
.preset:hover { background: #D8DCE3; }
.preset:active { transform: scale(.99); }
.preset[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* 입력 */
.form { margin-top: 40px; position: relative; }
.reset { position: absolute; top: 0; right: 0; min-height: 44px; padding: 0 2px; font: inherit; font-size: var(--step-small); background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.reset:hover { color: var(--ink); }
.form h2 { font-size: 1.5rem; margin-bottom: 4px; }
.form .hint { color: var(--muted); font-size: var(--step-small); margin-bottom: 16px; }
.group { margin-top: 28px; }
.group > h3 { font-size: var(--step-body); margin-bottom: 10px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.fields.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field label { display: block; font-size: var(--step-small); color: var(--muted); margin-bottom: 6px; }
.field .box { display: flex; align-items: center; background: var(--paper); }
.field input, .field select {
  width: 100%; min-width: 0; font: inherit; font-size: var(--step-lead); color: var(--ink);
  border: 0; background: transparent; padding: 12px 14px; border-radius: 0; appearance: none;
}
.field select { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%2316213A' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center; padding-right: 36px; }
.field .unit { padding-right: 14px; color: var(--muted); font-size: var(--step-small); white-space: nowrap; }
.field .box:focus-within { outline: 3px solid var(--ink); outline-offset: 0; }
.field input:focus, .field select:focus { outline: none; }
.seg { display: inline-flex; background: var(--surface); padding: 4px; gap: 4px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 8px 18px; color: var(--muted); }
.seg input:checked + span { background: var(--paper); color: var(--ink); font-weight: 700; }
.seg input:focus-visible + span { outline: 3px solid var(--ink); }
.addrow { margin-top: 12px; font: inherit; font-size: var(--step-small); background: none; border: 0; padding: 6px 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.seg-wrap { border: 0; padding: 0; margin: 0 0 4px; min-width: 0; }

/* 계산서 */
.receipt-wrap { position: sticky; top: 20px; }
.receipt { background: var(--paper); padding: 28px 28px 24px; }
.receipt .r-title { font-size: var(--step-small); color: var(--muted); display: flex; justify-content: space-between; gap: 12px; }
.receipt .r-answer { margin-top: 14px; }
.receipt .r-answer span { display: block; font-size: var(--step-small); color: var(--muted); }
.receipt .r-answer strong { display: block; font-size: var(--step-display); font-weight: 800; letter-spacing: -0.04em; line-height: 1.15; color: var(--accent); }
.receipt .r-lead { margin-top: 18px; }
.receipt .r-lead-t { font-size: var(--step-small); font-weight: 700; color: var(--ink); }
.receipt .r-lead table { margin-top: 8px; font-size: 1.125rem; font-variant-numeric: tabular-nums; }
.receipt .r-lead th { font-size: var(--step-small); font-weight: 400; color: var(--muted); border-top: 0; padding: 4px 0; text-align: right; }
.receipt .r-lead th:first-child, .receipt .r-lead td:first-child { text-align: left; }
.receipt .r-lead td { font-weight: 800; color: var(--ink); border-top: 2px solid var(--ink); padding: 10px 0 10px 8px; }
.receipt .r-lead td:first-child { padding-left: 0; }
.receipt .r-lead tr:last-child td { border-bottom: 2px solid var(--ink); }
.receipt .r-lead-f { margin-top: 10px; font-size: var(--step-small); color: var(--muted); line-height: 1.5; }
.receipt .r-desc { margin-top: 12px; font-size: var(--step-small); line-height: 1.55; }
.receipt table { width: 100%; border-collapse: collapse; margin-top: 18px; font-size: 0.9375rem; }
.receipt th, .receipt td { padding: 9px 0; border-top: 1px dashed #C9CED8; vertical-align: top; }
.receipt th { text-align: left; font-weight: 400; color: var(--muted); padding-right: 12px; }
.receipt td { text-align: right; white-space: nowrap; }
.receipt tr.sum th, .receipt tr.sum td { color: var(--ink); font-weight: 700; border-top: 2px solid var(--ink); }
.receipt tr.sub th { padding-top: 18px; color: var(--ink); font-weight: 700; }
.receipt tr.sub td { padding-top: 18px; }
.receipt .gain { color: var(--gain); }
.receipt .loss { color: var(--loss); }
.receipt .r-note { margin-top: 14px; font-size: var(--step-small); color: var(--muted); line-height: 1.5; }
.receipt .r-error { margin-top: 14px; color: var(--ink); }
.r-actions { display: flex; gap: 16px; align-items: center; margin-top: 14px; }
.copy {
  font: inherit; font-size: var(--step-small); font-weight: 700; background: var(--ink); color: var(--paper);
  border: 0; border-radius: 0; padding: 10px 16px; cursor: pointer; transition: transform .15s var(--ease), background-color .15s;
}
.copy:hover { background: #24345A; }
.copy:active { transform: scale(.98); }
.copy.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 2px var(--ink); }
.copy.ghost:hover { background: var(--surface); }
.copy:disabled { opacity: .45; cursor: default; }
.r-actions { flex-wrap: wrap; }
.quote { margin: 0 0 22px; }
.quote input { flex: 1; min-width: 0; }
.quote input::-webkit-search-cancel-button { display: none; }
.quote-go { flex: none; align-self: stretch; display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; background: var(--ink); color: var(--paper); font-size: var(--step-small); font-weight: 700; text-decoration: none; }
.quote-go:hover { background: #24345A; }
.quote-go[aria-disabled="true"] { background: var(--surface); color: var(--muted); }
.quote-note { margin-top: 8px; font-size: var(--step-small); color: var(--muted); line-height: 1.5; }
.r-actions .done { flex-basis: 100%; }
.r-actions .done { font-size: var(--step-small); color: var(--muted); }
.flash { animation: flash .5s var(--ease); }
@keyframes flash { from { opacity: .35; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* 해설 글 */
.article { max-width: 720px; padding-top: clamp(72px, 12vh, 140px); }
.article section + section { margin-top: 64px; }
.article h2, .faq h2, .more h2 { font-size: var(--step-head); margin-bottom: 20px; }
.article p + p { margin-top: 14px; }
.article ul, .article ol { margin: 14px 0 0; padding-left: 1.2em; }
.article li + li { margin-top: 6px; }
.formula { background: var(--surface); padding: 18px 22px; margin-top: 16px; font-weight: 600; line-height: 1.7; }
.example { background: var(--paper); padding: 20px 22px; margin-top: 16px; }
.example p + p { margin-top: 6px; }
.article table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 0.9375rem; background: var(--paper); }
.article th, .article td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--surface); }
.article td.n, .article th.n { text-align: right; }
.article thead th { font-weight: 700; }
.note { color: var(--muted); font-size: var(--step-small); margin-top: 14px; }

/* 자주 묻는 질문: 읽는 글로 */
.faq { padding-top: clamp(72px, 12vh, 140px); display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 9fr); gap: 32px; }
.faq-text { columns: 2; column-gap: 56px; }
.faq-text p { break-inside: avoid; margin-bottom: 20px; line-height: 1.6; }
.faq-text strong { font-weight: 700; }

/* 다른 계산기 */
.more { padding-top: clamp(72px, 12vh, 140px); max-width: 720px; }
.more ul { list-style: none; margin: 0; padding: 0; }
.more li { display: flex; flex-wrap: wrap; gap: 4px 18px; align-items: baseline; padding: 14px 0; }
.more li + li { border-top: 6px solid var(--bg); }
.more li { background: var(--surface); padding: 16px 20px; }
.more a { font-weight: 700; font-size: var(--step-lead); }
.more span { color: var(--muted); }

/* 일반 글(소개·개인정보·문의) */
.doc { max-width: 720px; padding: clamp(40px, 8vh, 80px) 0 0; }
.doc h1 { font-size: var(--step-display); margin-bottom: 24px; }
.doc h2 { font-size: var(--step-lead); margin: 40px 0 10px; }
.doc p + p { margin-top: 12px; }
.doc ul { padding-left: 1.2em; }

/* 첫 페이지 */
.home-top { display: grid; grid-template-columns: minmax(0, 7fr) minmax(300px, 5fr); gap: clamp(32px, 6vw, 96px); align-items: end; padding: clamp(40px, 10vh, 110px) 0 56px; }
.home-head { max-width: 640px; padding-bottom: 8px; }
.home-head h1 { font-size: clamp(2.5rem, 1.4rem + 4.4vw, 5rem); line-height: 1.08; letter-spacing: -0.045em; }
.sample { display: block; text-decoration: none; transition: transform .2s var(--ease); }
.sample:hover { color: var(--ink); transform: translateY(-3px); }
.sample .r-note { color: var(--ink); font-weight: 700; }
.sample .r-answer strong { font-size: clamp(3rem, 2rem + 3vw, 4.5rem); }
@media (max-width: 900px) { .home-top { grid-template-columns: 1fr; align-items: start; } }

.home-head p { margin-top: 18px; font-size: var(--step-lead); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.list a { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 8px 32px; text-decoration: none; background: var(--surface); padding: 24px 28px; transition: background-color .15s var(--ease); }
.list a:hover { background: #D8DCE3; color: var(--ink); }
.list b { font-size: var(--step-head); letter-spacing: -0.03em; line-height: 1.2; }
.list span { color: var(--ink); align-self: center; }
.list small { display: block; color: var(--muted); font-size: var(--step-small); margin-top: 6px; }
.how { padding-top: clamp(72px, 12vh, 140px); max-width: 720px; }
.how h2 { font-size: var(--step-head); margin-bottom: 24px; }
.how p + p { margin-top: 16px; }
.how p b { font-weight: 700; }
.how .muted { color: var(--ink); }

/* 바닥 줄 */
.foot {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: baseline;
  max-width: 1240px; margin: 0 auto; padding: 30svh var(--margin) 30px; font-size: var(--step-small); color: var(--muted);
}
.foot .links { display: flex; gap: 24px; }
.foot .links a, .foot a { color: var(--ink); }
.foot > span:last-child { text-align: right; }

/* 등장 */
@media (prefers-reduced-motion: no-preference) {
  .rise { animation: rise .6s var(--ease) both; }
  .rise.d1 { animation-delay: .07s; } .rise.d2 { animation-delay: .14s; } .rise.d3 { animation-delay: .21s; }
  @keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
  .reveal { opacity: 0; transform: translateY(20px); transition: opacity .6s var(--ease), transform .6s var(--ease); }
  .reveal.in { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }

/* 폰: 화면 아래 답 한 줄 */
.mini { display: none; }
@media (max-width: 900px) {
  .mini { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; justify-content: space-between; align-items: baseline; gap: 12px;
    background: var(--ink); color: var(--paper); padding: 14px var(--margin) calc(14px + env(safe-area-inset-bottom)); text-decoration: none;
    transition: transform .25s var(--ease); }
  .mini:hover { color: var(--paper); }
  .mini span { font-size: var(--step-small); opacity: .8; }
  .mini strong { font-size: var(--step-lead); font-weight: 800; }
  .mini.away { transform: translateY(110%); }
  .calc-page .foot { padding-bottom: 96px; }
}

/* 태블릿·폰 */
@media (max-width: 900px) {
  .tool { grid-template-columns: 1fr; }
  .receipt-wrap { position: static; }
  .faq { grid-template-columns: 1fr; gap: 0; }
  .faq-text { columns: 1; }
}
@media (max-width: 600px) {
  .bar { flex-direction: column; gap: 6px; padding-top: 16px; padding-bottom: 8px; }
  .bar nav { width: 100%; gap: 0 16px; }
  .bar nav a { padding: 8px 0; }
  .fields, .fields.three { grid-template-columns: 1fr 1fr; }
  .receipt { padding: 22px 20px; }
  .list a { grid-template-columns: 1fr; padding: 20px; }
  .foot { grid-template-columns: 1fr; gap: 8px; padding-top: 20svh; }
  .foot > span:last-child { text-align: left; }
}

/* 해설 글 */
.guide-page .article { padding-top: 24px; }
.guide-page .article b { font-weight: 700; }
.list.guides { margin-top: 0; }
.list.guides b { font-size: var(--step-lead); }
@media (max-width: 600px) {
  .article table { font-size: 0.875rem; }
  .article th, .article td { padding: 9px 8px; word-break: keep-all; }
}

/* 손가락으로 누르기 쉬운 크기(44px) */
.bar nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0; }
.mark { display: inline-flex; align-items: center; min-height: 44px; }
.addrow { min-height: 44px; }
.copy { min-height: 44px; }
.more li { position: relative; }
.more a::after { content: ''; position: absolute; inset: 0; }
.more li:hover { background: #D8DCE3; }
.foot a { display: inline-flex; align-items: center; min-height: 44px; }
.field input::placeholder { color: #9096A3; opacity: 1; }
/* 선택 칸: 구분선 아래, 연하게 두었다가 마우스·포커스·입력하면 진하게 */
.opt { margin-top: 36px; padding-top: 18px; border-top: 1px solid #C9CED8; }
.opt-t { font-size: var(--step-small); color: var(--muted); }
.opt-t b { display: inline-block; margin-right: 8px; padding: 1px 8px; background: var(--surface); color: var(--ink); font-weight: 700; }
.opt > .group:first-of-type, .opt > .quote + .group { margin-top: 16px; }
.opt .quote { margin-top: 16px; }
.opt .group .field .box { background: transparent; box-shadow: inset 0 0 0 1px #CDD2DA; transition: background-color .15s var(--ease), box-shadow .15s var(--ease); }
.opt .group .field input { color: var(--muted); }
.opt .group .field .box:hover, .opt .group .field .box:focus-within, .opt .group .field .box.on { background: var(--paper); box-shadow: none; }
.opt .group .field .box:focus-within input, .opt .group .field .box.on input { color: var(--ink); }
