:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --panel: #ffffff;
  --ink: #23211d;
  --muted: #6f6a61;
  --line: #d7dee4;
  --accent: #116466;
  --accent-strong: #0b4f50;
  --gold: #d79a28;
  --danger: #a43f32;
  --shadow: 0 18px 50px rgba(32, 29, 24, 0.12);
  --page-pad: clamp(14px, 2.4vw, 28px);
  --panel-pad: clamp(20px, 3vw, 34px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: 24px var(--page-pad) 12px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(22px, 2.2vw, 28px);
}

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

.progress-shell {
  width: clamp(220px, 30vw, 380px);
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #e7edf1;
}

.progress-bar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 180ms ease;
}

.app-shell {
  width: min(100%, 1280px);
  margin: 0 auto;
  padding: 20px var(--page-pad) 42px;
}

.study-panel {
  width: 100%;
  min-height: min(620px, calc(100vh - 150px));
  padding: var(--panel-pad);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.study-panel h2 {
  margin: 0 0 16px;
  font-size: clamp(25px, 3vw, 34px);
}

.study-panel h3 {
  margin: 0 0 8px;
  font-size: clamp(17px, 1.7vw, 19px);
}

.study-panel p {
  line-height: 1.55;
}

.study-panel h3.practice-heading {
  margin-top: 34px;
}

.info-grid,
.tutorial-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 24px 0;
}

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

.info-grid > div,
.tutorial-grid > div,
.summary-grid > div,
.callout {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #f8fafb;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: 26px 0;
  line-height: 1.45;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
}

.actions.split {
  justify-content: space-between;
}

button {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

button.danger {
  border-color: var(--danger);
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.text-link {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.prompt {
  max-width: 780px;
  margin: 0 0 20px;
  color: var(--muted);
  font-size: clamp(16px, 1.7vw, 18px);
}

.chart-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: clamp(260px, 38vh, 340px);
  margin: 18px 0 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chart-large {
  min-height: clamp(310px, 48vh, 440px);
}

.mini-chart {
  min-height: clamp(180px, 25vh, 230px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-frame svg,
.mini-chart svg {
  max-height: 100%;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 0;
  border: 0;
}

.option-tile,
.rank-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

.option-tile:has(input:checked),
.rank-choice.selected {
  border-color: var(--accent);
  outline: 2px solid rgba(17, 100, 102, 0.16);
}

.ranker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 12px;
}

.rank-choice {
  justify-content: space-between;
  user-select: none;
}

.rank-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e7edf1;
  color: var(--muted);
  font-weight: 700;
}

.selected .rank-number {
  background: var(--accent);
  color: #fff;
}

.feedback {
  min-height: 24px;
  margin: 14px 0 0;
  font-weight: 700;
}

.feedback.good {
  color: var(--accent-strong);
}

.feedback.bad {
  color: var(--danger);
}

.trial-topline {
  display: flex;
  justify-content: space-between;
  gap: 20px;
}

.trial-count {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.confidence-label {
  display: block;
  margin-top: 22px;
  font-weight: 700;
}

.confidence-slider {
  width: min(420px, 100%);
  margin-top: 8px;
  accent-color: var(--accent);
}

.muted {
  color: var(--muted);
}

.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-grid > div {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-number {
  font-size: clamp(28px, 3vw, 36px);
  font-weight: 800;
  color: var(--accent);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 22px;
  margin-top: 26px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 14px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.legend text,
.chart-label {
  fill: var(--ink);
  font-size: 13px;
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .app-header h1 {
    font-size: 20px;
  }

  .progress-shell {
    width: 100%;
  }

  .app-shell {
    padding: 12px 12px 32px;
  }

  .study-panel {
    min-height: auto;
    padding: 18px 14px;
  }

  .study-panel h2 {
    font-size: 26px;
  }

  .prompt {
    font-size: 16px;
  }

  .info-grid,
  .tutorial-grid,
  .summary-grid,
  .admin-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .actions,
  .actions.split,
  .trial-topline {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-frame,
  .chart-large {
    min-height: 220px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .chart-frame svg,
  .chart-large svg {
    min-width: 400px;
  }

  .ranker {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }
}

@media (min-width: 1180px) {
  .trial-panel .ranker {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) {
  .app-header {
    padding-top: 18px;
  }

  .study-panel {
    min-height: auto;
    box-shadow: 0 12px 34px rgba(32, 29, 24, 0.1);
  }

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

  .tutorial-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .chart-frame {
    margin: 14px 0 20px;
  }

  .trial-panel .ranker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  :root {
    --page-pad: 10px;
    --panel-pad: 16px;
  }

  .app-header {
    gap: 14px;
    padding-top: 14px;
  }

  .app-shell {
    padding-top: 10px;
    padding-bottom: 24px;
  }

  .study-panel {
    border-radius: 0;
    box-shadow: none;
  }

  .info-grid,
  .tutorial-grid,
  .summary-grid,
  .admin-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .info-grid,
  .tutorial-grid,
  .summary-grid {
    gap: 10px;
    margin: 18px 0;
  }

  .info-grid > div,
  .tutorial-grid > div,
  .summary-grid > div,
  .callout {
    padding: 14px;
  }

  .chart-frame,
  .chart-large {
    min-height: 0;
  }

  .mini-chart {
    min-height: 0;
  }

  .chart-frame svg,
  .mini-chart svg {
    width: 100%;
  }

  .legend text,
  .chart-label {
    font-size: 16px;
  }

  .chart-label {
    font-weight: 700;
  }

  .ranker,
  .trial-panel .ranker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .rank-choice,
  .option-tile {
    min-height: 44px;
    padding: 10px 12px;
  }

  .actions,
  .actions.split,
  .trial-topline {
    align-items: stretch;
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .confidence-slider {
    width: 100%;
  }

  th,
  td {
    padding: 10px 12px;
  }
}

@media (max-width: 420px) {
  .app-header h1 {
    font-size: 21px;
  }

  .study-panel h2 {
    font-size: 23px;
  }

  .chart-frame,
  .chart-large {
    min-height: 0;
  }

  .mini-chart {
    min-height: 0;
  }

  .ranker,
  .trial-panel .ranker {
    grid-template-columns: 1fr;
  }

  .rank-number {
    width: 26px;
    height: 26px;
  }
}
