/* Grachten Racer decomp. Direction and tokens: web/DESIGN.md */

:root {
  color-scheme: light dark;
  --page: #f5efe3;
  --card: #fbf8f1;
  --tint: #e9e1d0;
  --line: #ddd3bf;
  --ink: #1c2626;
  --muted: #4b5755;
  --link: #8b3a26;
  --water: #145452;
  --water-deep: #0f3f3d;
  --house: #6f2f1e;
  --window: #f1d9a6;
  --on-water: #f5efe3;
  --matched: #c9600c;
  --effective: #00918c;
  --track: #e2d9c5;
  --button: #a84f08;
  --on-button: #ffffff;
  --focus: #145452;
  --ok-bg: #dcebe6;
  --error-bg: #f5ddd4;

  --text: Verdana, "DejaVu Sans", "Bitstream Vera Sans", Geneva, sans-serif;
  --heading: "Trebuchet MS", "Lucida Grande", "DejaVu Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", Menlo, Consolas, monospace;
  --radius: 4px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #101c1c;
    --card: #172726;
    --tint: #1f3331;
    --line: #2b3e3c;
    --ink: #ebe6da;
    --muted: #a7b1ae;
    --link: #f0a184;
    --water: #0b3533;
    --water-deep: #082826;
    --house: #3a1d16;
    --window: #c9a560;
    --on-water: #ebe6da;
    --matched: #e57a24;
    --effective: #1fa89d;
    --track: #253634;
    --button: #e57a24;
    --on-button: #101c1c;
    --focus: #7fd1c8;
    --ok-bg: #173a36;
    --error-bg: #3e231c;
  }
}

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

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.6 var(--text);
}

h1, h2, h3 { font-family: var(--heading); line-height: 1.25; color: var(--ink); }
h1 { font-size: 1.9rem; margin: 0 0 .6rem; }
h2 { font-size: 1.2rem; margin: 0 0 .8rem; }

a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

code { font-family: var(--mono); font-size: .92em; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.skip {
  position: absolute; left: .5rem; top: -3rem; z-index: 10;
  background: var(--card); color: var(--ink); padding: .6rem 1rem; border-radius: var(--radius);
}
.skip:focus { top: .5rem; }

/* --- Header: gables on the quay ---------------------------------------- */

header.site { background: var(--page); }

.skyline { display: block; width: 100%; height: 64px; }
.skyline .houses { fill: var(--house); }
.skyline .windows { fill: var(--window); opacity: .55; }

.quay {
  display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1.5rem;
  background: var(--water); color: var(--on-water);
  border-top: 3px solid var(--water-deep);
  padding: .35rem max(1rem, calc((100% - 72rem) / 2));
}

.brand {
  color: var(--on-water); text-decoration: none;
  font: 700 1.15rem/1 var(--heading); padding: .7rem 0;
}
.brand span { font-weight: 400; opacity: .85; }

.quay nav { display: flex; flex-wrap: wrap; gap: 0 .25rem; flex: 1; }
.quay nav a, .account .me {
  color: var(--on-water); text-decoration: none;
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 .65rem;
  border-bottom: 3px solid transparent;
}
.quay nav a:hover, .account .me:hover { border-bottom-color: color-mix(in srgb, var(--on-water) 50%, transparent); }
.quay nav a[aria-current="page"] { border-bottom-color: var(--matched); }
.quay :focus-visible { outline-color: var(--on-water); }

.account { display: flex; align-items: center; gap: .25rem; }
.account form { margin: 0; }
.account button.link { color: var(--on-water); }

.env-note {
  margin: 0; padding: .5rem 1rem; text-align: center;
  background: var(--tint); color: var(--ink); font-size: .9rem;
}

/* --- Layout ------------------------------------------------------------- */

main { max-width: 72rem; margin: 0 auto; padding: 2rem 1rem 3rem; }

section { margin-bottom: 2.75rem; }

.lead { max-width: 46rem; color: var(--muted); margin-top: 0; }

.columns { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1.5rem; align-items: start; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 2.5rem; align-items: start; }
.rules-split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem;
}

@media (max-width: 52rem) {
  .columns, .split, .rules-split { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
}

footer.site {
  border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem;
  padding: 1.5rem max(1rem, calc((100% - 72rem) / 2)) 2.5rem;
}
footer.site p { max-width: 50rem; }

/* --- Flash messages ------------------------------------------------------ */

.flash { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1.5rem; }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--error-bg); }

