:root {
  --bg: #f5f5fa;
  --card: #ffffff;
  --text: #1c1c22;
  --muted: #6b6b76;
  --line: #e2e2ea;
  --accent: #4f5fb8;
  --accent-soft: #e8eaf7;
  --accent-text: #ffffff;
  --in: #1f7a4d;
  --danger: #b3261e;
  --tab-h: 58px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161c;
    --card: #212129;
    --text: #ececf2;
    --muted: #9c9cab;
    --line: #33333e;
    --accent: #8f9bea;
    --accent-soft: #2a2d45;
    --accent-text: #12142a;
    --in: #6fcf9a;
    --danger: #f2877f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(var(--tab-h) + max(24px, env(safe-area-inset-bottom)));
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: 24px; margin: 6px 0 10px; letter-spacing: -0.02em; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 24px 0 8px; }
h3 { font-size: 15px; margin: 20px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
.empty { margin: 4px 0; }

input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=date], input[type=number], select {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  width: 100%;
  min-width: 0;
}
input[type=date] { -webkit-appearance: none; appearance: none; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  background: var(--accent);
  color: var(--accent-text);
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
button.danger { background: transparent; color: var(--danger); font-weight: 500; }
button.link { background: none; color: var(--muted); padding: 0; min-height: 0; font-weight: 400; text-decoration: underline; }
.quiet-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 8px 14px;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 15px; cursor: pointer;
}
.small-btn { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.small-btn.quiet { background: var(--accent-soft); color: var(--accent); }

.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.year-pick select { width: auto; min-height: 36px; padding: 4px 8px; font-size: 15px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 8px 0;
}
.card > p { margin: 0 0 8px; }
.card > p:last-child { margin-bottom: 0; }
#key-form { display: grid; gap: 10px; margin-top: 24px; }
#key-form p { margin: 0; }

/* Home: three big buttons, each one tap from opening the app. */
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 92px; padding: 12px 6px; border-radius: 16px; font-size: 15px; line-height: 1.2;
}
.action svg, .tabs svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.again {
  width: 100%; margin-top: 10px; display: grid; justify-items: start; gap: 2px; text-align: left;
  background: var(--card); color: var(--text); border: 1px solid var(--line); font-weight: 400; padding: 10px 14px;
}
.again-label { font-size: 13px; color: var(--accent); font-weight: 600; }
.again-route { font-size: 15px; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 18px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; display: grid; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-value { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile-note { font-size: 12px; color: var(--muted); }
#ta-line { margin: 10px 2px 0; }

.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.view-head h2 { margin: 0; }
.view-head + .rows, .view-head + p { margin-top: 8px; }

ul.rows { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
ul.rows:empty { display: none; }
ul.rows li + li { border-top: 1px solid var(--line); }
button.row {
  width: 100%; background: none; color: inherit; font-weight: 400; text-align: left; border-radius: 0;
  padding: 10px 14px; min-height: 56px; gap: 10px;
}
button.row:active { background: var(--accent-soft); }
.row-body { flex: 1; min-width: 0; display: grid; }
.row-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-amount.in { color: var(--in); }
.badge { font-size: 14px; }

/* The year */
.figs { display: grid; gap: 0; padding-top: 6px; padding-bottom: 6px; }
.fig { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.fig:first-child { border-top: 0; }
.fig.strong { font-weight: 600; }
.fig-value { font-variant-numeric: tabular-nums; text-align: right; }
.fig-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.box { margin-left: 8px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 6px; padding: 1px 6px; white-space: nowrap; vertical-align: 1px; }
.figs > p { margin: 8px 0 2px; }
.downloads { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.footer { margin-top: 32px; text-align: center; }

/* Tabs along the bottom, clear of the home indicator. */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
}
.tabs button {
  flex: 1; max-width: 128px; height: var(--tab-h); background: none; color: var(--muted); font-size: 11px; font-weight: 500;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 4px 0; border-radius: 0;
}
.tabs button svg { width: 24px; height: 24px; }
.tabs button[aria-current] { color: var(--accent); }

/* The sheet every form opens in: up from the bottom on a phone, a card in the middle on a Mac. */
dialog {
  border: 0; padding: 0; color: var(--text); background: var(--card);
  width: min(560px, 100%); max-width: 100%; max-height: 92vh; max-height: 92dvh;
  margin: auto auto 0; border-radius: 18px 18px 0 0; overflow: auto;
  box-shadow: 0 -8px 30px rgb(0 0 0 / 0.18);
}
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
@media (min-width: 700px) { dialog { margin: auto; border-radius: 18px; } }
#sheet-form { padding: 14px 16px max(16px, env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 18px; text-transform: none; letter-spacing: -0.01em; color: var(--text); }
#sheet-body { display: grid; gap: 12px; }
#sheet-body > p { margin: 0; }
.sheet-foot { display: flex; justify-content: space-between; gap: 12px; }
.sheet-foot #sheet-save { margin-left: auto; min-width: 120px; }
#sheet-error { margin: 0; }

.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); }
.hint:empty { display: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.segs { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; min-height: 44px; }
.seg { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 15px; cursor: pointer; padding: 0 6px; text-align: center; }
.seg + .seg { border-left: 1px solid var(--line); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg:has(input:checked) { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
.thumb { max-width: 100%; max-height: 240px; border-radius: 10px; border: 1px solid var(--line); justify-self: start; margin-top: 4px; }

.quick { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.quick p { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--accent-soft); color: var(--accent); font-weight: 400; border-radius: 999px; padding: 8px 14px; }
.chip strong { font-weight: 600; }

.toast {
  position: fixed; z-index: 20; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
  width: max-content; max-width: calc(100% - 32px);
  display: flex; gap: 14px; align-items: center;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 16px; font-size: 15px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.2);
}
.toast .link { color: var(--bg); font-weight: 600; }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .downloads { grid-template-columns: repeat(4, 1fr); }
}
