:root {
  color-scheme: light;
  --navy-950: #071d31;
  --navy-900: #0b2b49;
  --blue-800: #0b3b66;
  --blue-700: #0c568b;
  --teal-600: #067c78;
  --teal-500: #0a9790;
  --teal-100: #d9f4f1;
  --sky-100: #e8f3fb;
  --ink: #10283d;
  --muted: #526779;
  --line: #c8d7e2;
  --surface: #ffffff;
  --canvas: #f3f7fa;
  --success: #0b6b50;
  --warning: #9a5b00;
  --danger: #9f2936;
  --shadow: 0 12px 34px rgba(7, 29, 49, 0.10);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { margin: 0; min-height: 100%; color: var(--ink); background: radial-gradient(circle at top right, #d8eef7 0, transparent 35rem), var(--canvas); }
button, input, select { font: inherit; }
button, .file-button { min-height: 44px; }
button:focus-visible, input:focus-visible, select:focus-visible, .file-button:focus-within { outline: 3px solid #f0a44b; outline-offset: 2px; }
[hidden] { display: none !important; }
.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .75rem 1rem; background: white; color: var(--navy-950); border-radius: .5rem; }
.skip-link:focus { top: 1rem; }

.app-header { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: max(1rem, env(safe-area-inset-top)) 1rem 1rem; color: white; background: linear-gradient(120deg, var(--navy-950), var(--blue-800) 60%, var(--teal-600)); }
.brand-lockup { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 auto; border-radius: 14px; color: var(--navy-950); background: linear-gradient(145deg, #a8fff5, #5bc6dc); font-size: 1.35rem; font-weight: 850; box-shadow: inset 0 0 0 1px rgba(255,255,255,.55); }
h1 { margin: .08rem 0 0; font-size: clamp(1.05rem, 5vw, 1.45rem); line-height: 1.12; letter-spacing: -.02em; }
h2 { margin: .15rem 0 0; font-size: clamp(1.45rem, 6vw, 2.2rem); line-height: 1.08; letter-spacing: -.035em; }
h2:focus { outline: none; }
h3 { margin: 0 0 .45rem; font-size: 1.05rem; }
p { line-height: 1.55; }
.eyebrow { margin: 0; color: inherit; font-size: .72rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; opacity: .78; }
.header-actions { display: flex; gap: .5rem; align-items: center; }
.status-chip, .version-badge, .badge { display: inline-flex; align-items: center; min-height: 30px; padding: .3rem .62rem; border-radius: 999px; font-size: .76rem; font-weight: 750; }
.status-chip { color: white; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25); }
.version-badge { color: var(--blue-800); background: var(--sky-100); }
.badge { color: var(--blue-800); background: var(--sky-100); }
.badge.success { color: var(--success); background: #ddf3e9; }
.badge.warning { color: var(--warning); background: #fff0cf; }
.badge.danger { color: var(--danger); background: #fde4e6; }

.app-nav { position: sticky; top: 0; z-index: 20; display: flex; overflow-x: auto; gap: .15rem; padding: .55rem .4rem; background: rgba(255,255,255,.96); border-bottom: 1px solid var(--line); box-shadow: 0 5px 18px rgba(7,29,49,.06); }
.nav-button { flex: 0 0 auto; padding: .58rem .64rem; border: 0; border-radius: 999px; color: var(--muted); background: transparent; font-size: .82rem; font-weight: 750; cursor: pointer; }
.nav-button.is-active { color: white; background: var(--blue-800); }

main { width: min(1180px, 100%); margin: 0 auto; padding: 1.1rem .85rem 3.5rem; }
.panel { animation: reveal .18s ease-out both; }
@keyframes reveal { from { opacity: .4; transform: translateY(4px); } }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin: .35rem .2rem 1rem; }
.section-heading .eyebrow { color: var(--teal-600); opacity: 1; }
.surface, .result-card, .data-card { min-width: 0; background: var(--surface); border: 1px solid rgba(143,165,181,.42); border-radius: var(--radius); box-shadow: var(--shadow); }
.surface { padding: 1rem; }
.stack { display: grid; gap: 1rem; }
.grid { display: grid; gap: .85rem; }
.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: .7rem; }
.metric { min-height: 105px; padding: .9rem; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(145deg, #fff, #f6fbfd); }
.metric span { display: block; color: var(--muted); font-size: .76rem; font-weight: 760; line-height: 1.25; text-transform: uppercase; letter-spacing: .06em; }
.metric strong { display: block; margin-top: .45rem; color: var(--navy-950); font-size: clamp(1.25rem, 7vw, 2rem); line-height: 1; letter-spacing: -.03em; overflow-wrap: anywhere; }
.metric small { display: block; margin-top: .35rem; color: var(--muted); }
.winner-card { position: relative; overflow: hidden; padding: 1.15rem; color: white; background: linear-gradient(135deg, var(--navy-950), var(--blue-800) 60%, var(--teal-600)); border-radius: var(--radius); box-shadow: 0 18px 46px rgba(7,29,49,.22); }
.winner-card::after { content: ""; position: absolute; right: -65px; bottom: -90px; width: 210px; height: 210px; border-radius: 50%; background: rgba(91,220,210,.16); }
.winner-label { position: relative; z-index: 1; margin: 0; color: #a7f4ed; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .12em; }
.winner-name { position: relative; z-index: 1; margin: .35rem 0 .15rem; font-size: clamp(1.8rem, 10vw, 3.1rem); line-height: 1; letter-spacing: -.05em; }
.winner-value { position: relative; z-index: 1; margin: .5rem 0 0; font-size: 1.05rem; }
.difference { color: #a7f4ed; font-weight: 800; }
.explanation { position: relative; z-index: 1; display: grid; gap: .55rem; margin: 1rem 0 0; padding: 1rem; background: rgba(255,255,255,.09); border: 1px solid rgba(255,255,255,.18); border-radius: 14px; }
.explanation div { display: grid; grid-template-columns: 7.2rem minmax(0,1fr); gap: .5rem; align-items: start; }
.explanation dt { color: #a7f4ed; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.explanation dd { margin: 0; line-height: 1.45; overflow-wrap: anywhere; }
.result-card, .data-card { padding: 1rem; }
.card-header { display: flex; min-width: 0; flex-wrap: wrap; align-items: start; justify-content: space-between; gap: .7rem; margin-bottom: .75rem; }
.card-header > div { min-width: 0; flex: 1 1 10rem; }
.card-header p { margin: .2rem 0 0; color: var(--muted); font-size: .88rem; }
.rank-row { display: grid; grid-template-columns: 2rem minmax(0,1fr) auto; gap: .65rem; align-items: center; padding: .72rem 0; border-top: 1px solid #e4edf3; }
.rank-row:first-child { border-top: 0; }
.rank-number { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; color: var(--blue-800); background: var(--sky-100); font-weight: 850; }
.rank-value { text-align: right; font-weight: 800; }
.rank-value small { display: block; color: var(--muted); font-weight: 500; }

.form-grid { display: grid; gap: .85rem; }
label { display: grid; gap: .35rem; color: var(--ink); font-size: .82rem; font-weight: 760; }
input, select { width: 100%; min-width: 0; min-height: 44px; padding: .65rem .72rem; color: var(--ink); background: white; border: 1px solid #9eb3c2; border-radius: 10px; }
input[type="checkbox"] { width: 24px; min-height: 24px; accent-color: var(--teal-600); }
.check-label { display: flex; align-items: center; gap: .55rem; min-height: 44px; }
.input-prefix { display: flex; align-items: center; background: white; border: 1px solid #9eb3c2; border-radius: 10px; overflow: hidden; }
.input-prefix > span { padding-left: .7rem; color: var(--muted); }
.input-prefix input { border: 0; }
.collection-grid { display: grid; min-width: 0; gap: .75rem; }
.editable-row { position: relative; display: grid; min-width: 0; gap: .65rem; padding: .9rem; border: 1px solid var(--line); border-radius: 14px; background: #fbfdfe; }
.row-actions { display: flex; justify-content: flex-end; }
.field-grid { display: grid; grid-template-columns: minmax(0,1fr); gap: .65rem; }
.field-grid .wide { grid-column: 1 / -1; }
.button-row { display: flex; flex-wrap: wrap; gap: .65rem; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .65rem .9rem; border: 1px solid transparent; border-radius: 10px; font-weight: 800; text-decoration: none; cursor: pointer; }
.button-primary { color: white; background: var(--blue-800); }
.button-secondary { color: var(--blue-800); background: white; border-color: #9eb3c2; }
.button-danger { color: var(--danger); background: white; border-color: #d6a2a8; }
.button-small { min-height: 44px; padding: .45rem .68rem; font-size: .8rem; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.notice { padding: .85rem 1rem; border-radius: 12px; line-height: 1.45; }
.notice-info { color: #174d68; background: #e6f4fa; border: 1px solid #b8dae7; }
.notice-error { color: #7d1f2b; background: #fdebed; border: 1px solid #efb8be; }
.empty { margin: 0; color: var(--muted); font-style: italic; }
.progress-bar { width: 100%; height: 9px; overflow: hidden; border: 0; border-radius: 999px; background: #dbe7ed; appearance: none; }
.progress-bar::-webkit-progress-bar { background: #dbe7ed; border-radius: 999px; }
.progress-bar::-webkit-progress-value { background: linear-gradient(90deg, var(--blue-700), var(--teal-500)); border-radius: 999px; }
.progress-bar::-moz-progress-bar { background: linear-gradient(90deg, var(--blue-700), var(--teal-500)); border-radius: 999px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { padding: .7rem .55rem; text-align: left; border-bottom: 1px solid #e1eaf0; white-space: nowrap; }
th { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; }
td.numeric, th.numeric { text-align: right; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: max(1rem, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(92vw, 520px); padding: .9rem 1rem; color: white; background: var(--navy-950); border-radius: 12px; box-shadow: 0 16px 42px rgba(0,0,0,.28); text-align: center; font-weight: 700; }
footer { padding: 1.2rem 1rem calc(1.2rem + env(safe-area-inset-bottom)); color: #dce8f0; background: var(--navy-950); }
footer p { width: min(980px,100%); margin: 0 auto; font-size: .8rem; }

@media (min-width: 720px) {
  .app-header { padding-inline: 2rem; }
  .app-nav { justify-content: center; }
  main { padding: 1.8rem 1.5rem 5rem; }
  .form-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .metric-grid { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .dashboard-grid { display: grid; grid-template-columns: minmax(0,1.35fr) minmax(300px,.65fr); gap: 1rem; align-items: start; }
  .collection-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .field-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (min-width: 1040px) {
  .collection-grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
