:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #eef1f5;
  background: #101319;
  --muted: #a4afbd;
  --line: #2c3541;
  --accent: #8db9ff;
  --surface: #181e27;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
main { width: min(74rem, 100% - 2rem); margin-inline: auto; padding: 2rem 0 3rem; }
h1, h2, p { margin: 0; }
h2 { font-size: 1.125rem; font-weight: 680; }

.masthead {
  position: relative;
  max-width: 42rem;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  margin-bottom: 1.75rem;
}
#open-help, .help-close button {
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; padding: 0;
  border: 0; border-radius: 50%; color: inherit; background: transparent;
}
#open-help { position: absolute; right: 0; top: 0; }
#open-help span {
  display: grid; place-items: center; width: 1.5rem; height: 1.5rem; border: 2px solid currentColor;
  border-radius: 50%; font: 700 1rem/1 system-ui, sans-serif;
}
#open-help:hover, .help-close button:hover { background: #2a323e; }
h1 { font-size: clamp(2rem, 5vw, 2.75rem); font-weight: 750; letter-spacing: -.055em; line-height: 1; }
time { color: var(--muted); font-size: .875rem; white-space: nowrap; }
.reset-countdown { color: var(--muted); font-size: .75rem; font-variant-numeric: tabular-nums; }
#win-screen .reset-countdown { margin-top: .25rem; }
.game-modes { display: flex; justify-content: center; gap: 1.25rem; margin: -.5rem auto 1.25rem; }
.game-modes a { padding: .35rem .15rem; color: var(--muted); text-decoration: none; }
.game-modes a[aria-current] { color: inherit; border-bottom: 2px solid var(--accent); font-weight: 650; }
.next-round { display: block; margin: .5rem auto; padding: .55rem 1rem; border: 1px solid var(--line); border-radius: .35rem; color: var(--accent); background: var(--surface); }

button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

form { position: relative; max-width: 35rem; margin-inline: auto; }
label { display: block; margin-bottom: .375rem; font-size: .875rem; font-weight: 650; }
.controls { display: flex; gap: .5rem; }
input {
  flex: 1;
  min-width: 0;
  padding: .65rem .8rem;
  color: inherit;
  background: var(--surface);
  border: 1px solid #475468;
  border-radius: .35rem;
}
input::placeholder { color: var(--muted); }
#submit { padding: .65rem 1rem; background: var(--accent); color: #111a28; border: 0; border-radius: .35rem; font-weight: 650; }
#submit:enabled:hover { background: #a9caff; }
#submit:disabled { opacity: .5; }
#suggestions {
  position: absolute;
  z-index: 2;
  inset: 100% 0 auto;
  margin: .25rem 0 0;
  padding: .25rem;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: .35rem;
  max-height: 16rem;
  overflow-y: auto;
}
#suggestions button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  padding: .45rem;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}
#suggestions button:is(:hover, :focus-visible) { background: #252e3b; }
#suggestions small, #suggestions .alias { color: var(--muted); }
.search-photo { width: 2rem; height: 2rem; object-fit: contain; vertical-align: middle; margin-right: .4rem; }

