:root { color-scheme: light; font: 16px/1.5 system-ui, sans-serif; color: #163d31; background: #f7f6ee;
  --paid: #0b7a4b; --interest: #c0893a; --line: #d6dccd; --muted: #4f6659;
  --pad-y: clamp(16px, 2.4vw, 24px); }
* { box-sizing: border-box; }
body { max-width: 1080px; margin: auto; padding: 0 clamp(16px, 4vw, 48px) 56px; }
header, header label, .masthead { display: flex; align-items: center; gap: 10px; }
header { justify-content: space-between; flex-wrap: wrap; padding-block: 18px; border-bottom: 1px solid var(--line); }
header a { color: inherit; font-weight: 650; text-decoration: none; white-space: nowrap; }
.masthead { position: relative; gap: 10px; flex-wrap: wrap; }
h1 { margin: 0; font-size: clamp(1.1rem, 2.6vw, 1.5rem); letter-spacing: -.02em; line-height: 1.2; }
.masthead h1 { padding-inline-start: 14px; border-inline-start: 1px solid var(--line); }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.workspace { display: grid; grid-template-columns: 1.15fr 1fr; gap: 18px; margin-top: 18px; }
form, .result, .history { border-radius: 18px; border: 1px solid var(--line); }
/* 입력 카드와 결과 카드의 첫 줄이 같은 높이에서 시작하도록 위아래 여백을 맞춥니다. */
form { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; padding: var(--pad-y) clamp(16px,2.4vw,24px); background: #fffefa; }
form label, .field { display: flex; flex-direction: column; justify-content: end; gap: 5px; font-weight: 600; font-size: .92rem; }
form > label:first-child > span, .field:first-of-type .field-head { line-height: 24px; }
.field { position: relative; }
.pair { display: flex; gap: 6px; }
.pair input { flex: 1 1 55%; }
.pair select { flex: 1 1 45%; min-width: 4.5rem; padding-inline: 6px; }
.field-head { display: flex; align-items: center; gap: 6px; }
.hint { flex: none; width: 19px; height: 19px; padding: 0; border: 1px solid #abb9ab; border-radius: 50%;
  background: #eef2e6; color: var(--muted); font: 600 12px/1 system-ui, sans-serif; cursor: pointer; }
.hint[aria-expanded=true] { background: #163d31; color: #f7f6ee; border-color: #163d31; }
.tip p { margin: 0; }
.tip p + p { margin-top: 6px; opacity: .9; }
.tip { position: absolute; z-index: 5; inset-inline-start: 0; top: calc(100% + 6px); width: max(100%, min(260px, 80vw)); margin: 0;
  padding: 10px 12px; border-radius: 10px; background: #163d31; color: #f5f7e5; font-weight: 500; font-size: .82rem;
  box-shadow: 0 6px 18px #163d3133; }
input, select { min-width: 0; max-width: 100%; padding: 9px 10px; border: 1px solid #abb9ab; border-radius: 8px; color: #163d31; background: white; font: inherit; }
input[aria-invalid=true] { border-color: #a83824; }
:focus-visible { outline: 3px solid #ab782a; outline-offset: 2px; }
.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#reset { flex: none; padding: 2px 12px; border: 1px solid #6c8577; border-radius: 999px; background: transparent;
  color: #d6eab2; font: 600 .82rem/20px system-ui, sans-serif; cursor: pointer; }
#reset:hover { background: #22513f; }
.result { min-width: 0; padding: var(--pad-y) clamp(20px,3vw,32px); background: #193d33; color: #f5f7e5; }
h2 { margin: 0; font-size: 1rem; font-weight: 550; line-height: 24px; }
output, strong, td { font-variant-numeric: tabular-nums; }
/* 금액이 길어지면 글자 크기를 줄여 한 줄로 맞춥니다(app.js의 fitBalance). */
output { display: block; margin: 8px 0 20px; font-size: clamp(1.7rem,3.8vw,3rem); font-weight: 720; line-height: 1.2;
  white-space: nowrap; overflow: hidden; }
.breakdown { border-top: 1px solid #587064; padding-top: 12px; }
.breakdown div { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; padding-block: 5px; }
.breakdown strong { overflow-wrap: anywhere; color: #d6eab2; }
#error { color: #ffe2aa; }

.history { background: #fffefa; margin-top: 18px; padding: clamp(16px,3vw,24px); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; background: currentColor; }
.chart-area { position: relative; margin-top: 10px; }
#chart { display: block; width: 100%; height: clamp(200px, 32vw, 300px); overflow: visible; touch-action: pan-y; }
#chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
#chart .axis { stroke: var(--line); stroke-width: 1; }
#chart .edge { fill: none; stroke: #163d31; stroke-width: 2; stroke-linejoin: round; }
#chart .marker { fill: #163d31; stroke: #fffefa; stroke-width: 2; }
#chart .crosshair { stroke: #163d31; stroke-width: 1; stroke-dasharray: 3 3; }
#tooltip { position: absolute; z-index: 4; min-width: 11rem; padding: 9px 11px; border-radius: 10px; background: #163d31;
  color: #f5f7e5; font-size: .82rem; line-height: 1.5; pointer-events: none; box-shadow: 0 6px 18px #163d3133; }
#tooltip b { display: block; margin-bottom: 3px; }
#tooltip div { display: flex; justify-content: space-between; gap: 12px; font-variant-numeric: tabular-nums; }
#tooltip i { display: inline-block; width: 9px; height: 9px; margin-inline-end: 6px; border-radius: 2px; background: currentColor; }
.table-scroll { overflow: auto; max-height: 24rem; margin-top: 14px; border-top: 1px solid #e4e8dc; overscroll-behavior: contain; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
td, th { text-align: end; padding: 9px; border-bottom: 1px solid #e4e8dc; }
th:first-child { text-align: start; }
thead th { position: sticky; top: 0; background: #edf1e4; }
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; }
  output { font-size: clamp(1.6rem, 7vw, 2.2rem); }
  #chart { height: clamp(190px, 46vw, 260px); }
}
@media (max-width: 520px) {
  body { padding-inline: 14px; }
  header { gap: 8px; padding-block: 14px; }
  header label span { display: none; }
  .masthead h1 { padding-inline-start: 0; border: 0; }
  form { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; padding: 14px; }
  .field, form label:last-of-type { grid-column: auto; }
  .history { padding: 16px 12px; }
  #chart { height: 200px; }
  #chart text { font-size: 10px; }
  table { font-size: .84rem; }
  td, th { padding: 7px 6px; }
  .tip { inset-inline: 0; width: auto; }
}
/* 모바일 Safari는 글자가 16px보다 작은 입력칸에 초점이 가면 화면을 확대합니다(되돌리지 않습니다).
   터치 기기에서만 입력칸·선택칸 글자를 16px로 올려 막습니다. 손가락 확대는 그대로 둡니다. */
@media (pointer: coarse) {
  input, select { font-size: 16px; }
  /* 글자가 커진 만큼 주기 선택칸에 폭을 조금 더 주어 주기 이름이 긴 언어에서도 읽히게 한다. */
  .pair { gap: 4px; }
  .pair input { flex: 1 1 46%; }
  .pair select { flex: 1 1 54%; padding-inline: 4px; }
}
@media (prefers-reduced-motion: no-preference) { #chart .area, #chart .edge { transition: d .2s ease; } }
