/* ── Base ──────────────────────────────────────────────────────────────── */
html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: #337ab7;
}
*, *::before, *::after { box-sizing: inherit; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.header-title h1 {
  margin-top: 0.5em;
  margin-bottom: 0.4em;
}

/* ── Layout grid ───────────────────────────────────────────────────────── */
.container {
  width: 100%;
  padding: 0 15px;
  margin: 0 auto;
}

.row {
  display: flex;
  flex-wrap: wrap;
}

/* Fixed-width columns (12-column grid fractions) */
.col-1  { flex: 0 0 8.3333%;  max-width: 8.3333%;  }
.col-3  { flex: 0 0 25%;      max-width: 25%;       }
.col-9  { flex: 0 0 75%;      max-width: 75%;       }
.col-10 { flex: 0 0 83.3333%; max-width: 83.3333%;  }

/* Auto-width column used in the toolbar row */
.col-md-auto { flex: 0 0 auto; padding: 0 6px; }

/* Centre the toolbar buttons */
.justify-content-md-center { justify-content: center; align-items: center; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 6px 12px;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.43;
  text-align: center;
  white-space: nowrap;
  vertical-align: middle;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 4px;
  text-decoration: none;
  background: none;
}

.btn-primary {
  background-image: linear-gradient(#f0f0f0, #a0a0a0);
  border: 0;
  border-radius: 4px;
  box-shadow: rgba(0, 0, 0, .3) 0 5px 15px;
  color: #333;
  cursor: pointer;
  font-size: .9em;
  padding: 9px 15px;
  text-align: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.btn-primary:hover,
.btn-primary:focus {
  background-image: linear-gradient(#f8f8f8, #b0b0b0);
  box-shadow: rgba(0, 0, 0, .4) 0 6px 18px;
  color: #111;
  outline: none;
}

.btn-primary:active {
  background-image: linear-gradient(#a0a0a0, #f0f0f0);
  box-shadow: rgba(0, 0, 0, .2) 0 3px 8px;
}

/* ── Form controls ─────────────────────────────────────────────────────── */
.form-control {
  display: block;
  width: 100%;
  padding: 6px 12px;
  font-size: 14px;
  line-height: 1.43;
  color: #555;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
}

textarea.form-control { height: auto; }

/* ── Country dropdown items (generated by setupCountries) ──────────────── */
.dropdown-item {
  display: block;
  padding: 5px 16px;
  color: #333;
  text-decoration: none;
  white-space: nowrap;
}

.dropdown-item:hover {
  background-color: #f0f4f8;
  color: #000;
  text-decoration: none;
}

/* ── Region hierarchy dropdown list ────────────────────────────────────── */
#location-list li {
  padding: 4px 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#location-list li:hover { background-color: #f0f4f8; }

#location-list li a {
  text-decoration: none;
  color: #333;
  pointer-events: none; /* clicks land on <li> via event delegation */
}

#location-list .level-2 { padding-left: 20px; }
#location-list .level-3 { padding-left: 32px; }

/* Region search input inside the dropdown panel */
#region-search {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
}

/* ── Region description popup ───────────────────────────────────────────── */

.region-popup h3,
.region-popup h4 {
  margin-bottom: 0;
}

.region-popup p {
  margin-top: 0;
}

.region-popup .leaflet-popup-content {
  max-height: 70vh;
  overflow-y: auto;
}

/* ── App-specific ──────────────────────────────────────────────────────── */
#map {
  flex: 1;
  min-height: 0;
}

#top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  background: rgba(51, 122, 183, 0.30);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

/* Push Leaflet zoom controls below the top-bar */
.leaflet-top {
  margin-top: 120px;
}

/* On narrow screens, hide zoom controls while a region popup is open.
   (z-index can't fix this — leaflet-map-pane's transform creates an isolated stacking context) */
@media (max-width: 640px) {
  #map.popup-open .leaflet-control-container {
    visibility: hidden;
  }
}

body.quiz-active .leaflet-top {
  margin-top: 175px;
}

.region-label {
  font-size: 12px;
  background: rgba(175, 120, 76, 0.656);
  border: 1px solid #000;
  border-radius: 4px;
  color: white;
  font-weight: bold;
  text-align: center;
  height: 20px;
  padding-top: 0;
  padding-bottom: 0;
}

.stopwatchdigit {
  font-size: 35px;
  color: #fff;
}

.stopwatchtxt {
  font-size: 15px;
  color: #fffcd6;
}

/* ── Quiz modals ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-box {
  background: #fff;
  border-radius: 8px;
  padding: 24px;
  width: 90%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

.modal-box h3 {
  margin: 0 0 16px;
  color: #2A6598;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 14px;
  color: #333;
}

.quiz-option input[type="checkbox"],
.quiz-option input[type="radio"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

/* ── Wine Knowledge Quiz ────────────────────────────────────────────────── */
.dq-modal-box {
  max-width: 620px;
}

.dq-exit-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: #888;
  cursor: pointer;
  padding: 0;
}

