/* 預設暗色，不跟隨系統設定；亮色僅供本頁手動切換。 */
:root {
  color-scheme: dark;
  font-family: "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-variant-numeric: tabular-nums;
  --bg: #090f1b;
  --panel: #111b2b;
  --text: #eef3f8;
  --muted: #b5c0d0;
  --label: #b6c7dc;
  --red: #ff4040;
  --line: #304158;
  --border: #526680;
  --heading-bg: #1c2b40;
  --heading-text: #d3ddea;
  --row-bg: #152135;
  --input-bg: #0c1523;
  --placeholder: #8798ae;
  --hover-border: #a2b3ca;
  --focus: #f1c16d;
  --focus-bg: #1b293e;
  --error-bg: #3a1726;
  --shadow: #00000040;
  color: var(--text);
  background: var(--bg);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f9f7f2;
  --panel: #fffdf9;
  --text: #4c4741;
  --muted: #71695e;
  --label: #76634e;
  --red: #b9082a;
  --line: #e8dfd1;
  --border: #9c8d79;
  --heading-bg: #eee8de;
  --heading-text: #665d51;
  --row-bg: #f8f5ef;
  --input-bg: #ffffff;
  --placeholder: #786f64;
  --hover-border: #76634e;
  --focus: #986b25;
  --focus-bg: #fff9eb;
  --error-bg: #fff0f3;
  --shadow: #76634e25;
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.workspace {
  height: 100vh;
  height: 100dvh;
  max-width: 1440px;
  margin: auto;
  padding: 0 32px;
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr) 28px;
}
header { display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 14px; font-size: 16px; font-weight: 700; }
.brand img { width: 75px; height: 30px; }
.back { font-size: 12px; color: var(--muted); }
main {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) calc(50vh - 28px);
  grid-template-rows: minmax(0, 1fr) calc(50dvh - 28px);
  gap: 10px;
  padding-top: 8px;
}
.summary {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  padding: 8px 24px 12px;
  display: grid;
  grid-template-rows: 24px 24px minmax(0, 1fr) auto;
  background: var(--panel);
  border: none;
  border-radius: 10px;
}
.summary-heading { display: flex; align-items: center; justify-content: space-between; }
.summary-heading h1 { font-size: 16px; margin: 0; font-weight: 600; }
.summary-heading > span { font-size: 12px; color: var(--muted); }
.amount-label { font-size: 18px; text-align: center; font-weight: 650; color: var(--label); }
.amount-label span { font-size: 12px; margin-left: 8px; font-weight: 400; }
.grand-amount { display: flex; justify-content: center; align-items: baseline; align-self: center; gap: 12px; min-width: 0; line-height: 1.05; color: var(--red); }
.grand-amount output { min-width: 0; white-space: nowrap; font-size: clamp(56px, 10vw, 148px); font-weight: 800; letter-spacing: -.035em; }
.currency { flex: none; font-size: 26px; font-weight: 600; }
.unit { flex: none; font-size: 20px; }
.counts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; border-top: 1px solid var(--line); padding-top: 8px; text-align: center; }
.counts > div { min-width: 0; }
.counts span { display: block; font-size: 16px; color: var(--label); white-space: nowrap; }
.counts output { display: block; white-space: nowrap; font-size: 42px; font-weight: 750; line-height: 1.15; color: var(--red); }
.entry { grid-column: 1 / -1; grid-row: 2; min-height: 0; display: grid; grid-template-rows: 22px minmax(0, 1fr) 20px; }
.entry-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.entry-heading h2 { margin: 0; font-size: 13px; }
.entry-heading p { font-size: 11px; color: var(--muted); margin: 0; }
table { width: 100%; height: 100%; border-spacing: 0; table-layout: fixed; background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.group-col { width: 8%; }
.money-col { width: 32%; }
thead { height: 26px; }
th { font-size: 11px; font-weight: 600; background: var(--heading-bg); color: var(--heading-text); }
th span { margin-left: 0; }
tbody th { background: var(--row-bg); color: var(--text); font-size: 16px; font-weight: 750; line-height: 1.1; white-space: nowrap; }
td { padding: 1px 10px; border-top: 1px solid var(--line); }
tbody th { border-top: 1px solid var(--line); }
input { display: block; width: 100%; height: clamp(18px, calc(5dvh - 13px), 36px); min-height: 18px; max-height: 36px; border: 1px solid var(--border); border-radius: 3px; background: var(--input-bg); color: var(--text); line-height: 1.05; font-family: inherit; font-size: 15px; font-weight: 600; text-align: right; padding: 0 8px; font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--placeholder); font-weight: 400; }
input:hover { border-color: var(--hover-border); }
input:focus { outline: 2px solid var(--focus); outline-offset: 0; background: var(--focus-bg); }
input[aria-invalid=true] { border-color: var(--red); background: var(--error-bg); }
input.high-amount { color: var(--red); font-weight: 750; }
.million th { color: var(--red); }
#validation-status { font-size: 10px; color: var(--muted); margin: 3px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#validation-status.error { color: var(--red); }
footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 10px; }
kbd { font: inherit; color: var(--text); }
.celebration { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); background: var(--panel); color: var(--red); border: 1px solid var(--red); border-radius: 8px; padding: 10px 20px; box-shadow: 0 3px 14px var(--shadow); pointer-events: none; font-weight: 700; z-index: 3; }
.celebration:empty { display: none; }
#fireworks { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; }
@media (max-height: 700px) {
  .workspace { grid-template-rows: 40px minmax(0, 1fr) 24px; }
  main { grid-template-rows: minmax(0, 1fr) calc(50dvh - 24px); gap: 6px; padding-top: 4px; }
  .summary { padding: 4px 20px 6px; grid-template-rows: 20px 20px minmax(0, 1fr) auto; }
  .summary-heading h1 { font-size: 14px; }
  .amount-label { font-size: 16px; }
  .grand-amount output { font-size: min(10vw, 17vh); }
  .counts { padding-top: 4px; }
  .counts output { font-size: 32px; }
  .counts span { font-size: 14px; }
  .entry { grid-template-rows: 20px minmax(0, 1fr) 18px; }
  thead { height: 24px; }
  input { font-size: 14px; }
}
@media (max-width: 640px) {
  .workspace { padding: 0 10px; grid-template-rows: 42px minmax(0, 1fr) 32px; }
  main { grid-template-rows: minmax(0, 1fr) calc(50dvh - 32px); gap: 6px; padding-top: 5px; }
  .brand { font-size: 13px; gap: 8px; }
  .brand img { width: 62px; }
  .back { font-size: 11px; }
  .summary { padding: 8px 10px; grid-template-rows: 22px 24px minmax(0, 1fr) auto; }
  .summary-heading h1 { font-size: 14px; }
  .summary-heading > span { font-size: 10px; }
  .amount-label { font-size: 17px; }
  .grand-amount { gap: 5px; }
  .grand-amount output { font-size: 16vw; }
  .currency { font-size: 16px; }
  .unit { font-size: 13px; }
  .counts { gap: 8px; padding-top: 8px; }
  .counts span { font-size: 12px; }
  .counts output { font-size: 30px; }
  .entry-heading h2 { font-size: 12px; }
  .entry-heading p { font-size: 9px; }
  .group-col { width: 10%; }
  .money-col { width: 34%; }
  thead { height: 30px; }
  th { font-size: 9px; }
  th span { display: block; margin: 0; }
  tbody th { font-size: 12px; }
  td { padding: 1px 3px; }
  input { height: clamp(17px, calc(5dvh - 14px), 36px); font-size: 13px; padding: 0 3px; min-height: 17px; }
  footer { display: block; padding-top: 2px; font-size: 8px; line-height: 1.6; }
  footer > span { display: block; }
  #validation-status { font-size: 9px; }
  .celebration { font-size: 12px; white-space: nowrap; padding: 8px 12px; }
}

