:root {
  --bg: #282828;          /* surface-900 */
  --s800: #32302f;
  --s700: #45403d;
  --s600: #504a45;
  --s500: #5a524c;
  --s400: #8c8682;
  --fg: #ddc7a1;          /* tertiary-500 */
  --fg-dim: #a69579;      /* tertiary-700 */
  --fg-dark: #857761;     /* tertiary-800 */
  --from: #d3869b;        /* secondary-500 */
  --from-hi: #e0aab9;
  --to: #7daea3;          /* primary-500 */
  --to-hi: #a4c6bf;
  --olive: #a9b665;       /* success-500 */
  --warn: #ea6962;        /* warning-500 */
  --radius: 8px;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.modal-open { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }

/* Page layout: one centred game column with a soft shadow, like the original */
.stage { position: relative; min-height: 100vh; }
.game-col {
  position: relative;
  width: 100%;
  margin: 0 auto;
  padding: 18px 1rem 40px;
  background: var(--bg);
  min-height: 100vh;
}
@media (min-width: 768px) {
  .game-col { max-width: min(65vh, 100vw); min-width: 560px; }
}
@media (min-width: 1024px) {
  .game-col { box-shadow: 0 0 80px -20px #000; }
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 18px;
  color: var(--fg);
  font-size: 34px;
  font-weight: 400;
  letter-spacing: .01em;
  line-height: 1;
}
.brand svg { width: 27px; height: 27px; }
.brand small {
  margin-left: 4px;
  padding: 3px 7px;
  border: 1px solid var(--s600);
  border-radius: 999px;
  color: var(--fg-dim);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
}

#title {
  margin: 0;
  font-size: clamp(20px, 2.85vh, 37px);
  font-weight: 400;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-align: right;
}
#title span { font-weight: 700; }
#title b.from { color: var(--from); }
#title b.to { color: var(--to); }
#avoid { margin: 4px 0 0; text-align: right; color: var(--fg); font-size: 17px; }
#avoid b { color: var(--warn); }

.links {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  margin: 6px 0 8px;
  font-size: 13px;
}
.links button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--to);
}
.links button:hover { text-decoration: underline; }
.links svg { width: 13px; height: 13px; }

/* Map */
#map { position: relative; width: 100%; aspect-ratio: 1.35; }
#map-svg {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: var(--s800);
  border: 1px solid var(--s700);
  touch-action: none;
}
.map-zoom {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--fg-dark);
  border-radius: 6px;
  overflow: hidden;
}
.map-zoom button {
  width: 30px;
  height: 26px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  font-size: 18px;
  line-height: 1;
}
.map-zoom button + button { border-top: 1px solid var(--fg-dark); }
.map-zoom button:hover { background: var(--s700); color: var(--fg); }
.map-mark {
  position: absolute;
  left: 6px;
  bottom: 4px;
  color: var(--s500);
  font-size: 13px;
  pointer-events: none;
  user-select: none;
}

.graticule { pointer-events: none; fill: none; stroke: #777; stroke-width: .5px; stroke-opacity: .5; }
.country-start { fill: var(--from); stroke: var(--s700); }
.country-end { fill: var(--to); stroke: var(--s700); }
circle.country-start { stroke: var(--from); stroke-width: 3; fill-opacity: 0; }
circle.country-end { stroke: var(--to); stroke-width: 3; fill-opacity: 0; }
.country-connected {
  fill: var(--fg);
  stroke: var(--s700);
  transform-box: fill-box;
  transform-origin: center;
  animation: country-connect 1.2s ease forwards;
}
.country-disconnected { fill: var(--s600); stroke: var(--s700); }
.country-hidden { fill: var(--s600); fill-opacity: .2; }
.country-outline { stroke: var(--s600); fill: var(--s600); fill-opacity: .15; }
.country-selected { stroke: var(--bg); stroke-width: 2px; stroke-opacity: 1; }
@keyframes country-connect {
  0%, 30%, 60%, 80%, 100% { transform: translateY(0); }
  45% { transform: translateY(-4%); }
  70% { transform: translateY(-1.5%); }
}
@media (prefers-reduced-motion: reduce) { .country-connected { animation: none; } }

#map-tip {
  position: absolute;
  z-index: 5;
  width: max-content;
  max-width: 260px;
  padding: 7px;
  border-radius: 5px;
  background: var(--bg);
  color: var(--warn);
  font-size: 14px;
  line-height: 1.2;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}
