/* Council service costs across Scotland.
   Colours: validated data-viz palette (see README). Light and dark each have their own steps. */

:root {
  color-scheme: light;
  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --wash: rgba(11, 11, 11, 0.05);
  --s1: #2a78d6;                 /* series 1: the selected council, ranked bars */
  --s2: #eb6834;                 /* series 2: Scotland */
  --k0: #6da7ec; --k1: #3987e5; --k2: #256abf; --k3: #184f95; --k4: #0d366b;   /* map: five classes, low to high */
  --na: #c3c2b7;                 /* map: no data */
  --focus: #2a78d6;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --wash: rgba(255, 255, 255, 0.06);
    --s1: #3987e5;
    --s2: #d95926;
    --k0: #184f95; --k1: #256abf; --k2: #3987e5; --k3: #6da7ec; --k4: #9ec5f4;
    --na: #383835;
    --focus: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --wash: rgba(255, 255, 255, 0.06);
  --s1: #3987e5;
  --s2: #d95926;
  --k0: #184f95; --k1: #256abf; --k2: #3987e5; --k3: #6da7ec; --k4: #9ec5f4;
  --na: #383835;
  --focus: #6da7ec;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font: 15px/1.5 var(--font);
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 12px; top: -48px; background: var(--ink); color: var(--surface); padding: 8px 12px; border-radius: 4px; z-index: 100; }
.skip:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Masthead */
.masthead { background: var(--plane); border-bottom: 1px solid var(--grid); }
.masthead-in { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding-top: 28px; padding-bottom: 24px; }
h1 { margin: 0; font-size: clamp(26px, 3.2vw, 40px); line-height: 1.1; font-weight: 700; letter-spacing: -0.022em; }
.lede { margin: 10px 0 0; max-width: 62ch; color: var(--ink-2); font-size: 16px; }

/* Buttons and fields */
.btn {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 4px; height: 36px; padding: 0 14px; cursor: pointer;
}
.btn:hover { background: var(--wash); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--wash); color: var(--ink); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }

.controls {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 28px;
  padding: 18px 0; margin-top: 4px; border-bottom: 1px solid var(--grid);
}
.field { display: grid; gap: 6px; }
.field.grow { flex: 1 1 260px; max-width: 400px; }
.field label, .lbl { font-size: 13px; font-weight: 600; color: var(--ink-2); }
select {
  font: inherit; color: var(--ink); background: var(--surface); width: 100%;
  height: 36px; padding: 0 10px; border: 1px solid var(--axis); border-radius: 4px;
}
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 4px; overflow: hidden; height: 36px; }
.seg button {
  font: inherit; font-weight: 600; font-size: 13.5px; color: var(--ink-2); background: var(--surface);
  border: 0; padding: 0 14px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--axis); }
.seg button:hover { background: var(--wash); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.yearctl { display: flex; align-items: center; gap: 12px; height: 36px; }
.yearctl input[type="range"] { width: clamp(120px, 13vw, 200px); accent-color: var(--s1); }
.yearctl output { min-width: 4.4em; font-weight: 700; font-variant-numeric: tabular-nums; }
#play { min-width: 68px; }

/* Layout */
.layout { padding-top: 32px; padding-bottom: 56px; }
/* The sticky map lives in its own grid so it can only slide within this block, never over the tables below */
.stage { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 48px 56px; align-items: start; }
.map-col { position: sticky; top: 16px; }
.side-col { display: grid; gap: 48px; min-width: 0; }
.profile, .tableview { margin-top: 48px; }

.ptitle { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 700; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--ink-2); font-size: 13.5px; }
.sub .b { display: block; }
.fine { margin: 14px 0 0; color: var(--ink-2); font-size: 12.5px; max-width: 58ch; }
.small { font-size: 12.5px; color: var(--ink-2); }

/* Map */
.map-wrap { position: relative; margin-top: 12px; }
#map, #map3d { display: block; width: 100%; height: auto; }
#map3d[hidden], #map[hidden] { display: none; }
.view-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin: 12px 0 4px; }

