/* Concelho do Dia. The font is kept with the site (SIL Open Font License, see the OFL
   file next to it); nothing is loaded from other domains. */
@font-face { font-family: "Hanken Grotesk"; font-style: normal; font-weight: 100 900; font-display: swap; src: url("../fonts/hanken-grotesk-latin-wght-normal.woff2") format("woff2"); }

:root {
  --bg: #F3F0E8;
  --surface: #FFFDF8;
  --surface-2: #EAE5D8;
  --ink: #15212B;
  --muted: #4E5965;
  --line: #D5CDBC;
  --accent: #1B6551;
  --accent-ink: #FFFFFF;
  --land: #D4E6DB;
  --land-line: #174A3D;
  --won: #A9DBC4;
  --lost: #F1D6C9;
  --guess: #E8C9A0;
  --mark: #B04A16;
  --focus: #B04A16;
  --grid: rgba(21, 33, 43, .06);
  --map-land: #E3DCCB;
  --map-line: #C9BFAA;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E151B; --surface: #15202A; --surface-2: #1C2934; --ink: #ECE7DC; --muted: #A9B4BE; --line: #2C3B48;
    --accent: #7ED3B6; --accent-ink: #0E151B; --land: #1E3A31; --land-line: #92E2C6; --won: #2C6B55; --lost: #5B3426;
    --guess: #7A5A2E; --mark: #F2A65A; --focus: #F2A65A; --grid: rgba(236, 231, 220, .05);
    --map-land: #2B3B48; --map-line: #3F5262;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E151B; --surface: #15202A; --surface-2: #1C2934; --ink: #ECE7DC; --muted: #A9B4BE; --line: #2C3B48;
  --accent: #7ED3B6; --accent-ink: #0E151B; --land: #1E3A31; --land-line: #92E2C6; --won: #2C6B55; --lost: #5B3426;
  --guess: #7A5A2E; --mark: #F2A65A; --focus: #F2A65A; --grid: rgba(236, 231, 220, .05);
    --map-land: #2B3B48; --map-line: #3F5262;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 1rem/1.5 "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-wrap: break-word;
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 20; text-decoration: none; font-weight: 600; }
.skip:focus { top: 12px; }

/* header */
.top { border-bottom: 1px solid var(--line); background: var(--surface); }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { margin: 0; display: inline-flex; align-items: center; gap: 10px; font-size: 1.2rem; font-weight: 750; letter-spacing: -.01em; }
.brand-mark { width: 28px; height: 28px; flex: none; background: url("../img/icon.svg") center / contain no-repeat; }
.toolbar { display: flex; gap: 8px; align-items: center; }

/* controls */
button, select, input, textarea { font: inherit; color: inherit; }
select, input[type="text"], textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-height: 44px;
}
select:hover, input:hover { border-color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 650;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }

main { padding: 14px 0 24px; }
main:focus { outline: none; }
.intro { margin-bottom: 10px; }
.lead { margin: 0 0 6px; }
.number { font-weight: 700; color: var(--accent); }
.notice { margin: 0; color: var(--muted); font-size: .86rem; }

.controls { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; margin: 12px 0 6px; }
.field { display: grid; gap: 4px; flex: 1 1 220px; min-width: 0; }
.field label { font-weight: 650; font-size: .9rem; }
.field select { width: 100%; }
@media (max-width: 520px) { .field { flex-basis: 100%; } }
.mode-note { margin: 0 0 6px; font-size: .9rem; color: var(--muted); }
.help { margin: 4px 0 12px; }
.help summary { cursor: pointer; font-weight: 650; min-height: 44px; display: flex; align-items: center; width: max-content; max-width: 100%; }
.help p { margin: 0 0 8px; max-width: 62ch; }