.guide { position: fixed; top: 12px; right: 16px; width: 330px; z-index: 4; padding: 0; }
.guide summary { font-size: 11px; font-weight: 650; color: var(--label); cursor: pointer; }
.guide h2 { font-size: 14px; color: var(--red); margin: 10px 0 5px; }
.guide ol { margin: 0; padding-left: 23px; font-size: 13px; line-height: 1.8; }
.guide li { padding-left: 2px; margin-bottom: 4px; white-space: nowrap; }
.guide dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 8px; row-gap: 6px; margin: 0; font-size: 12px; line-height: 1.8; }
.guide dt { font-weight: 700; margin: 0; }
.guide dd { margin: 0; color: var(--muted); white-space: nowrap; }
@media (max-width: 1799px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .guide { position: fixed; top: 10px; right: 12px; width: auto; z-index: 4; padding: 0; }
  .guide summary { font-size: 11px; }
  .guide-content { position: absolute; right: 0; top: 25px; width: min(340px, calc(100vw - 24px)); max-height: calc(100dvh - 60px); overflow-y: auto; padding: 8px 18px 18px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 24px var(--shadow); }
  .guide li, .guide dd { white-space: normal; }
  .guide dl { display: block; font-size: 13px; }
  .guide dt { margin-top: 8px; }
}

.theme-toggle { font: inherit; font-size: 12px; font-weight: 650; min-height: 30px; padding: 4px 12px; border: 1px solid var(--border); border-radius: 5px; background: var(--panel); color: var(--text); cursor: pointer; }
.theme-toggle:hover { border-color: var(--hover-border); background: var(--heading-bg); }
.theme-toggle[hidden] { display: none; }
::selection { background: var(--red); color: var(--bg); }
input { caret-color: var(--red); }
