/* ============================================================
   การแก้ไขคะแนนสอบท้องถิ่น 2568
   Palette: warm-graphite ground + single-hue amber magnitude ramp.
   Every value below was contrast-checked against its own surface
   (body ink >= 4.5:1, chart marks >= 2:1 ordinal floor).
   ============================================================ */

:root {
  color-scheme: light;

  --ground: #eceff1;
  --surface: #fafbfc;
  --raised: #e5e8eb;
  --hairline: #d1d5d8;
  --hairline-strong: #b9bfc4;

  --ink: #161b20;
  --ink-2: #4e5359;
  --ink-3: #5e646a;

  --accent: #bc4f00;
  --accent-hot: #be260b;
  --accent-wash: rgba(188, 79, 0, 0.09);

  --seq-1: #e6a375;
  --seq-2: #d78951;
  --seq-3: #c6702b;
  --seq-4: #b35800;
  --seq-5: #9d4100;

  --track: #dee2e5;
  --shadow-panel: 0 1px 2px rgba(22, 27, 32, 0.05), 0 8px 24px -12px rgba(22, 27, 32, 0.12);

  --font-text: 'Anuphan', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-num: 'Azeret Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --step-0: 0.8125rem;
  --step-1: 0.875rem;
  --step-2: 0.9375rem;
  --step-3: 1.0625rem;
  --step-4: 1.3125rem;
  --step-5: 1.625rem;
  --hero: clamp(3.25rem, 11vw, 5.25rem);

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 72px;

  --r-sm: 3px;
  --r-md: 6px;
  --r-lg: 10px;

  --z-sticky: 10;
  --z-tooltip: 40;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 180ms;
  --dur-data: 520ms;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;

    --ground: #0f0d0b;
    --surface: #181613;
    --raised: #23201c;
    --hairline: #36322e;
    --hairline-strong: #4a4540;

    --ink: #f3f1ef;
    --ink-2: #bab7b2;
    --ink-3: #898580;

    --accent: #f5a33a;
    --accent-hot: #f5642b;
    --accent-wash: rgba(245, 163, 58, 0.12);

    --seq-1: #76522e;
    --seq-2: #9c672e;
    --seq-3: #b6762a;
    --seq-4: #d78b2a;
    --seq-5: #fea92f;

    --track: #262320;
    --shadow-panel: none;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;

  --ground: #0f0d0b;
  --surface: #181613;
  --raised: #23201c;
  --hairline: #36322e;
  --hairline-strong: #4a4540;

  --ink: #f3f1ef;
  --ink-2: #bab7b2;
  --ink-3: #898580;

  --accent: #f5a33a;
  --accent-hot: #f5642b;
  --accent-wash: rgba(245, 163, 58, 0.12);

  --seq-1: #76522e;
  --seq-2: #9c672e;
  --seq-3: #b6762a;
  --seq-4: #d78b2a;
  --seq-5: #fea92f;

  --track: #262320;
  --shadow-panel: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: var(--step-2);
  line-height: 1.6;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--s5) var(--s8);
}

main {
  display: flex;
  flex-direction: column;
  gap: var(--s5);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- shared type ---------------------------------------------------- */

.rule-label {
  font-size: var(--step-0);
  font-weight: 500;
  color: var(--ink-3);
  margin: 0 0 var(--s2);
  letter-spacing: 0.01em;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  text-wrap: balance;
  letter-spacing: -0.01em;
}

h1 {
  font-size: var(--step-5);
  font-weight: 600;
}

h2 {
  font-size: var(--step-4);
  font-weight: 600;
}

h3 {
  font-size: var(--step-3);
  font-weight: 600;
}

.year {
  font-family: var(--font-num);
  font-weight: 500;
  font-size: 0.92em;
  color: var(--ink-2);
}

/* --- masthead -------------------------------------------------------- */

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s7) 0 var(--s5);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: var(--s6);
}

.masthead__id .rule-label {
  margin-bottom: var(--s1);
}

.icon-btn {
  flex: none;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}

.icon-btn:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

/* --- readout (headline figures + national density) ------------------- */

.readout {
  display: grid;
  grid-template-columns: minmax(0, 0.82fr) minmax(0, 1.18fr);
  gap: var(--s5) var(--s7);
  align-items: end;
  padding-bottom: var(--s6);
  border-bottom: 1px solid var(--hairline);
}

.readout__figure {
  font-family: var(--font-num);
  font-size: var(--hero);
  font-weight: 500;
  line-height: 0.94;
  letter-spacing: -0.035em;
  margin: 0;
  font-variant-numeric: proportional-nums;
}

.readout__finding {
  margin: var(--s4) 0 0;
  color: var(--ink-2);
  font-size: var(--step-2);
  max-width: 42ch;
  text-wrap: pretty;
}

