/* Shared visual foundation for the six public pages. Page-specific layouts stay local. */
:root {
  color-scheme: light;
  --bg: #f4f6fa;
  --card: #fff;
  --surface: #fff;
  --surface-soft: #f7f9fc;
  --text: #1e293b;
  --muted: #637187;
  --line: #e0e6ef;
  --primary: #285fcb;
  --primary-soft: #edf3ff;
  --red: #c82c42;
  --blue: #285fcb;
  --green: #147a51;
  --shadow: 0 6px 24px rgba(26, 47, 78, .045);
}

.site-ui { background: var(--bg); color: var(--text); font-family: "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
.site-ui .page { width: min(1120px, calc(100% - 40px)); margin: 0 auto; padding: 0 0 40px; }
.site-ui button, .site-ui a, .site-ui textarea { -webkit-tap-highlight-color: transparent; }
.site-ui button:focus-visible, .site-ui a:focus-visible, .site-ui textarea:focus-visible { outline: 3px solid #85a9f2; outline-offset: 3px; }
.site-ui .global-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0; margin-bottom: 24px; border-bottom: 1px solid var(--line); }
.site-ui .nav-brand { color: #253751; font-size: 17px; font-weight: 800; letter-spacing: .08em; text-decoration: none; white-space: nowrap; }
.site-ui .nav-links { display: flex; gap: 5px; }
.site-ui .nav-links a { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 15px; border-radius: 9px; color: #5d6a7f; text-decoration: none; font-size: 13px; font-weight: 700; white-space: nowrap; }
.site-ui .nav-links a:hover { background: #e9eef7; }
.site-ui .nav-links a.active { background: var(--primary-soft); color: var(--primary); }
.site-ui header, .site-ui .site-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 18px; margin: 0 0 22px; padding: 0; border: 0; border-radius: 0; background: none; overflow: visible; }
.site-ui header::after { content: none; }
.site-ui h1 { margin: 0; color: #22334b; font: 750 clamp(26px, 3.4vw, 34px)/1.35 "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif; letter-spacing: .02em; }
.site-ui .brand { gap: 12px; }
.site-ui .brand-seal, .site-ui .brand-mark { width: 44px; height: 44px; flex: 0 0 44px; border: 1px solid #d8e3f6; border-radius: 12px; background: var(--primary-soft); color: var(--primary); transform: none; box-shadow: none; }
.site-ui .title-line { display: none; }
.site-ui .subtitle, .site-ui .sub { display: block; margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; letter-spacing: 0; }
.site-ui .eyebrow { margin-bottom: 5px; font-size: 11px; }
.site-ui .year { padding: 8px 12px; border-color: var(--line); color: var(--muted); box-shadow: none; }
.site-ui .btn, .site-ui .back, .site-ui .copy { min-height: 44px; border-radius: 10px; font-size: 13px; }
.site-ui .back { display: inline-flex; align-items: center; background: #fff; border-color: var(--line); color: var(--primary); }
.site-ui .btn { background: #fff; border-color: #d2dbe8; color: #46566e; padding: 10px 17px; }
.site-ui .btn.primary, .site-ui .copy { background: var(--primary); color: #fff; border-color: var(--primary); }
.site-ui .btn:hover:not(:disabled), .site-ui .back:hover { background: var(--primary-soft); border-color: #9bb8ee; transform: none; }
.site-ui .btn.primary:hover:not(:disabled), .site-ui .copy:hover { background: #204eaa; color: #fff; }
.site-ui .card, .site-ui .panel, .site-ui .result-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.site-ui .card { padding: 24px; }
.site-ui .hint { color: var(--muted); font-size: 13px; line-height: 1.7; }
.site-ui textarea { border-color: #d6dfec; border-radius: 10px; background: #fafbfd; color: var(--text); }
.site-ui .actions { gap: 10px; align-items: center; }
.site-ui footer { margin-top: 26px; color: #718096; font-size: 11px; line-height: 1.8; overflow-wrap: anywhere; }

/* Compact rule selection; visual rows and calculation categories stay independent. */
.calculator-page .global-nav { padding: 10px 0; margin-bottom: 12px; }
.calculator-page header { gap: 10px; margin-bottom: 10px; }
.calculator-page h1 { font-size: 28px; }
.calculator-page .brand-seal { width: 38px; height: 38px; flex-basis: 38px; }
.calculator-page .subtitle { margin-top: 2px; font-size: 11px; line-height: 1.4; }
.calculator-page .year { padding: 6px 10px; }
.calculator-page .result-card { position: sticky; top: 6px; z-index: 10; max-height: calc(100vh - 12px); max-height: calc(100dvh - 12px); overflow-y: auto; overscroll-behavior: contain; padding: 12px; background: #fff; backdrop-filter: none; }
.calculator-page .count { color: #36475f; font-size: 14px; }
.calculator-page .count b { font-size: 24px; font-variant-numeric: tabular-nums; }
.calculator-page #result { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 8px; height: 120px; min-height: 120px; max-height: none; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px; margin: 8px 0; border-color: #e0e7f2; background: #f8fafd; }
.calculator-page #result.empty { align-items: center; justify-content: center; height: 120px; min-height: 120px; padding: 10px; color: var(--muted); font: 14px/1.5 "PingFang TC", "Microsoft JhengHei", sans-serif; }
.calculator-page #result .num { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; flex: 0 0 44px; border: 4px solid; border-radius: 50%; background: #fff; color: #172033; font: 700 23px/1 Consolas, monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calculator-page #result .num.red { border-color: var(--red); }
.calculator-page #result .num.blue { border-color: var(--blue); }
.calculator-page #result .num.green { border-color: var(--green); }
.calculator-page .rules { display: block; margin-top: 8px; padding: 8px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.calculator-page .rule-group { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; padding: 5px 0; }
.calculator-page .rule-group:first-child { padding-top: 0; }
.calculator-page .rule-group:last-child { padding-bottom: 0; }
.calculator-page .rule-group + .rule-group { border-top: 1px solid #e5eaf1; }
.calculator-page .choice { position: relative; min-width: 0; min-height: 44px; padding: 6px 2px; border-radius: 7px; border: 1px solid #dbe3ee; color: #46566d; background: #fafbfd; font-size: 16px; font-weight: 700; line-height: 1.2; }
.calculator-page .choice-detailed { grid-column: span 3; font-size: 15px; }
.calculator-page .choice.selected { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); font-weight: 800; }
.calculator-page .choice[data-color="red"] { --choice-ink: var(--red); --choice-soft: #fff1f3; }
.calculator-page .choice[data-color="blue"] { --choice-ink: var(--blue); --choice-soft: #edf3ff; }
.calculator-page .choice[data-color="green"] { --choice-ink: var(--green); --choice-soft: #edf8f2; }
.calculator-page .choice[data-color] { color: var(--choice-ink); background: var(--choice-soft); }
.calculator-page .choice[data-color].selected { border-color: var(--choice-ink); box-shadow: inset 0 0 0 1px var(--choice-ink); }
.calculator-page #feedback { min-width: 0; }
.calculator-page footer { margin-top: 12px; }

@media (hover: hover) and (pointer: fine) {
  .calculator-page .choice:hover { border-color: #88a9e6; background: var(--primary-soft); }
}

@media (hover: none), (pointer: coarse) {
  .calculator-page .choice { transition: none; }
}

/* Input tools. */
.analyzer-page .card, .common-page .card { max-width: 920px; margin: 0 auto; }
.analyzer-page textarea { min-height: 120px; }
.analyzer-page .summary { padding: 12px 14px; background: var(--primary-soft); }
.analyzer-page .result-section { padding: 18px 0; }
.analyzer-page .attribute-group { padding: 12px; border-color: var(--line); background: #fafbfd; }
.common-page .groups { gap: 12px; }
.common-page .group-input { height: 66px; padding: 11px; }
.common-page .group-row { grid-template-columns: 52px minmax(0, 1fr) 44px; }
.common-page .remove { width: 44px; height: 44px; border-radius: 10px; }
.common-page .result { padding: 16px; margin-top: 20px; border-color: var(--line); }
.common-page .result-head { flex-wrap: wrap; }
.common-page .result-head > span:last-child { display: inline-flex; align-items: center; flex-wrap: wrap; gap: 4px; }

/* Record pages retain the existing responsive seven-ball layouts. */
.records-page .header-actions { flex-wrap: wrap; }
.records-page .record-switch { gap: 3px; background: #fff; border-color: var(--line); }
.records-page .record-link { display: flex; align-items: center; justify-content: center; min-height: 44px; }
.records-page .record-link.active { background: var(--primary); box-shadow: none; }
.records-page .current-panel { padding: 24px; }
.records-page .current-panel::before { height: 3px; background: var(--primary); }
.records-page .ball { box-shadow: inset 0 -3px 5px rgba(0,0,0,.08); }
.records-page .ball::after { content: none; }
.records-page .ball.red { background: var(--red); border-color: var(--red); }
.records-page .ball.blue { background: var(--blue); border-color: var(--blue); }
.records-page .ball.green { background: var(--green); border-color: var(--green); }
.records-page .metric { padding: 13px; background: #f8fafd; border-color: #e5ebf3; }
.records-page .metric-label { color: var(--muted); font-size: 11px; }
.records-page .metric strong { white-space: normal; overflow: visible; overflow-wrap: anywhere; line-height: 1.6; }
.records-page .status { line-height: 1.5; }
.records-page .history-panel { padding: 22px; margin-top: 18px; }
.records-page .history-list { gap: 8px; }
.records-page .history-row { grid-template-columns: 240px minmax(0, 1fr); background: #fff; border-color: #e7ecf3; padding: 12px; }
.records-page .history-meta { flex-wrap: wrap; }
.records-page .history-tag { flex-shrink: 0; white-space: nowrap; }
.records-page .history-row:first-child { background: #f5f8ff; border-color: #d4e1f7; }
.records-page .source-note, .records-page .updated, .records-page .history-date { color: #66758a; }

@media (max-width: 720px) {
  .site-ui .page { width: calc(100% - 24px); padding-bottom: 28px; }
  .site-ui .global-nav { margin-bottom: 20px; gap: 10px; padding: 15px 0 12px; }
  .site-ui .nav-brand { font-size: 15px; }
  .site-ui .nav-links { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .site-ui .nav-links a { padding: 0 4px; font-size: 12px; }
  .site-ui header, .site-ui .site-header { gap: 12px; margin-bottom: 18px; }
  .site-ui h1 { font-size: 26px; }
  .site-ui .subtitle, .site-ui .sub { font-size: 12px; line-height: 1.6; }
  .site-ui .brand { align-items: flex-start; }
  .site-ui .card { padding: 16px; }
  .calculator-page .global-nav { padding: 8px 0; margin-bottom: 10px; }
  .calculator-page header { gap: 8px; margin-bottom: 8px; }
  .calculator-page h1 { font-size: 24px; }
  .calculator-page .brand-seal { width: 35px; height: 35px; flex-basis: 35px; }
  .calculator-page .subtitle { font-size: 10px; line-height: 1.35; }
  .calculator-page .result-card { top: 4px; max-height: calc(100vh - 8px); max-height: calc(100dvh - 8px); padding: 10px; }
  .calculator-page #result { height: 206px; min-height: 206px; margin: 6px 0; padding: 8px; }
  .calculator-page #result.empty { height: 206px; min-height: 206px; padding: 8px; }
  .calculator-page #result .num { width: 32px; height: 32px; flex-basis: 32px; border-width: 3px; font-size: 16px; }
  .calculator-page .rules { margin-top: 6px; padding: 5px; }
  .calculator-page .rule-group { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; padding: 5px 0; }
  .calculator-page .choice { min-height: 48px; padding: 5px 1px; font-size: 14px; font-weight: 400; white-space: normal; overflow-wrap: anywhere; }
  .calculator-page .choice-detailed { grid-column: span 3; font-size: 12px; }
  .calculator-page footer { margin-top: 10px; }
  .analyzer-page .group-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analyzer-page .attribute-group { gap: 5px; padding: 9px; }
  .common-page .group-row { grid-template-columns: 42px minmax(0, 1fr) 44px; gap: 6px; }
  .common-page .group-label { font-size: 12px; }
  .records-page .header-actions { width: 100%; }
  .records-page .record-switch { width: 100%; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .records-page .record-link { padding: 7px 4px; font-size: 12px; }
  .records-page .current-panel { padding: 18px 12px; }
  .records-page .history-panel { padding: 16px 10px; }
  .records-page .history-row { padding: 10px 8px; }
  .records-page .history-numbers { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)) 8px minmax(0, 1fr); gap: 4px; }
  .records-page .history-number-wrap { width: 100%; max-width: 42px; }
  .records-page .history-plus { height: 34px; }
  .records-page .metric { padding: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .site-ui *, .site-ui *::before, .site-ui *::after { transition: none !important; scroll-behavior: auto !important; }
}