.picker { max-width: 55rem; margin: 1.75rem auto 0; text-align: center; }
.picker-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: .25rem .85rem;
  margin-bottom: .65rem;
}
.browse-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(100%, 18rem);
  min-inline-size: 0;
  margin: 0 auto 1rem;
  padding: 3px;
  border: 0;
  border-radius: .6rem;
  background: var(--surface);
}
.browse-modes label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 2.75rem;
  margin: 0;
  border-radius: .4rem;
  color: var(--muted);
}
.browse-modes input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.browse-modes label:hover { color: inherit; }
.browse-modes label:has(:checked) { background: #344357; color: #fff; }
.browse-modes label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: -2px; }
@media (forced-colors: active) {
  .browse-modes label:has(:checked) { border-bottom: 3px solid Highlight; }
}
#all-groups {
  padding: .15rem 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: .16em;
  font-size: .875rem;
}
.carousel { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: clamp(.3rem, 2vw, .85rem); }
.carousel-arrow {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  padding: 0;
  border: 1px solid #475468;
  border-radius: .4rem;
  background: var(--surface);
  color: inherit;
  font-size: 2.25rem;
  line-height: 1;
}
.carousel-arrow:enabled:hover { background: #262e3b; }
.carousel-arrow:disabled { opacity: .3; }
.picker-cards { --card-gap: clamp(.45rem, 2vw, 1rem); display: flex; justify-content: center; gap: var(--card-gap); }
.picker-card {
  width: calc((100% - 2 * var(--card-gap)) / 3);
  min-width: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}
.picker-card:enabled:hover .card-caption > :first-child { color: var(--accent); text-decoration: underline; }
.picker-card:disabled { opacity: .64; }
.vehicle-photo {
  width: 100%;
  aspect-ratio: 1.75;
  display: block;
  object-fit: cover;
  background: #1b222c;
  border-radius: .25rem;
}
.engine-card .vehicle-photo { object-fit: contain; }
.card-caption { display: grid; gap: .15rem; width: 100%; line-height: 1.25; overflow-wrap: anywhere; font-weight: 680; }
.card-detail, .picker-range { font-size: .875rem; font-weight: 400; color: var(--muted); }
.picker-range { min-height: 1.25rem; margin-top: .7rem; font-variant-numeric: tabular-nums; }

.results { --max-tile: clamp(3.5rem, 6vw, 4.4rem); --gutter: .22rem; width: min(100%, calc(9 * var(--max-tile) + 10 * var(--gutter))); margin: 0 auto 1.25rem; }
.game-info { display: flex; justify-content: space-between; gap: .5rem 1rem; align-items: baseline; margin-bottom: .5rem; }
#status, .board-note { color: var(--muted); font-size: .875rem; }
.board-note { text-align: center; margin-top: .45rem; }
#copy-result {
  display: block; margin: .75rem auto 0; padding: .65rem 1.1rem;
  border: 0; border-radius: .35rem; background: #a8e4bc; color: #11251b; font-weight: 680;
}
#win-screen {
  width: min(27rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow-y: auto;
  padding: clamp(1rem, 4vw, 1.6rem); background: var(--surface); color: inherit;
  border: 1px solid var(--line); border-radius: .65rem;
}
dialog::backdrop { background: rgb(5 8 12 / 82%); }
#help-screen {
  width: min(31rem, calc(100% - 1.5rem)); max-height: calc(100dvh - 1.5rem);
  overflow-y: auto; overscroll-behavior: contain; padding: 2.6rem clamp(1.25rem, 5vw, 2.75rem) 2rem;
  color: inherit; background: #15191f; border: 1px solid var(--line); border-radius: .5rem;
  font-size: .9375rem; line-height: 1.45;
}
.help-close { position: absolute; inset: .35rem .35rem auto auto; }
.help-close button { font-size: 1.8rem; line-height: 1; }
#help-title { font: 700 2rem/1.1 Georgia, serif; letter-spacing: -.035em; }
#help-title:focus { outline: 0; }
.help-intro { margin-top: .4rem; font-size: 1.125rem; }
.help-rules { padding-left: 1.2rem; margin: 1rem 0 1.5rem; }
.help-rules li + li { margin-top: .4rem; }
#help-screen h3 { margin: 0; font-size: 1rem; }
#help-screen h3 span { margin-left: .3rem; font-family: ui-monospace, monospace; }
.help-examples {
  display: grid; grid-template-columns: 4rem 1fr; align-items: center; gap: 1rem .8rem;
  margin: 1rem 0 1.25rem;
}
.help-examples dt { display: grid; justify-items: center; gap: .2rem; font-size: .75rem; color: var(--muted); }
.help-examples dd { margin: 0; }
.help-examples strong { display: block; }
.example-tile {
  display: grid; align-content: center; justify-items: center; gap: .12rem;
  width: 2.9rem; height: 2.9rem; border-radius: .15rem; color: #eef1f5; font: 650 .9rem/1 ui-monospace, monospace;
}
.help-footer { padding-top: 1rem; border-top: 1px solid var(--line); color: var(--muted); }
.win-heading { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .875rem; }
#close-result { background: transparent; color: inherit; border: 0; font-size: 1.6rem; padding: .2rem .55rem; }
#winning-engine { margin: .5rem 0 .2rem; font-size: clamp(1.5rem, 5vw, 2rem); line-height: 1.1; }
#win-score { color: #a8e4bc; }
#win-screen.lost #win-score { color: #ffda96; }
#win-photo { margin: 1rem 0; }
#win-photo img { display: block; width: 100%; height: clamp(7rem, 22vh, 12rem); object-fit: contain; background: #101319; }
#win-facts dt { color: var(--muted); }
#win-facts { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .9rem; }
#win-facts dd { margin: 0; }
#copy-result, #win-screen .next-round { width: 100%; }
#win-screen .next-round { margin: 1rem 0 0; }
#copy-status { text-align: center; font-size: .85rem; }
#copy-status:not(:empty), #share-text { margin-top: .6rem; }
#share-text { width: 100%; }
.board { container-type: inline-size; }
.board table { --tile: calc((100cqi - 10 * var(--gutter)) / 9); width: 100%; table-layout: fixed; border-spacing: var(--gutter); text-align: center; }
thead th { font-size: .76rem; line-height: 1.1; padding: .3rem 0; color: var(--muted); }
tbody td, tbody th { height: var(--tile); padding: 0; border-radius: .15rem; }
td.clue, th.engine, .example-tile.miss { background: #2a323e; }
td.match, th.engine.match, .example-tile.match { background: #235842; }
td.higher, td.lower, .example-tile.higher { background: #604621; }
.tile-face {
  width: 100%; height: var(--tile); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .12rem; padding: .12rem; border: 0; background: transparent;
  color: inherit; font: 650 clamp(.72rem, 1.1vw, .88rem) ui-monospace, monospace;
  border-radius: inherit; cursor: help;
}
.tile-face:focus-visible { outline-offset: -2px; }
.clue-value { max-width: 100%; }
.clue-marker { line-height: 1; color: #c1cbd7; }
.match .clue-marker { color: #b2f5cb; }
.higher .clue-marker, .lower .clue-marker { color: #ffda96; }
.unused td { border: 1px solid #343d49; }
.unused td:first-child { color: var(--muted); font: .75rem ui-monospace, monospace; }
#tile-tip { position: fixed; z-index: 5; pointer-events: none; max-width: min(22rem, calc(100vw - 12px)); padding: .45rem .7rem; border-radius: .3rem; background: #f1f4fa; color: #182333; font-size: .875rem; line-height: 1.35; }
@media (prefers-reduced-motion: no-preference) {
  .revealing .clue { animation: reveal-tile .28s ease-out; }
  @keyframes reveal-tile {
    from { opacity: .4; transform: translateY(.25rem); }
    to { opacity: 1; transform: none; }
  }
}
.country-flags { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: .18rem; }
.country-flags img { width: 1.15rem; height: .86rem; object-fit: cover; border-radius: .075rem; }

@media (max-width: 36rem) {
  main { width: calc(100% - 1.25rem); padding-top: 1.4rem; }
  .results { --gutter: 2px; }
  thead th { font-size: clamp(.625rem, 2.9cqi, .75rem); }
  thead th[data-short] span { position: absolute; clip-path: inset(50%); width: 1px; height: 1px; overflow: hidden; }
  thead th[data-short]::after { content: attr(data-short) / ""; }
  .carousel { column-gap: .25rem; }
  .tile-face { font-size: clamp(.625rem, 2.9cqi, .75rem); line-height: 1; padding: 0; gap: 1px; }
  .country-flags { flex-wrap: nowrap; gap: 1px; }
  .country-flags img { width: min(1rem, 4cqi); height: auto; }
  .card-caption { font-size: .85rem; }
  .card-detail { font-size: .8rem; }
  .vehicle-photo { aspect-ratio: 1.3; }
}