/* 3D blocks: tops use the map ramp; side walls are the same colour, darkened */
.blk { cursor: pointer; }
.blk:focus { outline: none; }
.blk .top { stroke: var(--surface); stroke-width: 1px; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.blk .wall { stroke: none; }
.blk.k0 .top { fill: var(--k0); } .blk.k1 .top { fill: var(--k1); } .blk.k2 .top { fill: var(--k2); }
.blk.k3 .top { fill: var(--k3); } .blk.k4 .top { fill: var(--k4); } .blk.na .top { fill: var(--na); }
.blk:focus-visible .top { stroke: var(--ink); stroke-width: 3px; }
.base-plate { fill: none; stroke: var(--axis); stroke-width: 1px; vector-effect: non-scaling-stroke; pointer-events: none; }
.badge circle { fill: var(--ink); stroke: var(--surface); stroke-width: 2px; vector-effect: non-scaling-stroke; }
.badge text { fill: var(--surface); font-weight: 700; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; }
.badge { pointer-events: none; }
.inset-label { fill: var(--ink-2); font-size: 190px; }
.region {
  stroke: var(--surface); stroke-width: 1.5px; stroke-linejoin: round; vector-effect: non-scaling-stroke;
  cursor: pointer; transition: fill 0.28s ease;
}
.region:focus { outline: none; }
.region:focus-visible { stroke: var(--ink); stroke-width: 3px; }
.region.k0 { fill: var(--k0); } .region.k1 { fill: var(--k1); } .region.k2 { fill: var(--k2); }
.region.k3 { fill: var(--k3); } .region.k4 { fill: var(--k4); } .region.na { fill: var(--na); }
.outline { fill: none; stroke: var(--ink); stroke-linejoin: round; vector-effect: non-scaling-stroke; pointer-events: none; }
#hoverOutline { stroke-width: 1.5px; }
#selOutline { stroke-width: 3px; }
.inset-frame { fill: none; stroke: var(--axis); stroke-width: 1px; vector-effect: non-scaling-stroke; pointer-events: none; }
.inset-note { position: absolute; font-size: 12px; color: var(--ink-2); white-space: nowrap; transform: translateX(0); pointer-events: none; }

/* Legend */
.legend { margin-top: 14px; max-width: 520px; }
.lg-bar { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; height: 10px; }
.lg-bar span:nth-child(1) { background: var(--k0); } .lg-bar span:nth-child(2) { background: var(--k1); }
.lg-bar span:nth-child(3) { background: var(--k2); } .lg-bar span:nth-child(4) { background: var(--k3); }
.lg-bar span:nth-child(5) { background: var(--k4); }
.lg-labels { position: relative; height: 20px; margin-top: 4px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.lg-labels span { position: absolute; top: 0; white-space: nowrap; transform: translateX(-50%); }
.lg-labels span.first { transform: none; }
.lg-labels span.last { transform: translateX(-100%); }
.lg-na { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--ink-2); }
.lg-na i { width: 18px; height: 10px; background: var(--na); display: inline-block; }

/* Focus panel */
.focus-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.hero { margin: 10px 0 0; }
.hero-fig { font-size: clamp(44px, 5.4vw, 64px); line-height: 1; font-weight: 700; letter-spacing: -0.03em; }
.facts { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; color: var(--ink-2); }
.facts li { padding-left: 14px; position: relative; }
.facts li::before { content: ""; position: absolute; left: 0; top: 0.72em; width: 6px; height: 1px; background: var(--axis); }
.trend-keys { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 22px 0 6px; font-size: 13px; color: var(--ink-2); min-height: 18px; }
.trend-keys .key { display: inline-flex; align-items: center; gap: 8px; }
.trend-keys .kline { width: 18px; height: 2px; border-radius: 1px; display: inline-block; }
.trend { position: relative; }
.trend svg { display: block; width: 100%; height: auto; overflow: visible; }
.trend text { font-family: var(--font); }
.t-grid { stroke: var(--grid); stroke-width: 1px; }
.t-axis { stroke: var(--axis); stroke-width: 1px; }
.t-tick { fill: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.t-line { fill: none; stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; }
.t-dot { stroke: var(--surface); stroke-width: 2px; }
.t-val { fill: var(--ink); font-size: 12.5px; font-weight: 700; stroke: var(--surface); stroke-width: 4px; paint-order: stroke; font-variant-numeric: tabular-nums; }
.t-cross { stroke: var(--ink-2); stroke-width: 1px; }
.t-empty { color: var(--ink-2); padding: 24px 0; }

/* Ranking */
.rows { list-style: none; margin: 14px 0 0; padding: 0; }
.row {
  display: grid; grid-template-columns: minmax(112px, 164px) minmax(0, 1fr) 70px; align-items: center; gap: 12px;
  width: 100%; min-height: 26px; padding: 0 8px; border: 0; border-radius: 4px; background: none;
  color: inherit; font: inherit; font-size: 13.5px; text-align: left; cursor: pointer;
}
.row:hover, li.hov .row { background: var(--wash); }
.row[aria-pressed="true"] { background: var(--wash); font-weight: 700; }
.r-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-track { position: relative; height: 10px; }
.r-bar { display: block; height: 10px; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 1px; transition: width 0.3s ease, opacity 0.2s; }
.rows.has-sel .row:not([aria-pressed="true"]) .r-bar { opacity: 0.55; }
.r-mark { position: absolute; top: -8px; bottom: -8px; width: 1px; background: var(--ink-2); }
.r-val { text-align: right; font-variant-numeric: tabular-nums; }
.r-val.none { color: var(--muted); font-weight: 400; }

/* Tables */
.tbl-scroll { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
caption { text-align: left; color: var(--ink-2); padding: 8px 0; }
th, td { padding: 7px 12px; text-align: left; border-bottom: 1px solid var(--grid); }
thead th { font-weight: 700; color: var(--ink-2); border-bottom-color: var(--axis); white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody th[scope="row"] { font-weight: 400; }
tr.grp th { padding-top: 18px; font-size: 13px; font-weight: 700; color: var(--ink-2); border-bottom-color: var(--axis); }
tbody tr:hover { background: var(--wash); }
tr.cur { background: var(--wash); }
tr.cur th[scope="row"] { font-weight: 700; }
button.link {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: left; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--axis); text-underline-offset: 3px;
}
button.link:hover { text-decoration-color: var(--ink); }
.tableview summary { cursor: pointer; font-weight: 600; color: var(--ink-2); padding: 6px 0; }

/* Tooltip */
.tip {
  position: fixed; left: 0; top: 0; z-index: 60; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--axis); border-radius: 4px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.14);
}
.tip[hidden] { display: none; }
.tip-name { color: var(--ink-2); }
.tip-val { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tip-sub { color: var(--ink-2); }
.tip-row { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.tip-row .kline { width: 14px; height: 2px; border-radius: 1px; flex: none; }
.tip-row .tv { margin-left: auto; padding-left: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Footer */
.foot { background: var(--plane); border-top: 1px solid var(--grid); padding: 28px 0 40px; color: var(--ink-2); font-size: 13px; }
.foot p { margin: 0 0 10px; max-width: 90ch; }

/* Narrow screens */
@media (max-width: 960px) {
  .stage { grid-template-columns: minmax(0, 1fr); gap: 40px; }
  .profile, .tableview { margin-top: 40px; }
  .map-col { position: static; max-width: 560px; }
  .masthead-in { flex-direction: column; gap: 14px; }
}
@media (max-width: 640px) {
  /* The measures table becomes one block per measure: title, then value, rank and Scotland side by side. */
  #profTable thead { position: absolute; left: -9999px; }
  #profTable, #profTable tbody { display: block; }
  #profTable tr.grp { display: block; }
  #profTable tr:not(.grp) { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
  #profTable tr:not(.grp) > th[scope="row"] { grid-column: 1 / -1; padding: 0 0 6px; border: 0; }
  #profTable tr:not(.grp) > td { padding: 0; border: 0; text-align: left; }
  #profTable td::before { content: attr(data-label); display: block; font-size: 12px; color: var(--ink-2); }
  #profTable tr.grp th { display: block; padding-left: 0; }
}
@media (max-width: 520px) {
  .wrap { padding: 0 16px; }
  .row { grid-template-columns: minmax(96px, 120px) minmax(0, 1fr) 62px; gap: 8px; }
  .lg-labels { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
@media (forced-colors: active) {
  .region { stroke: CanvasText; }
}

/* 3D lighting: light from the west, so west-facing walls are lit and east-facing walls are in shade */
.blk.k0 .wall { fill: color-mix(in srgb, var(--k0) 74%, #000); } .blk.k0 .wall.shade { fill: color-mix(in srgb, var(--k0) 52%, #000); }
.blk.k1 .wall { fill: color-mix(in srgb, var(--k1) 74%, #000); } .blk.k1 .wall.shade { fill: color-mix(in srgb, var(--k1) 52%, #000); }
.blk.k2 .wall { fill: color-mix(in srgb, var(--k2) 74%, #000); } .blk.k2 .wall.shade { fill: color-mix(in srgb, var(--k2) 52%, #000); }
.blk.k3 .wall { fill: color-mix(in srgb, var(--k3) 74%, #000); } .blk.k3 .wall.shade { fill: color-mix(in srgb, var(--k3) 52%, #000); }
.blk.k4 .wall { fill: color-mix(in srgb, var(--k4) 74%, #000); } .blk.k4 .wall.shade { fill: color-mix(in srgb, var(--k4) 52%, #000); }
.blk.na .wall { fill: color-mix(in srgb, var(--na) 74%, #000); } .blk.na .wall.shade { fill: color-mix(in srgb, var(--na) 52%, #000); }
#map3d.has-hover .blk:not(.hov) { opacity: .72; }
.blk { transition: opacity .15s; }
.callout { pointer-events: none; }
.callout rect { fill: var(--ink); }
.callout text { fill: var(--surface); font-size: 165px; font-weight: 700; text-anchor: middle; dominant-baseline: central; }
@media (prefers-reduced-motion: reduce) { .blk { transition: none; } }