#map-tip::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: var(--bg);
}

/* Guess bar */
#guess-row { position: relative; display: flex; gap: 0; margin-top: 6px; }
#guess-input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--s700);
  border-radius: 5px 0 0 5px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 13px;
  outline: none;
}
#guess-input::placeholder { color: var(--s400); }
#guess-input:focus { border-color: var(--fg); }
#guess-btn {
  flex: none;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--fg-dark);
  border-left: 0;
  border-radius: 0 5px 5px 0;
  background: var(--s800);
  color: var(--olive);
  font-size: 13px;
  white-space: nowrap;
}
#guess-btn:hover { background: var(--s700); }
#suggest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  z-index: 6;
  max-height: 96px;
  margin: 0;
  padding: 2px 0;
  overflow-y: auto;
  list-style: none;
  background: var(--bg);
  border-top: 1px solid var(--s700);
  font-size: 13px;
}
#suggest li { padding: 1px 10px; line-height: 19px; cursor: pointer; }
#suggest li:hover, #suggest li.on { background: var(--s700); }
#suggest mark { background: none; color: var(--warn); }

/* Past guesses and hints */
.label { margin: 14px 0 6px; font-size: 16px; }
#past { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
#past button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 0;
  border-radius: 5px;
  background: var(--s800);
  font-size: 13px;
  line-height: 20px;
}
#past button:hover { background: var(--s700); }
#past .n { color: var(--fg-dim); }
#past .em { font-size: 15px; line-height: 1; }
#past button.is-hidden .nm { text-decoration: line-through; opacity: .55; }

#hints .hint-list { display: flex; flex-direction: column; gap: 8px; }
#hints button {
  width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--fg-dark);
  border-radius: 6px;
  background: transparent;
  color: var(--olive);
  font-size: 13px;
}
#hints button:not(:disabled):hover { background: var(--s700); }
#hints button:disabled { color: var(--s400); border-color: var(--s600); }
#hints button.used { color: var(--s500); border-color: var(--s700); text-decoration: line-through; }

/* Results */
#results {
  padding: 10px;
  border: 1px solid var(--s700);
  border-radius: 5px;
  background: var(--s800);
}
.res-top { display: flex; gap: 8px; }
.res-sum, .res-grid-box {
  border-radius: 6px;
  background: var(--s700);
  padding: 12px 14px;
}
.res-sum { flex: 1; }
.res-sum h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; }
#res-guesses { margin: 0; font-size: 14px; }
.streak { margin-top: 6px; font-size: 14px; display: flex; align-items: center; gap: 4px; }
.streak svg { width: 12px; height: 12px; }
.streak-label { display: block; color: var(--fg-dark); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
.res-grid-box { position: relative; min-width: 110px; display: flex; align-items: center; justify-content: center; padding: 18px 14px 12px; }
#res-grid { font-size: 19px; line-height: 1.25; text-align: center; letter-spacing: 1px; }
#copy-grid {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--to);
  color: var(--bg);
  display: grid;
  place-items: center;
}
#copy-grid svg { width: 10px; height: 10px; }
.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tabs button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border: 0;
  border-radius: 6px 6px 0 0;
  background: #4b6862;
  color: var(--fg);
  font-size: 12px;
  font-weight: 600;
}
.tabs button[data-tab="stats"] { background: #7f505d; }
.tabs button.on { background: var(--s700); }
.tabs svg { width: 12px; height: 12px; }
#tab-body { padding: 10px; border-radius: 0 6px 6px 6px; background: var(--s700); font-size: 14px; }
#tab-body p { margin: 0; }
#tab-body .route .from { color: var(--from); font-weight: 600; }
#tab-body .route .to { color: var(--to); font-weight: 600; }
#tab-body .arr { color: var(--fg-dark); }
#tab-body .miss { margin-top: 6px; color: var(--fg-dim); }
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.statgrid b { display: block; font-size: 22px; line-height: 1.1; }
.statgrid span { font-size: 11px; color: var(--fg-dim); }
#chart { display: block; width: 100%; max-width: 380px; margin: 10px auto 0; overflow: visible; }
#chart .tick text { fill: var(--fg); font-size: 9px; }
#chart .domain, #chart .tick line { stroke: var(--fg); }
#chart .bar-nh { fill: var(--to); }
#chart .bar-h { fill: var(--from); }
#chart .you-line { stroke: var(--fg); stroke-width: 1; }
#chart .arrow { fill: var(--fg); }
#chart .you { fill: var(--fg); font-size: 10px; font-weight: 700; }
#chart .ax-label { fill: var(--fg); font-size: 11px; }

#after { margin-top: 14px; }
.after-btns { display: grid; grid-template-columns: 3fr 2fr; gap: 8px; }
.after-side { display: flex; flex-direction: column; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 6px;
  font-weight: 500;
  transition: filter .15s, transform .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.95); filter: brightness(.9); }
