/* ============================================================
   Country Explorer — "modern atlas" theme
   Fonts: Archivo (display), IBM Plex Sans (body), IBM Plex Mono (data)
   ============================================================ */

:root {
  --ink: #16233f;          /* deep navy text */
  --ink-soft: #5b6579;
  --paper: #f4f6f9;        /* page background */
  --card: #ffffff;
  --line: #dde3ec;
  --accent: #0f766e;       /* meridian teal */
  --accent-soft: #e2f1ef;
  --gold: #f59e0b;         /* favorite star */
  --danger: #c0392b;
  --ok: #1e8e5a;
  --shadow: 0 1px 2px rgba(22, 35, 63, 0.06), 0 8px 24px rgba(22, 35, 63, 0.07);
  --radius: 14px;
}

[data-theme="dark"] {
  --ink: #e8ecf4;
  --ink-soft: #9aa5ba;
  --paper: #0e1524;
  --card: #172137;
  --line: #263450;
  --accent: #2dd4bf;
  --accent-soft: #123833;
  --gold: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  transition: background 0.25s ease, color 0.25s ease;
}

h1, h2, h3 { font-family: "Archivo", system-ui, sans-serif; }

.mono { font-family: "IBM Plex Mono", monospace; font-size: 0.8rem; }
.muted { color: var(--ink-soft); }

a { color: var(--accent); }

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0.7rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 1.2rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.65rem; }

.brand-mark {
  font-size: 1.7rem;
  color: var(--accent);
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.brand-sub { margin: 0; color: var(--ink-soft); }

/* the "meridian" — thin latitude lines under the header */
.meridian {
  height: 5px;
  background:
    repeating-linear-gradient(90deg,
      var(--accent) 0 26px,
      transparent 26px 34px);
  opacity: 0.55;
}

.tabs { display: flex; gap: 0.25rem; margin-left: auto; flex-wrap: wrap; }

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font: 600 0.9rem "IBM Plex Sans", sans-serif;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
}

.tab:hover { color: var(--ink); }

.tab.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.fav-count {
  background: var(--gold);
  color: #1d1500;
  border-radius: 999px;
  padding: 0 0.4rem;
  font-size: 0.7rem;
}

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}

/* ---------- layout ---------- */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.4rem 1.2rem 3rem;
}

.view { display: none; }
.view.is-active { display: block; animation: fadeUp 0.25s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- controls ---------- */

.controls {
  display: flex;
  gap: 0.8rem;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field.grow { flex: 1 1 240px; }

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

input[type="search"], select {
  font: 500 0.95rem "IBM Plex Sans", sans-serif;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  min-width: 150px;
}

input[type="search"]:focus, select:focus, .btn:focus, .tab:focus, .card:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font: 600 0.92rem "IBM Plex Sans", sans-serif;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 0.55rem 1rem;
  border-radius: 10px;
  cursor: pointer;
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .btn-accent { color: #06251f; }

.btn:hover { filter: brightness(1.05); }

.result-line { margin: 0 0 0.8rem; color: var(--ink-soft); }

/* ---------- status: loading & error ---------- */

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--ink-soft);
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  max-width: 480px;
}

/* ---------- country grid & cards ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(215px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
  text-align: left;
  padding: 0;
}

.card:hover { transform: translateY(-3px); }

.card-flag {
  width: 100%;
  aspect-ratio: 5 / 3;
  object-fit: cover;
  display: block;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.card-body { padding: 0.7rem 0.85rem 0.85rem; }

.card-name {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-stat {
  margin: 0.1rem 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.card-stat b { color: var(--ink); font-weight: 600; }

.star {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.88);
  color: #9aa0ab;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
}

.star.is-fav { color: var(--gold); }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 3rem 1rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---------- detail panel ---------- */

.overlay {
  position: fixed; inset: 0;
  background: rgba(10, 16, 30, 0.55);
  z-index: 30;
}

.detail {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100%);
  background: var(--card);
  border-left: 1px solid var(--line);
  z-index: 31;
  overflow-y: auto;
  padding: 1.2rem 1.4rem 2rem;
  animation: slideIn 0.22s ease;
}