.dq-exit-btn:hover { color: #333; }

.dq-modal-box { position: relative; }

#dq-progress {
  font-size: 12px;
  color: #888;
  margin-bottom: 10px;
}

#dq-question {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 18px;
  color: #222;
}

#dq-answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dq-answer-btn {
  width: 100%;
  text-align: left;
  white-space: normal;
  line-height: 1.4;
  padding: 10px 14px;
  border: 1px solid #000;
}

#dq-results-difficulty {
  margin: 0 0 6px;
  font-size: 13px;
  color: #555;
}

#dq-results-score {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
}

#dq-results-rating {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 700;
  color: #2A6598;
}

/* ── WSET results review ────────────────────────────────────────────────── */
#dq-results-review {
  border-top: 1px solid #ddd;
  padding-top: 12px;
}

.dq-review-item {
  margin-bottom: 14px;
  font-size: 13px;
  line-height: 1.5;
}

.dq-review-question {
  font-weight: 600;
  color: #222;
  margin-bottom: 2px;
}

.dq-review-verdict-correct { color: #2a7a2a; }
.dq-review-verdict-wrong   { color: #b00; }

.dq-review-explanation {
  color: #555;
  font-style: italic;
  margin-top: 2px;
}

/* ── Quiz bar ───────────────────────────────────────────────────────────── */
#quiz-bar {
  display: none;
  background: #2A6598;
  color: #fff;
  padding: 8px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

#quiz-bar.active { display: flex; }

#quiz-question {
  font-weight: bold;
  font-size: 15px;
  flex: 1;
}

#quiz-score { font-size: 13px; white-space: nowrap; }

#quiz-timer {
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Quiz bar shown — map still fills remaining space automatically via flex */

/* ── More panel ─────────────────────────────────────────────────────────── */
#more-panel {
  display: none;
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: white;
  border: 1px solid #aaa;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  padding: 8px;
  min-width: 240px;
  max-width: calc(100vw - 16px);
}

.more-panel-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  padding: 3px 0;
}

.more-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.more-panel-actions .btn,
.modal-actions .btn {
  border: 1px solid #000;
}

#vineyard-search {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 13px;
  margin-top: 6px;
  box-sizing: border-box;
}

#vineyard-search-results {
  display: none;
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid #ccc;
  border-top: none;
  background: white;
  position: absolute;
  width: 100%;
  z-index: 1002;
}

#vineyard-search-results li {
  padding: 5px 8px;
  cursor: pointer;
  font-size: 13px;
}

#vineyard-search-results li:hover {
  background: #f0f4f8;
}

.vineyard-result-country {
  color: #888;
  font-size: 11px;
  margin-left: 4px;
}

/* ── Mobile / responsive ────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Header row: let the title flex and give the About link enough room */
  .col-10 { flex: 1; max-width: 100%; }
  .col-1  { flex: 0 0 auto; max-width: none; padding: 0 8px; }

  /* Toolbar: tighter vertical padding so buttons stay on one row */
  .col-md-auto { padding: 2px 4px; }


  /* Map fills remaining height automatically via flex on body */
}