/* the outline */
.stage {
  margin: 0; aspect-ratio: 1 / 1; width: 100%; max-height: min(48vh, 440px); max-width: min(48vh, 440px); margin-inline: auto;
  background-color: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 10% 10%; background-position: center;
}
.outline { width: 100%; height: 100%; display: block; }
.outline .shape {
  fill: var(--land); stroke: var(--land-line); stroke-width: .9; stroke-linejoin: round; stroke-linecap: round; fill-rule: evenodd;
  transform-origin: 50% 50%; transform-box: fill-box;
  transition: fill .5s ease;
}
.outline.is-won .shape { fill: var(--won); }
.outline.is-lost .shape { fill: var(--lost); }
.outline.reveal .shape {
  stroke-dasharray: 1; stroke-dashoffset: 1; fill-opacity: 0;
  animation: draw 1.2s cubic-bezier(.4, 0, .2, 1) forwards, fill-in .6s ease-out .9s forwards;
}
.outline.is-won:not(.reveal) .shape { animation: settle .6s ease-out; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fill-in { to { fill-opacity: 1; } }
@keyframes settle { 0% { transform: scale(1); } 40% { transform: scale(1.04); } 100% { transform: scale(1); } }

/* hints */
.hints { margin: 12px 0 4px; display: grid; gap: 8px; justify-items: start; }
.hint-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.hint { background: var(--surface-2); border-radius: 999px; padding: 4px 12px; font-size: .92rem; font-weight: 600; }
#hint-btn { font-size: .92rem; }

/* guesses */
.attempts { margin-top: 10px; }
.guess-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.row, .slot { min-height: 44px; border-radius: 10px; }
.slot { border: 1px dashed var(--line); }
.row {
  position: relative; overflow: hidden; display: grid; grid-template-columns: minmax(0, 1fr) auto 28px 3.6ch; gap: 8px;
  align-items: center; padding: 8px 12px; background: var(--surface); border: 1px solid var(--line); font-variant-numeric: tabular-nums;
}
.row-name { font-weight: 650; min-width: 0; overflow-wrap: anywhere; }
.row-km, .row-prox { text-align: right; white-space: nowrap; }
.row-prox { font-weight: 700; }
.row-dir { display: inline-flex; justify-content: center; }
.arrow { width: 24px; height: 24px; fill: var(--accent); }
.row-bar { position: absolute; left: 0; bottom: 0; height: 4px; width: calc(var(--p, 0) * 1%); background: var(--accent); opacity: .7; }
.row.is-correct { grid-template-columns: minmax(0, 1fr) auto; background: var(--won); border-color: var(--accent); }
.row-correct { font-weight: 750; }
.row.enter { animation: rise .35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.scale { margin: 8px 2px 0; font-size: .84rem; color: var(--muted); }

/* the field, kept within reach of the thumb on a phone */
.play {
  position: sticky; bottom: 0; z-index: 5; margin: 12px -16px 0; padding: 8px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.counter { margin: 0 0 6px; font-size: .86rem; color: var(--muted); font-weight: 600; }
.play-row { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
.combo input { width: 100%; font-size: 1.05rem; }
.suggestions {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); margin: 0; padding: 4px; list-style: none; max-height: 50vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 -8px 24px rgba(0, 0, 0, .12);
}
.option { padding: 10px 12px; border-radius: 8px; cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.option:hover { background: var(--surface-2); }
.option[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.guess-msg { margin: 6px 0 0; min-height: 1.2em; font-size: .9rem; color: var(--mark); font-weight: 600; }
.guess-msg:empty { min-height: 0; margin: 0; }

/* result */
.result { margin-top: 18px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.result h2 { margin: 0 0 6px; font-size: 1.45rem; line-height: 1.2; }
.result h2:focus { outline: none; }
.result h2:focus-visible { outline: 3px solid var(--focus); }
.answer { margin: 0 0 12px; }
.share { display: grid; gap: 8px; justify-items: start; }
.share-text { width: 100%; resize: none; font-size: 1rem; line-height: 1.35; background: var(--surface-2); }
.copy-status { margin: 0; min-height: 1.2em; font-size: .9rem; }
.next { margin: 12px 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.where { margin: 16px 0 0; }
.where figcaption { font-weight: 700; margin-bottom: 6px; }
.pt-map { width: 100%; height: auto; display: block; max-width: 460px; }
.pt-map .map-other { fill: var(--map-land); stroke: var(--map-line); stroke-width: .4; }
.pt-map .map-guessed { fill: var(--guess); stroke: var(--map-line); stroke-width: .4; }
.pt-map .map-answer { fill: var(--accent); stroke: var(--accent); stroke-width: .6; }
.pt-map .map-ring { fill: none; stroke: var(--mark); stroke-width: 2; }
.pt-map .map-frame { fill: none; stroke: var(--line); stroke-dasharray: 3 3; }
.pt-map .map-label { fill: var(--muted); font-size: 12px; font-weight: 600; }
.legend { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .88rem; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.key-answer { background: var(--accent); }
.key-guess { background: var(--guess); }

/* statistics */
.stats-inline { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.stats-inline h3, .stats-mode { margin: 0 0 10px; font-size: 1.05rem; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.tile { display: flex; flex-direction: column-reverse; align-items: center; text-align: center; background: var(--surface-2); border-radius: 10px; padding: 8px 4px; }
.tile dd { margin: 0; font-size: 1.5rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.tile dt { font-size: .78rem; color: var(--muted); line-height: 1.2; }
.dist-title { margin: 0 0 6px; font-weight: 650; font-size: .92rem; }
.dist { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.dist li { display: grid; grid-template-columns: 1.2em minmax(0, 1fr); gap: 8px; align-items: center; font-variant-numeric: tabular-nums; }
.dist-bar { display: flex; justify-content: flex-end; width: calc(var(--w, 8) * 1%); min-width: 2em; background: var(--surface-2); border-radius: 6px; padding: 2px 8px; }
.dist li.is-today .dist-bar { background: var(--accent); color: var(--accent-ink); }
.dist-count { font-weight: 700; font-size: .88rem; }
.stats-note { margin: 10px 0 0; font-size: .84rem; color: var(--muted); }

.stats-dialog {
  width: min(92vw, 460px); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  background: var(--surface); color: var(--ink);
}
.stats-dialog::backdrop { background: rgba(8, 12, 16, .55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.dialog-head h2 { margin: 0; font-size: 1.3rem; }

/* footer */
.foot { border-top: 1px solid var(--line); padding: 18px 0 40px; color: var(--muted); font-size: .86rem; }
.foot p { margin: 0 0 6px; }

@media (min-width: 700px) {
  .play { margin-inline: 0; padding-inline: 0; }
  .brand { font-size: 1.35rem; }
}
@media (max-width: 380px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row { grid-template-columns: minmax(0, 1fr) auto 24px 3.4ch; gap: 6px; padding-inline: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  .outline.reveal .shape, .outline.is-won:not(.reveal) .shape, .row.enter { animation: none; stroke-dasharray: none; fill-opacity: 1; }
  .outline .shape { transition: none; }
}
