:root {
  color-scheme: light;
  --bg: #f5f7f5;
  --surface: #ffffff;
  --surface-2: #edf2ef;
  --text: #18221b;
  --muted: #637066;
  --line: #d9e2dc;
  --brand: #1f6b4f;
  --brand-dark: #154b39;
  --level-1: #c64c43;
  --level-2: #d5a429;
  --level-3: #2f8f5b;
  --level-4: #3477b9;
  --shadow: 0 14px 36px rgba(25, 45, 34, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 4vw, 32px);
  color: #fff;
  background: #173d2e;
  box-shadow: 0 8px 28px rgba(12, 31, 23, 0.18);
}

.eyebrow {
  margin: 0 0 4px;
  color: #bdd8ca;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

.progress-box {
  min-width: 118px;
  text-align: right;
}

#progressText {
  display: block;
  margin-bottom: 6px;
  font-weight: 800;
}

.progress-track {
  width: 118px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #74d69b;
  transition: width 160ms ease;
}

.shell {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 3vw, 24px) 36px;
}

.panel,
.legend-band,
.settings {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.identity-panel {
  padding: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid #c7d7cd;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--brand-dark);
  background: #eef7f1;
  font-size: 0.82rem;
  font-weight: 700;
}

.identity-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.8fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd8d0;
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  background: #fff;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(31, 107, 79, 0.14);
}

.legend-band {
  margin-top: 14px;
  padding: 16px 18px;
}

.legend-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}

.legend-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-left: 7px solid currentColor;
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfb;
}

.legend-item strong {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: currentColor;
}

.legend-item span {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.2;
}

.level-1 { color: var(--level-1); }
.level-2 { color: var(--level-2); }
.level-3 { color: var(--level-3); }
.level-4 { color: var(--level-4); }

.matrix-form {
  margin-top: 14px;
}

.group {
  margin-top: 14px;
}

.group-title {
  position: sticky;
  top: 70px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #cbd8d0;
  border-radius: 8px 8px 0 0;
  padding: 12px 16px;
  color: #fff;
  background: var(--brand-dark);
}

.group-title span {
  color: #d8eadf;
  font-size: 0.85rem;
  font-weight: 700;
}

.question-list {
  display: grid;
  gap: 1px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  background: var(--line);
}

.question-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 296px;
  align-items: center;
  gap: 16px;
  padding: 12px 14px;
  background: var(--surface);
}

.question-name {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 760;
  line-height: 1.25;
}

.score-control {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.score-button {
  min-width: 0;
  min-height: 46px;
  border: 1px solid #c9d5ce;
  border-radius: 8px;
  color: var(--text);
  background: #f7faf8;
  font-weight: 850;
  cursor: pointer;
}

.score-button:hover {
  background: #eef5f0;
}

.score-button.selected {
  color: #fff;
  border-color: transparent;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
}

.score-button[data-score="1"].selected { background: var(--level-1); }
.score-button[data-score="2"].selected { background: var(--level-2); }
.score-button[data-score="3"].selected { background: var(--level-3); }
.score-button[data-score="4"].selected { background: var(--level-4); }

.notes-panel {
  margin-top: 14px;
  padding: 16px;
}

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding: 12px 0 0;
  background: linear-gradient(to top, var(--bg) 74%, rgba(245, 247, 245, 0));
}

button.primary,
button.secondary {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

button.primary {
  border: 1px solid var(--brand);
  color: #fff;
  background: var(--brand);
}

button.secondary {
  border: 1px solid #cbd8d0;
  color: var(--brand-dark);
  background: #fff;
}

.settings {
  margin-top: 18px;
  padding: 14px 16px;
}

.settings summary {
  color: var(--brand-dark);
  font-weight: 850;
  cursor: pointer;
}

.settings-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.settings-grid p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 50;
  max-width: min(92vw, 560px);
  transform: translateX(-50%) translateY(22px);
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: #173d2e;
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
  }

  .identity-grid,
  .legend-grid,
  .question-row {
    grid-template-columns: 1fr;
  }

  .question-row {
    gap: 10px;
  }

  .score-control {
    grid-template-columns: repeat(4, minmax(54px, 1fr));
  }

  .group-title {
    top: 82px;
  }
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
  }

  .progress-box,
  .progress-track {
    width: 100%;
  }

  .progress-box {
    min-width: 0;
    text-align: left;
  }

  .action-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  button.primary,
  button.secondary {
    width: 100%;
    padding: 0 10px;
  }
}