@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

.detail-close {
  position: sticky;
  top: 0;
  float: right;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  width: 34px; height: 34px;
  border-radius: 50%;
  cursor: pointer;
}

.detail-flag {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin: 1.6rem 0 0.9rem;
}

.detail h2 { margin: 0 0 0.1rem; font-size: 1.5rem; letter-spacing: -0.02em; }

.detail-native { margin: 0 0 1rem; color: var(--ink-soft); }

.fact-list { margin: 0; padding: 0; list-style: none; }

.fact-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.fact-list .k { color: var(--ink-soft); }
.fact-list .v { text-align: right; font-weight: 600; }

/* weather block */
.weather {
  margin: 1.1rem 0;
  padding: 0.9rem 1rem;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius);
}

.weather h3 { margin: 0 0 0.3rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }

.weather-now { display: flex; align-items: center; gap: 0.7rem; }

.weather-temp { font: 900 1.8rem "Archivo", sans-serif; }

.weather-desc { color: var(--ink-soft); font-size: 0.85rem; }

.borders { margin-top: 1.1rem; }

.borders h3 { margin: 0 0 0.5rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }

.border-chip {
  display: inline-block;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  margin: 0 0.35rem 0.4rem 0;
  font-size: 0.8rem;
  cursor: pointer;
}

.border-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- compare ---------- */

.compare-head h2 { margin: 0 0 0.2rem; }
.compare-head p { margin: 0 0 1.2rem; }

.compare-pickers {
  display: flex;
  align-items: flex-end;
  gap: 0.8rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.vs { color: var(--ink-soft); padding-bottom: 0.7rem; }

.compare-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.compare-table th, .compare-table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  text-align: center;
}

.compare-table th { font-family: "Archivo", sans-serif; font-size: 1rem; }

.compare-table td:first-child {
  text-align: left;
  color: var(--ink-soft);
  width: 34%;
}

.compare-table .win {
  color: var(--accent);
  font-weight: 700;
}

.compare-flag { width: 42px; border-radius: 4px; vertical-align: middle; margin-right: 0.4rem; border: 1px solid var(--line); }

/* ---------- quiz ---------- */

.quiz-shell {
  max-width: 560px;
  margin: 0 auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.4rem 1.5rem 1.7rem;
}

.quiz-top { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.quiz-top h2 { margin: 0; }
.quiz-meta { color: var(--ink-soft); }

.quiz-start { text-align: center; padding: 1.4rem 0 0.4rem; }

.quiz-flag-wrap { text-align: center; margin: 1.1rem 0; }

.quiz-flag {
  max-width: 280px;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.quiz-options { display: grid; gap: 0.55rem; }

.quiz-option {
  text-align: left;
  font: 500 0.95rem "IBM Plex Sans", sans-serif;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  padding: 0.6rem 0.9rem;
  border-radius: 10px;
  cursor: pointer;
}

.quiz-option:hover { border-color: var(--accent); }

.quiz-option.correct { border-color: var(--ok); background: rgba(30, 142, 90, 0.12); color: var(--ok); font-weight: 700; }
.quiz-option.wrong { border-color: var(--danger); background: rgba(192, 57, 43, 0.1); color: var(--danger); }
.quiz-option:disabled { cursor: default; }

.quiz-feedback { min-height: 1.4rem; margin: 0.7rem 0 0.4rem; font-weight: 600; }

.quiz-final { font: 700 1.2rem "Archivo", sans-serif; }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 1rem 1.2rem 2rem;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- responsive ---------- */

@media (max-width: 640px) {
  .header-inner { gap: 0.6rem; }
  .tabs { margin-left: 0; width: 100%; justify-content: space-between; }
  .tab { padding: 0.4rem 0.6rem; font-size: 0.82rem; }
  .brand-sub { display: none; }
  .controls .field { flex: 1 1 46%; }
  .detail { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