.readout__finding b {
  color: var(--ink);
  font-weight: 600;
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.chart-head .rule-label {
  margin-bottom: 0;
}

.chart-note {
  margin: 0;
  font-family: var(--font-num);
  font-size: 0.6875rem;
  color: var(--ink-3);
  white-space: nowrap;
}

.readout__secondary {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  margin: 0;
  border-top: 1px solid var(--hairline);
  padding-top: var(--s4);
}

.readout__secondary > div {
  flex: 1 1 140px;
  padding-inline: var(--s5);
  border-left: 1px solid var(--hairline);
}

.readout__secondary > div:first-child {
  padding-inline-start: 0;
  border-left: 0;
}

.readout__secondary dt {
  font-size: var(--step-0);
  color: var(--ink-3);
  margin-bottom: var(--s1);
}

.readout__secondary dd {
  margin: 0;
  font-family: var(--font-num);
  font-size: var(--step-5);
  font-weight: 500;
  letter-spacing: -0.02em;
}

/* national density strip: 1px-gap columns, magnitude by height */
.density {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 96px;
}

.density__col {
  flex: 1;
  background: var(--seq-3);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  min-height: 2px;
  transform-origin: bottom;
  transition: background var(--dur) var(--ease);
}

.density__col[data-peak='true'] {
  background: var(--accent);
}

.density__axis,
.histogram__axis {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--hairline-strong);
  padding-top: var(--s2);
  font-family: var(--font-num);
  font-size: 0.6875rem;
  color: var(--ink-3);
}

/* --- panels ---------------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s5);
  box-shadow: var(--shadow-panel);
}

.panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
  margin-bottom: var(--s4);
}

.panel__head--sub {
  margin-top: var(--s6);
  padding-top: var(--s4);
  border-top: 1px solid var(--hairline);
  align-items: center;
}

.panel__hint {
  margin: var(--s1) 0 0;
  font-size: var(--step-1);
  color: var(--ink-3);
}

.count-chip {
  font-family: var(--font-num);
  color: var(--ink-3);
  font-weight: 400;
}

/* --- controls -------------------------------------------------------- */

.ghost-btn {
  font: inherit;
  font-size: var(--step-1);
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s1) var(--s3);
  cursor: pointer;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
    background var(--dur) var(--ease);
}

.ghost-btn:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
  background: var(--raised);
}

.field select,
.field input {
  font: inherit;
  font-size: var(--step-1);
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: var(--s2) var(--s3);
  min-height: 34px;
  transition: border-color var(--dur) var(--ease);
}

.field select:hover,
.field input:hover {
  border-color: var(--hairline-strong);
}

.field--search input {
  min-width: 260px;
}

.field input::placeholder {
  color: var(--ink-3);
}

:where(button, select, input, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* --- bar list -------------------------------------------------------- */

.bar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bar-list--tall {
  max-height: 460px;
  overflow-y: auto;
  scrollbar-width: thin;
}

/* Fade the cut-off edge only when the list actually overflows, and drop it
   while scrolling through so no row is ever dimmed under the pointer. */
.bar-list--tall.is-scrollable:not(:hover):not(:focus-within) {
  mask-image: linear-gradient(to bottom, #000 calc(100% - 44px), transparent 100%);
}

.bar-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 132px) 1fr 62px;
  align-items: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s1) var(--s2);
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: background var(--dur) var(--ease);
}

/* Thai agency names run long; give them the room the bar can spare. */
.bar-list--wide-label .bar-row {
  grid-template-columns: 22px minmax(0, 1.35fr) minmax(0, 1fr) 46px;
}

.bar-row:hover {
  background: var(--raised);
}

.bar-row[aria-pressed='true'] {
  background: var(--accent-wash);
}

.bar-row__rank {
  font-family: var(--font-num);
  font-size: 0.6875rem;
  color: var(--ink-3);
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.bar-row__label {
  font-size: var(--step-1);
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row[aria-pressed='true'] .bar-row__label {
  color: var(--ink);
  font-weight: 600;
}

.bar-row__track {
  display: block;
  height: 18px;
  background: var(--track);
  border-radius: var(--r-sm);
}

.bar-row__fill {
  display: block;
  height: 100%;
  background: var(--seq-3);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  min-width: 3px;
  transform-origin: left;
  transition: background var(--dur) var(--ease);
}

.bar-row[aria-pressed='true'] .bar-row__fill {
  background: var(--accent);
}

.bar-row__value {
  font-family: var(--font-num);
  font-size: var(--step-0);
  font-variant-numeric: tabular-nums;
  text-align: end;
  color: var(--ink-2);
}

.bar-row[aria-pressed='true'] .bar-row__value {
  color: var(--ink);
}

/* --- histogram ------------------------------------------------------- */

.histogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 168px;
}

.histogram__bar {
  flex: 1;
  min-width: 6px;
  height: 100%;
  display: flex;
  align-items: flex-end;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: background var(--dur) var(--ease);
}

.histogram__bar:hover {
  background: var(--accent-wash);
}

.histogram__col {
  width: 100%;
  background: var(--seq-3);
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  min-height: 2px;
  transform-origin: bottom;
}

/* --- inline readout (province figures) ------------------------------- */

.inline-readout {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s5);
  margin: 0 0 var(--s5);
  padding-bottom: var(--s4);
  border-bottom: 1px solid var(--hairline);
}

