:root {
  color-scheme: light;
  --bg: #f7f6f1;
  --ink: #202323;
  --muted: #697071;
  --surface: #fffdf8;
  --surface-strong: #f0eee6;
  --line: #d7d2c6;
  --teal: #0f6b68;
  --teal-soft: #dcefed;
  --rust: #b75f3b;
  --rust-soft: #f4e0d7;
  --steel: #667786;
  --steel-soft: #e5ebef;
  --gold: #a9761a;
  --gold-soft: #f6ead2;
  --focus: #1e756f;
  --shadow: 0 16px 40px rgba(35, 43, 44, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.78), rgba(247, 246, 241, 0.96)),
    repeating-linear-gradient(90deg, rgba(32, 35, 35, 0.035) 0 1px, transparent 1px 24px),
    repeating-linear-gradient(0deg, rgba(32, 35, 35, 0.035) 0 1px, transparent 1px 24px);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 18px;
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 2px 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(35, 43, 44, 0.08);
  cursor: pointer;
}

.icon-button:focus-visible,
input:focus-visible + span,
.choice-card:has(input:focus-visible),
.choice-pill:has(input:focus-visible) {
  outline: 3px solid rgba(30, 117, 111, 0.3);
  outline-offset: 3px;
}

.flow {
  display: grid;
  grid-template-columns: 1fr 26px 1fr 26px 1fr;
  align-items: stretch;
  margin-bottom: 18px;
}

.flow-step {
  display: flex;
  gap: 10px;
  min-width: 0;
  padding: 12px;
  background: rgba(255, 253, 248, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.flow-step p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.step-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--steel-soft);
  color: var(--steel);
  font-size: 13px;
  font-weight: 700;
}

.flow-step.is-complete .step-mark {
  background: var(--teal);
  color: #fffdf8;
}

.flow-line {
  align-self: center;
  height: 2px;
  background: var(--line);
}

.controls,
.result-panel,
.matrix {
  margin-top: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-group {
  margin: 0;
  padding: 0;
  border: 0;
}

.control-group + .control-group {
  margin-top: 18px;
}

legend {
  margin-bottom: 10px;
  color: var(--ink);
  font-weight: 700;
}

.choice-grid {
  display: grid;
  gap: 10px;
}

.choice-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.choice-card,
.choice-pill {
  position: relative;
  display: grid;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  cursor: pointer;
}

.choice-card {
  gap: 5px;
  min-height: 82px;
  padding: 14px;
}

.choice-pill {
  place-items: center;
  min-height: 48px;
  padding: 10px 8px;
  text-align: center;
}

.choice-card input,
.choice-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-card:has(input:checked),
.choice-pill:has(input:checked) {
  border-color: var(--teal);
  background: var(--teal-soft);
  box-shadow: inset 0 0 0 2px rgba(15, 107, 104, 0.18);
}

.choice-title,
.choice-pill span {
  font-weight: 700;
}

.choice-detail {
  color: var(--muted);
  font-size: 13px;
}

.result-heading,
.matrix-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.source-badge,
.matrix-head span,
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.source-badge {
  background: var(--gold-soft);
  color: #68460f;
}

.matrix-head span {
  background: var(--teal-soft);
  color: var(--teal);
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.device-card {
  display: grid;
  gap: 10px;
  align-content: start;
  min-height: 160px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.device-card.is-best {
  border-color: var(--teal);
  background: var(--teal-soft);
}

.device-name {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

.device-subtitle,
.device-reason {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.device-subtitle {
  min-height: 34px;
}

.device-rank {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.status-appropriate {
  background: var(--teal);
  color: #fffdf8;
}

.status-neutral {
  background: var(--steel-soft);
  color: #33434e;
}

.status-inappropriate {
  background: var(--rust);
  color: #fffdf8;
}

.notes {
  display: grid;
  gap: 9px;
  margin-top: 14px;
}

.note {
  padding: 11px 12px;
  border-left: 4px solid var(--gold);
  background: var(--gold-soft);
  border-radius: 6px;
  color: #4e3813;
  font-size: 13px;
  line-height: 1.45;
}

.matrix-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.matrix-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.matrix-table th,
.matrix-table td {
  padding: 10px 8px;
  border: 1px solid var(--line);
  text-align: center;
  vertical-align: middle;
}

.matrix-table th {
  background: var(--surface-strong);
}

.matrix-table th:first-child,
.matrix-table td:first-child {
  text-align: left;
  font-weight: 700;
}

.matrix-table .is-selected {
  box-shadow: inset 0 0 0 3px rgba(169, 118, 26, 0.38);
}

.cell-status {
  display: grid;
  gap: 2px;
  justify-items: center;
}

.cell-status strong {
  font-size: 13px;
}

.cell-status span {
  color: inherit;
  font-size: 11px;
}

.cell-appropriate {
  background: var(--teal);
  color: #fffdf8;
}

.cell-neutral {
  background: var(--steel);
  color: #fffdf8;
}

.cell-inappropriate {
  background: var(--rust);
  color: #fffdf8;
}

.disclaimer {
  display: grid;
  gap: 6px;
  padding: 14px 3px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .flow {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .flow-line {
    width: 2px;
    height: 12px;
    justify-self: 24px;
  }

  .choice-grid.two,
  .choice-grid.four,
  .device-grid {
    grid-template-columns: 1fr;
  }

  .device-card {
    min-height: 0;
  }

  .result-heading,
  .matrix-head {
    align-items: stretch;
    flex-direction: column;
  }

  .source-badge,
  .matrix-head span {
    align-self: flex-start;
  }

  .matrix-table {
    min-width: 0;
    font-size: 11px;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 8px 4px;
  }

  .matrix-table th:first-child,
  .matrix-table td:first-child {
    width: 64px;
  }

  .cell-status span {
    display: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181a19;
    --ink: #f4f0e8;
    --muted: #b7b1a6;
    --surface: #222422;
    --surface-strong: #2b2d2a;
    --line: #444941;
    --teal: #5fc7bc;
    --teal-soft: #173b38;
    --rust: #c97458;
    --rust-soft: #4a271d;
    --steel: #8294a1;
    --steel-soft: #303a41;
    --gold: #d6a545;
    --gold-soft: #43341c;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  }

  body {
    background:
      linear-gradient(180deg, rgba(34, 36, 34, 0.78), rgba(24, 26, 25, 0.96)),
      repeating-linear-gradient(90deg, rgba(244, 240, 232, 0.04) 0 1px, transparent 1px 24px),
      repeating-linear-gradient(0deg, rgba(244, 240, 232, 0.04) 0 1px, transparent 1px 24px);
  }

  .flow-step.is-complete .step-mark,
  .status-appropriate,
  .cell-appropriate {
    color: #102b29;
  }

  .source-badge,
  .matrix-head span,
  .note {
    color: var(--ink);
  }
}