.btn .ic { width: 14px; height: 14px; }
#play-again { min-height: 72px; background: var(--to); color: var(--bg); font-size: 20px; font-weight: 700; }
#play-again .ic { width: 18px; height: 18px; }
.after-side .btn { flex: 1; min-height: 32px; background: var(--from); color: var(--bg); font-size: 13px; }

/* Toasts */
#toasts {
  position: fixed;
  top: 10px;
  left: 50%;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 10px 10px 14px;
  border-radius: 6px;
  background: var(--s500);
  color: var(--fg);
  font-size: 14px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
  pointer-events: auto;
  transition: opacity .3s;
}
.toast.out { opacity: 0; }
.toast button {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  line-height: 22px;
}

/* How to play */
#help {
  position: fixed;
  inset: 0;
  z-index: 95;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  overflow-y: auto;
  background: rgba(0, 0, 0, .6);
}
.help-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 16px 12px 20px;
  border-radius: 8px;
  background: var(--s800);
  font-size: 13px;
}
.help-card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 18px; font-weight: 700; }
#help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font-size: 26px;
  line-height: 1;
}
.help-demo { display: block; width: 100%; max-width: 280px; margin: 0 auto 4px; border-radius: 5px; background: var(--bg); border: 1px solid var(--s700); }
.help-demo .hex-s { fill: var(--from); }
.help-demo .hex-e { fill: var(--to); }
.help-demo .hex-g { fill: var(--fg); stroke: var(--s700); stroke-width: 1; }
.help-card .lead { margin: 12px 0; }
.help-card .from { color: var(--from); font-weight: 700; }
.help-card .to { color: var(--to); font-weight: 700; }
.help-card details { margin-top: 6px; border-radius: 6px; background: var(--bg); }
.help-card summary { display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-weight: 700; cursor: pointer; list-style: none; }
.help-card summary::-webkit-details-marker { display: none; }
.help-card summary::after { content: "\2303"; margin-left: auto; transform: rotate(180deg); color: var(--fg-dim); }
.help-card details[open] summary::after { transform: none; }
.help-card details > div { padding: 0 12px 10px; }
.help-card details p { margin: 0 0 10px; }
.score-row { display: flex; align-items: center; gap: 14px; margin: 0 0 8px; }
.score-row .em { font-size: 22px; line-height: 1; }
.help-card em { color: var(--fg-dim); }

#loading { padding: 40px 0; text-align: center; color: var(--fg-dim); }

@media (max-width: 767px) {
  .game-col { padding: 12px .5rem 32px; }
  #title { text-align: center; }
  #avoid { text-align: center; }
  .links { justify-content: center; }
  .after-btns { grid-template-columns: 1fr 1fr; }
  #play-again { font-size: 17px; }
}
