/* موطن — style.css
   Palette: the land is sand, the water is Red Sea teal, the chosen region is saffron.
   Fonts: Reem Kufi for the wordmark and map labels, IBM Plex Sans Arabic for text. */

:root {
  --page: #EFE9DD;
  --water: #1F5F66;
  --water-edge: #17494F;
  --ink: #1C2B2E;
  --ink-soft: #5E6E71;
  --line: #D9D0BF;
  --card: #FBF8F1;
  --select: #F0B429;
  --select-ink: #3A2B08;
  --ok: #3E7A4E;
  --bad: #B3402E;

  --font-display: "Reem Kufi", "Noto Kufi Arabic", "Segoe UI", system-ui, sans-serif;
  --font-text: "IBM Plex Sans Arabic", "Noto Naskh Arabic", "Segoe UI", system-ui, sans-serif;

  --radius: 22px;
  --col: 430px;
  --dot-empty: #E6DECB;
}

* { box-sizing: border-box; }

/* An author rule that sets `display` on an element (eg. `.result { display: flex }`)
   otherwise beats the browser's own `[hidden] { display: none }` rule even at equal
   specificity, because origin is compared before specificity in the cascade. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-text);
  -webkit-text-size-adjust: 100%;
}

body { min-height: 100dvh; }

.app {
  position: relative;
  max-width: var(--col);
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 0;
  flex-wrap: wrap;
}
.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
}
.top-note {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: left;
}
.progress-strip {
  margin: 0;
  flex-basis: 100%;
  margin-top: 10px;
  font-size: 13px;
  color: var(--ink-soft);
}

.map-panel {
  background: var(--water);
  border-radius: var(--radius);
  padding: 10px 8px;
  box-shadow: inset 0 0 0 1px var(--water-edge);
}
#map {
  display: block;
  width: 100%;
  height: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.region {
  stroke: var(--water);
  stroke-width: 2.5;
  stroke-linejoin: round;
  cursor: pointer;
  transition: fill 160ms ease, stroke 160ms ease;
  outline: none;
}
.region:hover { filter: brightness(1.06); }
.region:focus-visible { stroke: #FFFFFF; stroke-width: 4; }
.region.is-selected {
  fill: var(--select);
  stroke: #FFFFFF;
  stroke-width: 4;
}
.label {
  font-family: var(--font-display);
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
  opacity: 0.86;
}
.label.is-selected { fill: var(--select-ink); opacity: 1; }

.card {
  min-height: 108px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}
.card-hint { margin: 0; color: var(--ink-soft); font-size: 15px; line-height: 1.6; }
.card-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.2;
}
.card-line { margin: 0; font-size: 16px; line-height: 1.6; }
.card-line .k { color: var(--ink-soft); }

.credit {
  margin-top: 4px;
  padding: 0 6px;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-soft);
}

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-primary {
  font-family: var(--font-text);
  font-weight: 600;
  font-size: 17px;
  background: var(--ink);
  color: var(--page);
  border: 0;
  border-radius: 16px;
  padding: 14px 20px;
  cursor: pointer;
}
.btn-primary:active { transform: scale(0.99); }
.btn-ghost {
  background: none;
  border: 0;
  padding: 8px 0 0;
  color: var(--ink-soft);
  font-family: var(--font-text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  align-self: flex-start;
}
.row { display: flex; gap: 14px; align-items: center; margin-top: 6px; }
.row .btn-ghost { padding: 8px 4px; align-self: center; }

.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.result-actions .btn-primary { width: 100%; }
.result-links { display: flex; gap: 14px; justify-content: center; }
.result-links .btn-ghost { flex: 1 1 0; align-self: auto; padding: 8px 4px; text-align: center; }

.quiz-hud { display: flex; flex-direction: column; gap: 6px; }
.quiz-progress { margin: 0; color: var(--ink-soft); font-size: 13px; }
.quiz-prompt {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 26px;
  line-height: 1.3;
}

.result { display: flex; flex-direction: column; gap: 6px; }
.result-score { margin: 0; font-size: 17px; font-weight: 600; }

body.quiz .label, body.gov-quiz .label, body.learn-region .label, body.daily .label { display: none; }
body.daily .region { cursor: default; pointer-events: none; }

.region.flash-correct { fill: var(--ok) !important; stroke: #FFFFFF; stroke-width: 4; }
.region.flash-wrong  { fill: var(--bad) !important; stroke: #FFFFFF; stroke-width: 4; }

.region.is-dimmed { opacity: 0.32; transition: opacity 200ms ease; }

.pin-hit { fill: transparent; pointer-events: all; cursor: pointer; }
.pin-mark { fill: var(--ink); stroke: #FFFFFF; pointer-events: none; }
.pin-mark.flash-correct { fill: var(--ok) !important; }
.pin-mark.flash-wrong { fill: var(--bad) !important; }
.pin:focus-visible .pin-mark { stroke: var(--select); }
.pin.is-selected .pin-mark { fill: var(--select); }

/* Governorate shapes (data/govshapes.js) reuse the pin/flash/selection rules
   above via the shared .pin-mark class -- these two just override the default
   ink-fill/white-stroke look with a sand tone (set per-shape via --gov-fill)
   and a water-colour stroke, matching the main map's own region shapes. */
