/* Tokens. One brand hue (blue: green and red already mean paid/owed next to money),
   one neutral ramp, one warning ramp. 4px spacing base, 1.25 type scale:
   12 · 14 · 16 · 20 · 25 · 31 px. Controls 44px tall. */
:root {
  --brand: #1d4ed8;
  --brand-strong: #1e40af;
  --brand-soft: #eef3ff;
  --on-brand: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --ink-3: #5b6778;
  --line: #d6dce5;
  --line-strong: #94a3b8;
  --bg: #ffffff;
  --surface: #f5f7fa;
  --warn-bg: #fff6e5;
  --warn-ink: #7a4a00;
  --warn-line: #efd29a;
  --bad-bg: #fdecec;
  --bad-ink: #a11a1a;
  --r: 8px;
  --r-lg: 12px;
  --t-xs: 0.75rem;
  --t-sm: 0.875rem;
  --t-md: 1.25rem;
  --t-lg: 1.5625rem;
  --t-xl: 1.953rem;
  --control: 44px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #7ea2ff;
    --brand-strong: #a9c1ff;
    --brand-soft: #172443;
    --on-brand: #0b1220;
    --ink: #e8edf5;
    --ink-2: #c3ccd9;
    --ink-3: #9aa6b8;
    --line: #2b3648;
    --line-strong: #4a5a73;
    --bg: #0d1320;
    --surface: #141c2b;
    --warn-bg: #2d2412;
    --warn-ink: #f3cf8a;
    --warn-line: #5a4520;
    --bad-bg: #3a1618;
    --bad-ink: #ffb3b3;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--brand); }
a:hover { color: var(--brand-strong); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* --- page frame --- */
.top, .page, .foot { margin: 0 auto; padding-left: 16px; padding-right: 16px; }
.narrow .top, .narrow .page, .narrow .foot { max-width: 44rem; }
.wide .top, .wide .page, .wide .foot { max-width: 72rem; }
.top { padding-top: 16px; padding-bottom: 8px; }
.brand { font-weight: 700; font-size: var(--t-md); text-decoration: none; color: var(--ink); }
.brand span { color: var(--brand); }
.page { padding-bottom: 48px; }
.foot { border-top: 1px solid var(--line); padding-top: 16px; padding-bottom: 32px; color: var(--ink-3); font-size: var(--t-sm); }
.foot p { margin: 4px 0; }

h1 { font-size: var(--t-lg); line-height: 1.2; margin: 16px 0 4px; letter-spacing: -0.01em; }
@media (min-width: 640px) { h1 { font-size: var(--t-xl); } }
h2.section { font-size: var(--t-md); margin: 40px 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.lead { color: var(--ink-2); margin: 0 0 24px; max-width: 60ch; }
.hint { color: var(--ink-3); font-size: var(--t-sm); margin: 6px 0 0; }
.back { margin: 8px 0 0; font-size: var(--t-sm); }
.back a::before { content: "← "; }
.more-link { font-size: var(--t-sm); }

/* --- buttons --- */
button { font: inherit; cursor: pointer; }
.primary {
  min-height: var(--control);
  width: 100%;
  padding: 0 24px;
  border: 0;
  border-radius: var(--r);
  background: var(--brand);
  color: var(--on-brand);
  font-weight: 600;
}
.primary:hover { background: var(--brand-strong); }
@media (min-width: 640px) { .primary { width: auto; } }

/* --- question box --- */
.ask { display: grid; gap: 8px; justify-items: start; }
.ask label { font-weight: 600; font-size: var(--t-sm); }
.ask textarea { width: 100%; }
.ask .hint { margin-top: 8px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.example {
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink-2);
  font-size: var(--t-sm);
  text-align: left;
}
.example:hover { border-color: var(--brand); color: var(--brand); }

/* --- text boxes --- */
textarea, input[type="text"] {
  width: 100%;
  min-height: var(--control);
  font: inherit;
  font-size: 1rem; /* 16px: iOS does not zoom */
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 9px 12px;
}
textarea { resize: vertical; }
textarea:hover, input[type="text"]:hover { border-color: var(--ink-3); }
.money { position: relative; }
.money::before { content: "₱"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.money input { padding-left: 28px; font-variant-numeric: tabular-nums; }

/* --- calculator tiles --- */
.tiles { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
@media (min-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } }
.tiles a {
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 2px 12px;
  height: 100%;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: var(--ink);
}
.tiles a:hover { border-color: var(--brand); background: var(--brand-soft); }
.tiles .icon { grid-row: span 2; color: var(--brand); }
.tiles strong { color: var(--brand); }
.tiles span { color: var(--ink-3); font-size: var(--t-sm); }

/* --- calculator layout: form | result --- */
.calc-layout { display: grid; gap: 24px; align-items: start; }
@media (min-width: 900px) {
  .calc-layout { grid-template-columns: minmax(0, 1fr) 24rem; gap: 48px; }
  .result-col { position: sticky; top: 16px; margin-top: 64px; }
  .edit-link { display: none; }
}

.calc { display: grid; gap: 32px; max-width: 40rem; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.step { display: grid; gap: 20px; }
.step > legend { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 1rem; margin-bottom: 16px; padding: 0; }
.step-no {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  font-size: var(--t-sm); font-weight: 700;
}
.field > label, .field > legend { display: block; font-weight: 600; font-size: var(--t-sm); margin-bottom: 6px; padding: 0; }
[data-show-if] { display: none; }

/* Choice controls: real radios and checkboxes, visually hidden but focusable. */
.seg input, .card input, .day input, .month input, .switch input {
  position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0;
}
label:has(> input:focus-visible) { outline: 3px solid var(--brand); outline-offset: 2px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; }
.seg label { position: relative; display: grid; place-items: center; min-width: 88px; min-height: var(--control); padding: 0 16px; cursor: pointer; font-weight: 500; }
.seg label + label { border-left: 1px solid var(--line-strong); }
.seg label:has(input:checked) { background: var(--brand); color: var(--on-brand); }
.seg label:has(input:focus-visible) { outline-offset: -3px; }

.cards { display: grid; gap: 8px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card, .day {
  position: relative;
  display: grid;
  gap: 2px;
  min-height: var(--control);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  cursor: pointer;
  background: var(--bg);
}
.card:hover, .day:hover, .month:hover { border-color: var(--line-strong); }
.card:has(input:checked), .day:has(input:checked), .month:has(input:checked) {
  border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); background: var(--brand-soft);
}
.card-title { font-weight: 600; }
.card-hint { color: var(--ink-3); font-size: var(--t-sm); }

.days { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .days { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.day-date { font-weight: 700; font-variant-numeric: tabular-nums; }
.day-name { color: var(--ink-2); font-size: var(--t-sm); line-height: 1.3; }
.badge { justify-self: start; margin-top: 4px; padding: 1px 8px; border-radius: 999px; font-size: var(--t-xs); font-weight: 600; border: 1px solid var(--line); color: var(--ink-3); }
.badge-regular { border-color: var(--brand); color: var(--brand); }

.months { display: grid; gap: 8px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (min-width: 640px) { .months { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.month { position: relative; display: grid; place-items: center; min-height: var(--control); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; font-weight: 500; }

.field > .switch, .switch { position: relative; display: flex; margin: 0; font-size: 1rem; align-items: center; gap: 12px; min-height: var(--control); cursor: pointer; font-weight: 500; }
.track { flex: none; position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--line-strong); transition: background 150ms; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 150ms; }
.switch:has(input:checked) .track { background: var(--brand); }
.switch:has(input:checked) .track::after { transform: translateX(18px); }

.more { border-top: 1px solid var(--line); padding-top: 16px; }
.more summary { cursor: pointer; font-weight: 600; color: var(--brand); min-height: 32px; }
.more[open] { display: grid; gap: 20px; }

/* --- result --- */
.result { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; background: var(--bg); }
.result:not(.placeholder):not(.result-error) { border: 2px solid var(--brand); }
.result-label { margin: 0; color: var(--ink-2); font-weight: 600; }
.amount { font-size: var(--t-xl); font-weight: 700; margin: 4px 0 12px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.parts { margin: 0 0 12px; color: var(--ink-2); }
.lines { margin: 0; border-top: 1px solid var(--line); }
.lines div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: var(--t-sm); }
.lines dt { color: var(--ink-2); }
.lines dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; font-weight: 600; }
.why { margin-top: 12px; }
.why summary { cursor: pointer; font-weight: 600; font-size: var(--t-sm); }
.notes { margin: 8px 0 0; padding-left: 20px; color: var(--ink-2); font-size: var(--t-sm); }
.notes li { margin-bottom: 6px; }
.cite { font-size: var(--t-sm); color: var(--ink-3); margin: 12px 0 0; }
.placeholder { border-style: dashed; color: var(--ink-3); }
.placeholder p:last-child { margin: 6px 0 0; font-size: var(--t-sm); }
.result-error { background: var(--bad-bg); border-color: var(--bad-ink); }
.result-error .result-label, .error-text { color: var(--bad-ink); }
.error-text { font-weight: 600; margin: 6px 0 0; }
.edit-link { display: inline-block; margin-top: 12px; font-size: var(--t-sm); }
.feedback { display: flex; align-items: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; font-size: var(--t-sm); }
.feedback button { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg); color: var(--ink); }

.asked { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); border-radius: var(--r-lg); padding: 12px 16px; margin-top: 16px; }
.asked p { margin: 4px 0; }
.asked-plain { color: var(--ink-3); margin: 16px 0 0; }

/* --- quoted rules --- */
.passage { border-left: 3px solid var(--brand); background: var(--surface); border-radius: 0 var(--r) var(--r) 0; padding: 12px 16px; margin-bottom: 12px; max-width: 48rem; }
.quote { white-space: pre-line; margin: 0; }

.sources { padding-left: 20px; }
.sources li { margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (min-width: 640px) { .calc .primary { justify-self: start; min-width: 240px; } }