/* --- The race (home) ----------------------------------------------------- */

.race { margin-bottom: 3rem; }
.hero { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem 1rem; }
.hero-number { font: 700 clamp(3rem, 9vw, 4.75rem)/1 var(--heading); color: var(--ink); }
.hero-text { font: 1.25rem/1.4 var(--heading); max-width: 26rem; }
.hero-sub { margin: .75rem 0 1.75rem; color: var(--muted); max-width: 46rem; }

.lane { position: relative; padding: 2.1rem 1.75rem 0 0; }
.track {
  display: flex; gap: 2px; height: 14px; border-radius: 7px; overflow: hidden;
  background: var(--track);
}
.track .part { width: var(--w); min-width: 0; }
.track .matched { background: var(--matched); }
.track .effective { background: var(--effective); }

.boat {
  position: absolute; top: .55rem; width: 42px; height: 21px;
  left: max(0px, calc((100% - 1.75rem) * var(--at) / 100 - 30px));
  min-width: 0;
}
.boat .hull { fill: var(--matched); }
.boat .cabin { fill: var(--ink); }
.boat .wake { fill: none; stroke: var(--effective); stroke-width: 2; stroke-linecap: round; }

.flag { position: absolute; right: 0; top: 0; width: 20px; height: 28px; }
.flag .pole { stroke: var(--ink); stroke-width: 2; }
.flag .cloth { fill: var(--card); stroke: var(--ink); stroke-width: 1; }
.flag .checks { fill: var(--ink); }

.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; padding: 0; margin: .75rem 0 .25rem; font-size: .9rem; }
.legend li { display: flex; align-items: center; gap: .4rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.matched { background: var(--matched); }
.swatch.effective { background: var(--effective); }
.swatch.todo { background: var(--track); outline: 1px solid var(--line); }
.updated { font-size: .9rem; margin: .25rem 0 0; }

/* --- Chart --------------------------------------------------------------- */

.chart { position: relative; margin: 0; }
.chart-scroll { overflow-x: auto; }
.chart svg { display: block; width: 100%; min-width: 520px; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font: 13px var(--text); font-variant-numeric: tabular-nums; }
.chart .area { fill: var(--matched); opacity: .1; }
.chart .line { fill: none; stroke: var(--matched); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end, .chart .focus { fill: var(--matched); stroke: var(--card); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font: 700 14px var(--text); }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; }
.chart svg:focus-visible { outline-offset: 4px; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 2;
  background: var(--ink); color: var(--page); border-radius: var(--radius);
  padding: .4rem .6rem; font-size: .8rem; line-height: 1.4; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
}

.table-view { margin-top: 1rem; }
.table-view summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--link); }

.empty { color: var(--muted); padding: 1rem 0; max-width: 40rem; }

/* --- Lists on the home page ---------------------------------------------- */

.finish-list, .leader-list, .credits { list-style: none; padding: 0; margin: 0; }
.finish-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.finish-list li:last-child { border-bottom: 0; }
.finish-list .fn { display: block; font-weight: 700; }
.finish-list .meta { font-size: .85rem; color: var(--muted); }

