:root {
  --bg: #0e0f11; --card: #15171a; --muted: #9aa3ad; --text: #e9eef2;
  --accent: #6ee7b7; --danger: #f87171; --warn: #fbbf24; --ok: #34d399;
  --radius: 16px; --shadow: 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, #0b0c0e 0%, #0e0f11 100%);
  color: var(--text);
}

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.5rem 1rem; position: sticky; top: 0; z-index: 10;
  backdrop-filter: saturate(1.2) blur(8px);
  -webkit-backdrop-filter: saturate(1.2) blur(8px);
  background: rgba(14,15,17,.7); border-bottom: 1px solid #1f2327;
}

.wrap { max-width: 1000px; margin: 0 auto; padding: 16px; }

h1 { font-size: clamp(1.3rem, 3.5vw, 1.8rem); margin: 0; }
.sub { color: var(--muted); font-size: .95rem; margin-top: 6px; }

.github-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 0.95rem; text-decoration: none;
}
.github-link:hover { color: var(--accent); }
.github-link img { width: 28px; height: 28px; display: block; }

.grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 16px; align-items: start;
}
.col { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: var(--card); border: 1px solid #1f2327;
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 1.1rem; }
.card1 { grid-column: 1; grid-row: 1; }
.card2 { grid-column: 2; grid-row: 1; }
.card3 { grid-column: 2; grid-row: 2; }

.muted { color: var(--muted); font-size: .92rem; }

.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button, .btn {
  appearance: none; border: 1px solid #2a2f35; color: var(--text);
  padding: 10px 12px; border-radius: 12px; background: #1a1d21;
  cursor: pointer; font-weight: 600; font-size: .95rem;
}
button:hover { border-color: #3a4047; }
.btn-accent { background: #1a2320; border-color: #2a3a34; color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-duplicate { background: #232318; color: #f5ff9a; border-color: #3a3a26; }
.btn-danger { background: #23181a; color: #ff9aa3; border-color: #3a2629; }


table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: 8px; }
tbody td { padding: 6px 8px; }
tbody tr { border-top: 1px solid #21262c; }

table.modules {
  width: 100%; border-collapse: collapse; table-layout: fixed;
}
.col-level   { width: 9ch; }
.col-code    { width: 18ch; }
.col-credits { width: 8ch; }
.col-mark    { width: 8ch; }
.col-actions { width: 12ch; }

table.modules thead th { text-align: center; }
table.modules input, table.modules select {
  width: 100%; min-width: 0;
}
table.modules th, table.modules td { white-space: nowrap; }

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }

input, select {
  width: 100%; padding: 10px; border-radius: 10px;
  border: 1px solid #2a2f35; background: #0f1114;
  color: var(--text); font-size: .95rem;
}
input::placeholder { color: #66707b; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 999px; font-weight: 700; font-size: .9rem; }
.pill.ok   { background: #12201a; color: var(--ok);   border: 1px solid #204a37; }
.pill.warn { background: #261f0f; color: var(--warn); border: 1px solid #4d3b15; }
.pill.bad  { background: #2a1517; color: #ffb4b9;     border: 1px solid #4a2629; }

.kpi { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 8px; }
.kpi .tile { background: #101317; border: 1px solid #20262d; padding: 12px; border-radius: 12px; transition: background .15s ease, border-color .15s ease; }
.kpi .tile.good { background: #12201a; border-color: #204a37; }
.kpi .label { color: var(--muted); font-size: .8rem; }
.kpi .value { font-size: 1.2rem; font-weight: 800; margin-top: 2px; }

.footer { color: var(--muted); font-size: .85rem; display: flex; gap: 8px; flex-wrap: wrap; justify-content: space-between; }

.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: #111418; color: var(--text); padding: 10px 12px;
  border-radius: 12px; border: 1px solid #222830; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

.cookie-toggle { display: inline-flex; align-items: center; gap: 8px; }
.switch { position: relative; width: 48px; height: 28px; background: #1f2327; border-radius: 999px; border: 1px solid #2a2f35; }
.knob { position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; background: #0f1114; border-radius: 50%; transition: left .18s ease; border: 1px solid #2a2f35; }
.switch.on { background: #163226; border-color: #214d39; }
.switch.on .knob { left: 22px; background: #0a1310; }

.inline { display: inline-flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }
input.dup { border-color: #5b1a1e; background:#1b1011; }
.warntext { color: #fbbf24; }

.skip-link { position: absolute; left: -9999px; top: auto; }
.skip-link:focus {
  left: 1rem; top: 1rem; background: #111418; color: var(--text);
  padding: .5rem 1rem; border: 2px solid #fff; border-radius: 8px; z-index: 1000;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  box-shadow: 0 0 0 3px rgba(110, 231, 183, 0.25);
}

.site-footer {
  text-align: center; padding: 1rem; font-size: 0.85rem; color: var(--muted);
  border-top: 1px solid #1f2327; margin-top: 2rem;
}
.site-footer span[role="img"] { font-size: 1rem; vertical-align: middle; }

header a, button { min-height: 40px; min-width: 40px; }
input:invalid, select:invalid { border-color: #7a2e2e; }
input:disabled, select:disabled, button:disabled { opacity: .6; cursor: not-allowed; }

#kpiArea { contain: content; }
#warnings { border-left: 3px solid var(--warn); }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .toast { transition: none; }
}

html.contrast {
  --muted: #cbd5df; --card: #101214; --text: #ffffff;
  --accent: #9af5d5; --warn: #ffd257;
}
html.contrast .muted { color: var(--muted); }

@media (max-width: 860px) {
  .grid { grid-template-columns: 1fr; }
  .card1, .card2, .card3 { grid-column: auto; grid-row: auto; }
  .kpi { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 540px) {
  .kpi { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  thead th { padding: 10px 6px; }
  tbody td { padding: 8px 6px; }
  .row-actions { gap: 4px; }
  .btn-duplicate, .btn-danger { padding: 8px 10px; }
}
@supports not ((backdrop-filter: blur(8px)) or (-webkit-backdrop-filter: blur(8px))) {
  header { background: rgba(14,15,17,.95); }
}
@media print {
  header, .toast, #schemaDialog, .notice, #addRowBtn, #sampleBtn, #clearBtn,
  #exportBtn, #importBtn, #resetCookieBtn { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #000; }
  a { color: #000; text-decoration: underline; }
}
html, body { overflow-x: hidden; }
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.modules, table.modules th, table.modules td { min-width: 0; }
@media (max-width: 540px) {
  table.modules th, table.modules td { white-space: normal; }
    .col-level   { width: 9ch; }
    .col-code    { width: 18ch; }
    .col-credits { width: 8ch; }
    .col-mark    { width: 8ch; }
    .col-actions { width: 12ch; }
  table.modules { table-layout: auto; } 
}
table.modules input, table.modules select {
  min-width: 0;
}
@media (max-width: 420px) {
  .wrap { padding-inline: 12px; }
  thead th { padding: 8px 6px; }
  tbody td { padding: 6px; }
  .row-actions { gap: 4px; }
  .btn-duplicate, .btn-danger { padding: 8px 10px; }
}
.mono, code, pre { overflow-wrap: anywhere; }
