:root {
  --bg: #0d1117;
  --surface: #0b0f14;
  --surface-raised: #111720;
  --surface-soft: #151b25;
  --border: #303846;
  --border-soft: #242c38;
  --text: #f3f6fb;
  --muted: #9aa5b4;
  --muted-blue: #aac8f6;
  --blue: #2f6fec;
  --blue-hover: #3d7af0;
  --coral: #ff6b75;
  --green: #26d6a0;
  --amber: #ffb11b;
  --purple: #a879ff;
  --danger-bg: #35161b;
  --danger-border: #7b2933;
  --radius: 10px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 72% -20%, rgba(47, 111, 236, 0.08), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select { font: inherit; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(48, 56, 70, 0.78);
  background: rgba(13, 17, 23, 0.93);
  backdrop-filter: blur(16px);
}

.header-inner {
  width: min(1120px, calc(100% - 48px));
  min-height: 68px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  color: var(--text);
  font-weight: 720;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 1px solid #4f7bd0;
  border-radius: 8px;
  background: linear-gradient(145deg, #2f6fec, #174799);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 8px 24px rgba(47,111,236,.18);
  color: white;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
}

.brand-mark-large { width: 40px; height: 40px; border-radius: 11px; font-size: 11px; }

.main-nav { align-self: stretch; display: flex; gap: 4px; align-items: center; }
.main-nav a {
  position: relative;
  display: grid;
  align-items: center;
  height: 100%;
  padding: 0 16px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.main-nav a:hover { color: var(--text); }
.main-nav a.active { color: var(--text); }
.main-nav a.active::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: -1px;
  left: 16px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--blue);
}

.logout-form { justify-self: end; }

.page-shell {
  width: min(1040px, calc(100% - 48px));
  margin: 0 auto;
  padding: 58px 0 88px;
}

.page-heading { margin-bottom: 22px; }
.page-heading h1, .result-heading h1, .empty-state h1, .access-card h1 {
  margin: 4px 0 10px;
  color: #f7f8fb;
  font-size: clamp(30px, 4vw, 38px);
  line-height: 1.14;
  letter-spacing: -0.035em;
}
.page-heading p, .result-heading p, .empty-state p, .lede {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.eyebrow, .score-label {
  color: var(--muted-blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
}

.panel, .score-hero, .score-card, .map-panel, .report-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(10, 14, 20, 0.72);
}

.tool-form { padding: 20px; }
.field-group { display: grid; gap: 8px; width: 100%; }
label { color: #f6f8fc; font-size: 13px; font-weight: 650; }
label span { color: var(--muted); font-weight: 500; }

input[type="url"], input[type="number"], input[type="password"], input[type="text"], select {
  width: 100%;
  height: 43px;
  border: 1px solid transparent;
  border-radius: 9px;
  outline: none;
  background: #080c12;
  color: var(--text);
  padding: 0 13px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.01);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: #758299; }
input:focus { border-color: #3b6dc8; box-shadow: 0 0 0 3px rgba(47,111,236,.15); }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9aa5b4 50%), linear-gradient(135deg, #9aa5b4 50%, transparent 50%); background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px; background-size: 5px 5px; background-repeat: no-repeat; }
.text-link { display: inline-block; margin-top: 10px; color: #7fb3ff; text-decoration: none; font-weight: 650; }

.field-help { margin: -2px 0 0; color: var(--muted); font-size: 12px; }
.form-action-row {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
  align-items: end;
  gap: 16px;
  margin-top: 16px;
}

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0 16px;
  color: white;
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .15s, opacity .15s;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: .78; transform: none; }
.button-primary { background: var(--blue); box-shadow: 0 8px 24px rgba(47,111,236,.16); }
.button-primary:hover { background: var(--blue-hover); }
.button-danger { border-color: var(--danger-border); background: var(--danger-bg); color: #ffc8cd; }
.button-danger:hover { background: #491b22; }
.button-quiet { border-color: var(--border); background: #111722; }
.button-quiet:hover { border-color: #485467; background: #151d2a; }
.button-large { min-height: 43px; }
.button-small { min-height: 34px; padding: 0 13px; font-size: 12px; }
.button-full { width: 100%; min-height: 44px; margin-top: 5px; }
.button-group { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.spinner { display: none; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.42); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
.is-loading .spinner { display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

.info-strip {
  display: flex;
  gap: 13px;
  align-items: flex-start;
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #1b426a;
  border-radius: 9px;
  background: #17324e;
  color: #b9d8ff;
}
.info-strip strong { color: #e5f2ff; }
.info-dot { flex: 0 0 auto; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: #47a3ff; box-shadow: 0 0 0 4px rgba(71,163,255,.12); }

.flash-stack { margin-bottom: 18px; }
.notice { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; }
.notice-error { border-color: var(--danger-border); background: var(--danger-bg); color: #ffc8cd; }
.notice-success { border-color: #196b52; background: #103127; color: #adf3db; }

.auth-page { display: grid; place-items: center; }
.page-shell-auth { width: min(430px, calc(100% - 32px)); padding: 70px 0; }
.access-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(12, 16, 22, .93);
  box-shadow: var(--shadow);
  padding: 34px;
}
.access-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.access-card h1 { font-size: 31px; }
.access-card .lede { margin-bottom: 24px; }
.stack-form { display: grid; gap: 9px; }
.form-footnote { margin: 18px 0 0; color: #758092; font-size: 12px; text-align: center; }
.access-card .notice { margin-bottom: 16px; }

.result-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}
.result-heading h1 { font-size: 29px; margin-bottom: 5px; }
.result-heading p { overflow-wrap: anywhere; }

.score-hero { padding: 24px; }
.score-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.score-number { margin-top: 7px; color: var(--coral); font-size: 44px; font-weight: 780; line-height: 1; letter-spacing: -.045em; }
.score-number span { font-size: 22px; }
.score-fraction { color: var(--muted-blue); font-size: 12px; }
.progress-track { height: 8px; margin-top: 18px; overflow: hidden; border-radius: 99px; background: #222b39; }
.progress-fill { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--blue); }
.progress-total { background: var(--coral); }

.score-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 14px; }
.score-card { padding: 16px; }
.score-card-value { margin-top: 8px; font-size: 24px; font-weight: 740; letter-spacing: -.025em; }
.score-card-value span { color: #71809a; font-size: 12px; font-weight: 500; }
.progress-small { height: 4px; margin-top: 11px; }
.score-1 .progress-fill { background: #6b7381; }
.score-2 .progress-fill { background: var(--amber); }
.score-3 .progress-fill { background: var(--green); }
.score-4 .progress-fill { background: var(--purple); }

.section-block { margin-top: 42px; }
.section-block h2 { margin: 4px 0 14px; font-size: 23px; letter-spacing: -.025em; }
.section-title-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border-soft); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; background: rgba(10,14,20,.45); font-variant-numeric: tabular-nums; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); text-align: left; white-space: nowrap; }
th { background: #181d27; color: #a9b8ce; font-size: 12px; font-weight: 560; }
td { color: #ecf1f8; font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.total-row td { background: #111824; font-weight: 700; }
tr.is-excluded td { color: #8b97a8; font-style: italic; }
.score-card.is-excluded { opacity: .6; }
.score-card-excluded { color: #8b97a8; font-style: italic; font-weight: 600; }
.percent-pill { display: inline-flex; min-width: 67px; justify-content: flex-end; border-radius: 5px; padding: 4px 8px; font-weight: 700; }
.percent-pill.good { background: #075c46; color: #74f3cd; }
.percent-pill.fair { background: #63450d; color: #ffd986; }
.percent-pill.low { background: #7c2025; color: #ffb4b9; }
.status { display: inline-flex; align-items: center; gap: 6px; color: #c7d1df; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.status-error::before { background: var(--coral); }
.status-muted { color: #8b97a8; }
.status-muted::before { background: #6b7688; }

.report-details { margin-top: 22px; padding: 0 16px; }
.report-details summary { cursor: pointer; padding: 14px 0; font-weight: 650; }
.report-details pre { max-height: 520px; overflow: auto; margin: 0 0 16px; border-top: 1px solid var(--border-soft); padding: 16px 0; color: #c6d0df; font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; }

.upload-panel { display: grid; grid-template-columns: minmax(0, 1fr) 245px; gap: 16px; align-items: stretch; padding: 14px; }
.upload-zone {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  border-radius: 9px;
  background: #080c12;
  padding: 12px;
  cursor: pointer;
}
.upload-zone:hover { box-shadow: inset 0 0 0 1px #38465a; }
.upload-icon { display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px; border: 1px solid #3a4556; border-radius: 8px; color: white; font-size: 20px; }
.upload-copy { min-width: 0; display: grid; gap: 1px; }
.upload-copy strong { font-size: 13px; }
.upload-copy small { color: var(--muted); font-size: 11px; }
.file-name { max-width: 400px; overflow: hidden; color: #7fb7ff; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.upload-button { margin-left: auto; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

.map-panel { overflow: hidden; }
.map-toolbar { min-height: 50px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); padding: 0 14px; background: #111722; }
.map-toolbar div { display: flex; align-items: center; gap: 9px; }
.map-toolbar a { color: #7fb3ff; font-size: 12px; text-decoration: none; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(38,214,160,.11); }
.map-frame { display: block; width: 100%; height: min(68vh, 690px); min-height: 520px; border: 0; background: #d8dfe3; }
.result-meta-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 16px; overflow: hidden; border: 1px solid var(--border); border-radius: 9px; background: var(--border); }
.result-meta-grid div { display: grid; gap: 3px; padding: 14px; background: #101620; }
.result-meta-grid span { color: var(--muted); font-size: 11px; }
.result-meta-grid strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-actions { margin-top: 18px; }

.management-panel { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-top: 16px; padding: 14px; }
.inline-form { display: flex; align-items: end; gap: 10px; flex: 1; }
.inline-form label { min-width: max-content; }
.inline-form input { max-width: 390px; }
.wrap-cell { min-width: 220px; max-width: 440px; white-space: normal; }
.score-input { width: 95px !important; }
.library-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.library-card { display: grid; gap: 18px; padding: 18px; }
.library-card h2, .saved-view-row h3 { margin: 0 0 3px; font-size: 18px; }
.library-card h2 a, .saved-view-row h3 a { text-decoration: none; }
.library-card p, .saved-view-row p, .compact-empty p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.library-card dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0; }
.library-card dl div { display: grid; gap: 2px; }
.library-card dt { color: var(--muted); font-size: 11px; }
.library-card dd { margin: 0; }
.library-card .button { justify-self: start; }
.variant-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 18px; }
.variant-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 10px; }
.variant-actions input { max-width: 250px; }
.saved-view-list { display: grid; gap: 10px; }
.saved-view-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px; }
.saved-view-row form { display: inline-flex; }
.compact-empty { padding: 18px; }

.empty-state { max-width: 510px; margin: 10vh auto 0; text-align: center; }
.empty-mark { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 18px; border: 1px solid var(--danger-border); border-radius: 50%; background: var(--danger-bg); color: #ffabb2; font-weight: 800; }
.empty-state p { margin-bottom: 24px; }

@media (max-width: 800px) {
  .header-inner { width: min(100% - 28px, 1120px); grid-template-columns: 1fr auto; min-height: 62px; }
  .main-nav { order: 3; grid-column: 1 / -1; height: 45px; justify-content: center; border-top: 1px solid var(--border-soft); }
  .logout-form { grid-column: 2; grid-row: 1; }
  .page-shell { width: min(100% - 32px, 1040px); padding-top: 40px; }
  .form-action-row, .upload-panel { grid-template-columns: 1fr; }
  .variant-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .management-panel { align-items: stretch; flex-direction: column; }
  .inline-form { width: 100%; }
  .score-grid { grid-template-columns: repeat(2, 1fr); }
  .result-heading { align-items: flex-start; flex-direction: column; }
  .button-group { justify-content: flex-start; }
  .map-frame { min-height: 430px; }
}

@media (max-width: 520px) {
  .page-shell { width: min(100% - 24px, 1040px); padding-top: 30px; }
  .header-inner { width: calc(100% - 24px); }
  .brand > span:last-child { display: none; }
  .main-nav a { padding: 0 10px; font-size: 12px; }
  .main-nav a.active::after { left: 10px; right: 10px; }
  .tool-form, .score-hero { padding: 16px; }
  .score-grid { grid-template-columns: 1fr; }
  .score-number { font-size: 39px; }
  .score-fraction { align-self: flex-end; }
  .section-title-row { align-items: flex-start; flex-direction: column; }
  .section-title-row .button, .button-group .button { width: 100%; }
  .button-group { width: 100%; }
  .upload-zone { align-items: flex-start; }
  .upload-button { display: none; }
  .result-meta-grid { grid-template-columns: 1fr; }
  .map-frame { min-height: 360px; height: 58vh; }
  .access-card { padding: 25px 20px; }
  .library-grid, .variant-form { grid-template-columns: 1fr; }
  .variant-actions, .inline-form, .saved-view-row { align-items: stretch; flex-direction: column; }
  .variant-actions input, .inline-form input { max-width: none; }
  .saved-view-row .button-group { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