.inline-readout dt {
  font-size: var(--step-0);
  color: var(--ink-3);
}

.inline-readout dd {
  margin: 0;
  font-family: var(--font-num);
  font-size: var(--step-4);
  font-weight: 500;
  letter-spacing: -0.015em;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: var(--s7);
}

/* --- tables ---------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
}

.table-wrap--scroll {
  max-height: 480px;
  overflow-y: auto;
  scrollbar-width: thin;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step-1);
}

thead th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--surface);
  text-align: start;
  font-weight: 500;
  font-size: var(--step-0);
  color: var(--ink-3);
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--hairline-strong);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

thead th:hover {
  color: var(--ink);
}

thead th[aria-sort]::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-inline-start: var(--s1);
  border-inline: 3px solid transparent;
}

thead th[aria-sort='ascending']::after {
  border-bottom: 4px solid var(--accent);
}

thead th[aria-sort='descending']::after {
  border-top: 4px solid var(--accent);
}

tbody td {
  padding: var(--s2) var(--s3);
  border-bottom: 1px solid var(--hairline);
  white-space: nowrap;
  color: var(--ink-2);
}

tbody tr:hover td {
  background: var(--raised);
  color: var(--ink);
}

td.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: end;
  color: var(--ink);
}

td.name {
  color: var(--ink);
}

/* score cell: number plus a proportional heat tick */
.score-cell {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  justify-content: flex-end;
  width: 100%;
}

.score-cell__tick {
  width: 34px;
  height: 4px;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
  flex: none;
}

.score-cell__tick i {
  display: block;
  height: 100%;
  background: var(--seq-3);
  border-radius: 2px;
}

/* --- states ---------------------------------------------------------- */

.skeleton-block {
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  padding-top: var(--s5);
}

.skeleton {
  background: var(--raised);
  border-radius: var(--r-md);
  animation: pulse 1.4s var(--ease) infinite;
}

.skeleton--hero {
  height: 84px;
  width: min(340px, 60%);
}

.skeleton--strip {
  height: 96px;
}

.skeleton--row {
  height: 22px;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.state {
  padding: var(--s7) var(--s5);
  text-align: center;
  color: var(--ink-2);
}

.state h2 {
  margin-bottom: var(--s2);
}

.state p {
  margin: 0 auto var(--s4);
  max-width: 46ch;
  color: var(--ink-3);
}

.empty-row {
  padding: var(--s6) var(--s3);
  text-align: center;
  color: var(--ink-3);
  font-size: var(--step-1);
}

/* --- colophon -------------------------------------------------------- */

.colophon {
  border-top: 1px solid var(--hairline);
  padding-top: var(--s4);
  color: var(--ink-3);
  font-size: var(--step-1);
}

.colophon p {
  margin: 0;
  max-width: 68ch;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

/* --- tooltip --------------------------------------------------------- */

.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  background: var(--ink);
  color: var(--ground);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-md);
  font-size: var(--step-0);
  line-height: 1.4;
  pointer-events: none;
  max-width: 280px;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, 0.4);
}

.tooltip b {
  font-family: var(--font-num);
  font-size: var(--step-2);
  font-weight: 600;
  display: block;
  letter-spacing: -0.01em;
}

.tooltip span {
  opacity: 0.75;
}

/* --- entrance motion (data marks only, once per load) ---------------- */

@keyframes grow-x {
  from {
    transform: scaleX(0);
  }
}

@keyframes grow-y {
  from {
    transform: scaleY(0);
  }
}

.is-entering .bar-row__fill {
  animation: grow-x var(--dur-data) var(--ease) backwards;
  animation-delay: var(--d, 0ms);
}

.is-entering .density__col,
.is-entering .histogram__col {
  animation: grow-y var(--dur-data) var(--ease) backwards;
  animation-delay: var(--d, 0ms);
}

/* --- responsive ------------------------------------------------------ */

@media (max-width: 900px) {
  .readout {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .split {
    grid-template-columns: 1fr;
    gap: var(--s6);
  }
}

@media (max-width: 620px) {
  .shell {
    padding: 0 var(--s4) var(--s7);
  }

  .masthead {
    padding-top: var(--s5);
  }

  .panel {
    padding: var(--s4);
  }

  .bar-row {
    grid-template-columns: 20px minmax(0, 96px) 1fr 48px;
    gap: var(--s2);
  }

  .readout__secondary > div {
    flex-basis: 100px;
    padding-inline: var(--s3);
  }

  .field--search input {
    min-width: 0;
    width: 100%;
  }

  .field--search {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