.pin-mark.gov-shape-fill {
  fill: var(--gov-fill);
  stroke: var(--water);
  stroke-width: 1.5;
  stroke-linejoin: round;
  /* Pins deliberately ignore pointer events (only their oversized invisible
     .pin-hit circle is tappable, since the visible dot is tiny) -- a shape's
     whole visible area should be tappable too, not just its small hit-circle. */
  pointer-events: auto;
  cursor: pointer;
}
.pin.is-selected .gov-shape-fill { stroke: #FFFFFF; stroke-width: 2.5; }
.pin-mark.gov-shape-fill.flash-correct,
.pin-mark.gov-shape-fill.flash-wrong { stroke: #FFFFFF; stroke-width: 2; }

#shape-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 260px;
}
.shape-path {
  stroke: var(--water-edge);
  stroke-width: 3;
  stroke-linejoin: round;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.choice-btn {
  font-family: var(--font-text);
  font-weight: 600;
  font-size: 15px;
  background: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}
.choice-btn:active { transform: scale(0.99); }
.choice-btn.flash-correct { background: var(--ok); border-color: var(--ok); color: #FFFFFF; }
.choice-btn.flash-wrong { background: var(--bad); border-color: var(--bad); color: #FFFFFF; }

@media (prefers-reduced-motion: reduce) {
  .region, .region.is-dimmed { transition: none; }
}

.daily-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  background: var(--select);
  color: var(--select-ink);
  border: 0;
  border-radius: 18px;
  padding: 16px 20px;
  font-family: var(--font-text);
  cursor: pointer;
  text-align: right;
}
.daily-cta:active { transform: scale(0.99); }
.daily-cta-title { font-weight: 700; font-size: 18px; }
.daily-cta-status { font-size: 13px; opacity: 0.85; }

#daily-form { display: flex; gap: 8px; margin-top: 2px; }
#daily-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-text);
  font-size: 15px;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--page);
  color: var(--ink);
}
#daily-input:focus { outline: none; border-color: var(--select); }
#daily-submit { flex: 0 0 auto; padding: 12px 18px; }

.daily-error { margin: 6px 0 0; color: var(--bad); font-size: 13px; }

.daily-guesses { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.daily-guess-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--page);
  border-radius: 12px;
  font-size: 14px;
}
.daily-guess-name { font-weight: 600; }
.daily-guess-distance { color: var(--ink-soft); font-size: 13px; }
.daily-guess-arrow { font-size: 16px; }
.daily-guess-square { font-size: 16px; }

#daily-result { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }

.trivia-chip {
  display: inline-block;
  align-self: flex-start;
  margin: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--select);
  color: var(--select-ink);
  font-family: var(--font-text);
  font-size: 12px;
  font-weight: 600;
}

.badges { display: flex; flex-direction: column; gap: 6px; }
.badge-strip-label {
  margin: 0;
  padding: 0 4px;
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
}
.badge-strip-label .hint { font-size: 11px; opacity: 0.8; }

.badge-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  justify-content: center;
  /* Exactly wide enough for 7 slots (44px + 2px gap each): forces a max of 7
     per row and, since the container itself is centered, makes the shorter
     6-slot second row symmetric under it instead of drifting to one side. */
  max-width: 320px;
  margin: 0 auto;
}
/* The visible circle stays compact (13 need to fit on one row at 390px) --
   the button itself is the full 44px minimum tap target around it. */
.badge-slot {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.badge-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px dashed var(--line);
  background: var(--dot-empty);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}
.badge-dot.gold {
  border-style: solid;
  border-color: #C89B2E;
  background: radial-gradient(circle at 35% 30%, #FFD873, #F0B429 65%, #C89B2E 100%);
}
.badge-dot.silver {
  border-style: solid;
  border-color: #9CA1A6;
  background: radial-gradient(circle at 35% 30%, #EEF1F2, #C9CDD1 65%, #9CA1A6 100%);
}

.badge-detail {
  margin: 0;
  padding: 0 4px;
  font-size: 13px;
  color: var(--ink-soft);
  text-align: center;
}

.toast {
  position: fixed;
  bottom: max(20px, calc(env(safe-area-inset-bottom) + 14px));
  left: 50%;
  right: auto;
  transform: translateX(-50%) translateY(8px);
  max-width: min(340px, calc(100vw - 32px));
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--line);
  padding: 10px 16px;
  border-radius: 14px;
  font-family: var(--font-text);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0,0,0,.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 60;
}
.toast::before {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--select);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.celebrate { border-color: var(--select); }

/* On a short viewport the compact-content screens (quiz/shapes/gov/trivia
   results, etc.) can end close enough to the actual viewport edge that a
   viewport-anchored toast lands on top of their last visible content --
   `.app`'s own trailing padding can't fix that (it doesn't move anything
   earlier in the flow). So below a real content-collision height, the toast
   switches from floating over the viewport to simply trailing the app's own
   content -- guaranteed never to overlap it, by construction, at the cost of
   no longer always being pinned to the visible screen edge on a short device. */
@media (max-height: 700px) {
  .toast {
    position: absolute;
    bottom: auto;
    top: 100%;
    margin-top: 14px;
    transform: translateX(-50%) translateY(-8px);
  }
  .toast.show { transform: translateX(-50%) translateY(0); }
}