.leader-list li { display: flex; align-items: center; gap: .75rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.leader-list .rank { width: 1.5rem; text-align: right; font: 700 1.1rem var(--heading); color: var(--muted); }
.leader-list .points { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }

.steps { padding-left: 1.4rem; margin: 0; }
.steps li { padding-left: .35rem; margin-bottom: .75rem; }
.steps li::marker { font: 700 1.05rem var(--heading); color: var(--matched); }

.credits li { padding: .4rem 0; }

.person { display: inline-flex; align-items: center; gap: .4rem; }
.person img { border-radius: 50%; background: var(--tint); }

/* --- Status labels ------------------------------------------------------- */

.status {
  display: inline-block; font-size: .8rem; line-height: 1.5; white-space: nowrap;
  padding: 0 .45rem; border-radius: 3px; border: 1px solid var(--line); color: var(--ink);
  background: var(--card);
}
.status.s-matched { border-color: var(--matched); box-shadow: inset 4px 0 0 var(--matched); padding-left: .65rem; }
.status.s-effective { border-color: var(--effective); box-shadow: inset 4px 0 0 var(--effective); padding-left: .65rem; }
.status.s-partial { border-style: dashed; }
.status.s-todo { color: var(--muted); }

/* --- Tables --------------------------------------------------------------- */

.scroll { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; background: var(--card); font-size: .92rem; }
th, td { text-align: left; padding: .55rem .75rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th { font: 700 .85rem var(--heading); color: var(--muted); background: var(--tint); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:hover { background: color-mix(in srgb, var(--tint) 55%, transparent); }
td form { margin: 0; }
table.functions td.name { min-width: 11rem; max-width: 24rem; overflow-wrap: anywhere; }
.fname.hint { color: var(--muted); font-style: italic; }
table.scoreboard .rank { font: 700 1rem var(--heading); color: var(--muted); }
table.scoreboard tr.you { background: var(--ok-bg); }
.claimed { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0 .2rem; font-size: .88rem; }

.count { margin: 0 0 .5rem; }

/* --- Forms and buttons ---------------------------------------------------- */

button, .button {
  font: 700 .95rem var(--text);
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 1.1rem; border-radius: var(--radius);
  background: var(--button); color: var(--on-button); border: 2px solid var(--button);
  cursor: pointer; text-decoration: none;
}
button:hover, .button:hover { filter: brightness(1.08); }
button.secondary { background: transparent; color: var(--ink); border-color: var(--line); }
button.small, .button.small { min-height: 36px; padding: 0 .8rem; font-size: .85rem; }
button.link { background: none; border: 0; padding: 0 .65rem; font-weight: 400; text-decoration: underline; color: var(--link); }
.quay .button.small { min-height: 40px; background: var(--card); color: var(--ink); border-color: var(--card); }

/* Small buttons stay 36px tall but get a 44px hit area. */
button.small { position: relative; }
button.small::after { content: ""; position: absolute; inset: -4px 0; }

.button-row { display: flex; flex-wrap: wrap; gap: .5rem; }

label { display: block; font-size: .85rem; font-weight: 700; margin-bottom: .25rem; }
input, select {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--muted); border-radius: var(--radius);
  min-height: 44px; padding: 0 .6rem; width: 100%;
}

.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem 1rem;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin: 1.25rem 0 1.5rem;
}
.filters .field { flex: 0 1 12rem; }
.filters .field.grow { flex: 1 1 14rem; }
.filters .field.size { flex: 0 1 6.5rem; }
.filters .actions { display: flex; align-items: center; gap: 1rem; }
.reset { white-space: nowrap; }

.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem 1rem; }
.inline-form label { width: 100%; }
.inline-form input { max-width: 18rem; }
form.inline { display: inline; margin-left: .5rem; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-top: 1.25rem; }
.pager a { min-height: 44px; display: inline-flex; align-items: center; }

/* --- Function page ---------------------------------------------------------- */

.crumb { margin: 0 0 .5rem; }
.fn-name { font-weight: 400; overflow-wrap: anywhere; }
.function-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 1.5rem; margin: 1.5rem 0; align-items: start; }
@media (max-width: 52rem) { .function-head { grid-template-columns: minmax(0, 1fr); } }
.facts { margin: 0; display: grid; gap: .1rem; }
.facts div { display: flex; gap: 1rem; padding: .45rem 0; border-bottom: 1px solid var(--line); }
.facts dt { width: 7.5rem; flex: none; color: var(--muted); }
.facts dd { margin: 0; }
.claim-box p { margin-top: 0; }

.profile { display: flex; align-items: center; gap: 1.25rem; margin-bottom: 2rem; }
.profile-avatar { border-radius: 50%; background: var(--tint); flex: none; }
.profile h1 { margin: 0; }
.profile p { margin: .25rem 0 0; }

.error-page { padding: 2rem 0; }

@media (max-width: 36rem) {
  body { font-size: 14px; }
  .quay { gap: 0 .5rem; }
  .quay nav { order: 3; width: 100%; flex: none; margin: 0 -.65rem; }
  .account { margin-left: auto; }
  .hero-text { font-size: 1.05rem; }
  th, td { padding: .5rem .5rem; }
}

@media (forced-colors: active) {
  .track .matched, .track .effective, .swatch { forced-color-adjust: none; }
  .status.s-matched, .status.s-effective { box-shadow: none; border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
