:root {
  --bg: #f2f4f8;
  --surface: #ffffff;
  --ink: #1c2333;
  --muted: #667085;
  --line: #e2e6ee;
  --field-bg: #fbfcfe;
  --free: #2bbfae;
  --paid: #f0a93a;
  --result-bg: #1c2333;
  --result-ink: #ffffff;
  --result-muted: #a9b1c3;
  --result-line: rgba(255, 255, 255, 0.14);
  --radius: 14px;
  --font: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;

  /* 画面の高さに応じて余白とサイズを伸縮させる（下限は小さい画面でも1画面に収まる値） */
  --vh: 1vh;
  --top: clamp(16px, calc(var(--vh) * 3), 44px);
  --gap: clamp(10px, calc(var(--vh) * 2.2), 26px);
  --pad: clamp(14px, calc(var(--vh) * 2.2), 24px);
  --inner-gap: clamp(10px, calc(var(--vh) * 2), 22px);
  --box-pad: clamp(6px, calc(var(--vh) * 1), 14px);
  --input-size: clamp(20px, calc(var(--vh) * 2.9), 28px);
  --result-pad: clamp(14px, calc(var(--vh) * 2.4), 28px);
  --row-pad: clamp(8px, calc(var(--vh) * 1.4), 16px);
}

@supports (height: 1dvh) {
  :root {
    --vh: 1dvh;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
}

.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;
}

/* Layout: 画面の縦方向の中央に、余白を均等にとって配置する */
.app {
  display: flex;
  flex: 1;
  flex-direction: column;
  justify-content: center;
  gap: var(--gap);
  width: 100%;
  min-width: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: var(--top) 16px calc(var(--top) * 0.5);
}

.intro {
  margin-bottom: calc(var(--gap) * 0.4);
}

.intro h1 {
  margin: 0 0 4px;
  font-size: clamp(19px, 5.2vw, 28px);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.01em;
}

.intro p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(12px, calc(var(--vh) * 1.6), 14px);
  line-height: 1.5;
}

/* Inputs */
.inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--inner-gap);
  padding: var(--pad);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.field {
  min-width: 0;
}

.field[data-kind="free"] {
  --dot: var(--free);
}

.field[data-kind="paid"] {
  --dot: var(--paid);
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot);
}

/* フォントの字形の都合で「ト」の前が広く見えるため、その分だけ詰める */
.kern-to {
  margin-left: -0.12em;
}

.field-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: var(--box-pad) 14px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}

.field-box:focus-within {
  background: var(--surface);
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(28, 35, 51, 0.12);
}

.field-box input {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: inherit;
  font: inherit;
  font-size: var(--input-size);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.3;
  text-align: right;
}

.field-box input::placeholder {
  color: #b5bccb;
}

/* 「+」で数値を追加するボタン。数字を入力し終えたときだけ表示される */
.add-btn {
  flex: none;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  background: var(--dot);
  color: #fff;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}

.add-icon {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2.6;
  stroke-linecap: round;
}

.add-btn[hidden] {
  display: none;
}

.add-btn:hover {
  filter: brightness(1.08);
}

.add-btn:active {
  transform: scale(0.92);
}

.add-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.suffix {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  justify-content: flex-end;
}

.reset {
  padding: 2px 4px;
  background: none;
  border: 0;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.reset:hover {
  color: var(--ink);
}

.reset:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Result */
.result {
  padding: var(--result-pad) calc(var(--pad) + 2px) 6px;
  background: var(--result-bg);
  border-radius: var(--radius);
  color: var(--result-ink);
}

.result-label {
  margin: 0;
  color: var(--result-muted);
  font-size: 12px;
  font-weight: 500;
}

.result-total {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 8px;
  margin: 2px 0 var(--inner-gap);
}

.result-total .num {
  font-size: clamp(36px, min(11vw, calc(var(--vh) * 7)), 64px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.result-total .num[data-long="true"] {
  font-size: clamp(28px, 8vw, 40px);
}

.result-total .unit {
  color: var(--result-muted);
  font-size: 13px;
}

.breakdown {
  margin: 0;
  border-top: 1px solid var(--result-line);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: var(--row-pad) 0;
}

.row + .row {
  border-top: 1px solid var(--result-line);
}

.row[data-kind="free"] {
  --dot: var(--free);
}

.row[data-kind="paid"] {
  --dot: var(--paid);
}

.row dt {
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* 値を右端、計算式をその左に置く。幅が足りないときは計算式が下に回る */
.row dd {
  display: flex;
  flex-direction: row-reverse;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 10px;
  min-width: 0;
  margin: 0;
}

.value {
  font-size: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

.formula {
  color: var(--result-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* Note & footer */
.note {
  margin: 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.site-footer {
  padding: 8px 16px var(--top);
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.site-footer p {
  margin: 0;
}

/* 画面の高さが低いときは説明文を省いて1画面に収める */
@media (max-height: 620px) {
  .intro p {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .field-box {
    transition: none;
  }
}
