:root {
  color-scheme: light dark;
  --page: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #ffffff;
  --surface-raised: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #8e8e93;
  --border: rgba(60, 60, 67, 0.12);
  --divider: rgba(60, 60, 67, 0.09);
  --blue: #007aff;
  --blue-strong: #0568d8;
  --blue-soft: #e8f2ff;
  --gold: #f0a500;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 8px 28px rgba(0, 0, 0, 0.05);
  --radius: 18px;
  --safe-bottom: max(24px, env(safe-area-inset-bottom));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--page);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -10%, rgba(0, 122, 255, 0.1), transparent 34rem),
    var(--page);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 3px solid rgba(0, 122, 255, 0.32); outline-offset: 2px; }
[hidden] { display: none !important; }

.app-shell {
  width: min(100%, 470px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 16px var(--safe-bottom);
}

.hero { padding: 8px 4px 20px; }
.brand-row { display: flex; align-items: center; gap: 12px; }

.brand-mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(145deg, #36a6ff, #0068e0);
  box-shadow: 0 8px 24px rgba(0, 105, 224, 0.23);
}

.brand-mark svg { width: 31px; height: 31px; fill: none; stroke: currentColor; stroke-width: 1.55; stroke-linecap: round; }
.eyebrow { margin: 0 0 2px; color: var(--blue); font-size: 10px; font-weight: 750; letter-spacing: 0.11em; }
h1 { margin: 0; font-size: clamp(24px, 7vw, 30px); line-height: 1.05; letter-spacing: -0.045em; }
.territory-count { margin-left: auto; padding: 6px 9px; border-radius: 999px; color: var(--blue-strong); background: var(--blue-soft); font-size: 11px; font-weight: 650; white-space: nowrap; }
.hero-copy { margin: 14px 0 0 60px; color: var(--muted); font-size: 14px; line-height: 1.45; }

.search-wrap { position: sticky; top: max(8px, env(safe-area-inset-top)); z-index: 10; margin-bottom: 18px; }
.search-box {
  display: flex;
  min-height: 50px;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
}
.search-box > svg { flex: 0 0 21px; width: 21px; fill: none; stroke: var(--faint); stroke-width: 1.8; stroke-linecap: round; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 16px; }
.search-box input::placeholder { color: var(--faint); }
.clear-search { flex: 0 0 28px; width: 28px; height: 28px; padding: 0 0 2px; border: 0; border-radius: 50%; color: var(--surface-solid); background: var(--faint); font-size: 20px; line-height: 1; cursor: pointer; }

.device-notice, .last-choice {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid rgba(255, 149, 0, 0.24);
  border-radius: var(--radius);
  background: rgba(255, 247, 225, 0.9);
}
.device-notice > span { font-size: 25px; }
.device-notice strong { font-size: 14px; }
.device-notice p { margin: 3px 0 0; color: #806425; font-size: 12px; line-height: 1.45; }

.last-choice { justify-content: space-between; border-color: rgba(0, 122, 255, 0.14); background: var(--blue-soft); }
.section-kicker { color: var(--blue-strong); font-size: 11px; font-weight: 700; }
.last-choice p { margin: 3px 0 0; font-size: 15px; font-weight: 650; }
.compact-action { min-height: 36px; padding: 0 12px; border: 0; border-radius: 10px; color: #fff; background: var(--blue); font-size: 12px; font-weight: 650; cursor: pointer; }

.country-section, .search-results { margin-bottom: 24px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; margin: 0 4px 10px; }
.section-heading h2 { margin: 0; font-size: 18px; letter-spacing: -0.025em; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }

.country-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.country-card { display: flex; min-width: 0; min-height: 66px; overflow: hidden; border: 1px solid var(--border); border-radius: 16px; background: var(--surface-raised); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.025); transition: transform 120ms ease, background-color 120ms ease; }
.country-card:active { transform: scale(0.985); background: var(--blue-soft); }
.country-open { display: flex; flex: 1 1 auto; min-width: 0; min-height: 64px; align-items: center; gap: 9px; padding: 9px 4px 9px 11px; border: 0; text-align: left; background: transparent; cursor: pointer; }
.flag { flex: 0 0 auto; font-size: 27px; line-height: 1; filter: saturate(0.94); }
.country-names { display: block; min-width: 0; }
.country-names strong, .country-names small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country-names strong { font-size: 14px; font-weight: 660; }
.country-names small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.favorite-toggle { flex: 0 0 36px; min-width: 36px; min-height: 52px; padding: 0; border: 0; color: var(--faint); background: transparent; font-size: 22px; line-height: 1; cursor: pointer; }
.favorite-toggle.is-favorite { color: var(--gold); }

.all-regions-action {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  width: 100%;
  min-height: 76px;
  align-items: center;
  gap: 12px;
  margin: 2px 0 24px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.all-regions-action:active { background: var(--blue-soft); }
.all-regions-icon { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; color: var(--blue); background: var(--blue-soft); }
.all-regions-icon svg { width: 21px; fill: currentColor; }
.all-regions-action strong, .all-regions-action small { display: block; }
.all-regions-action strong { font-size: 15px; }
.all-regions-action small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.chevron { color: var(--faint); font-size: 30px; font-weight: 300; }

.all-view-header { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 18px; }
.all-view-header p { margin: 0; font-size: 14px; font-weight: 650; }
.back-button { min-height: 42px; padding: 0 5px 0 0; border: 0; color: var(--blue); background: transparent; font-size: 14px; cursor: pointer; }
.back-button span { font-size: 27px; vertical-align: -2px; }
.region-section { margin-bottom: 26px; }
.region-title { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 10px; }
.region-title h2 { margin: 0; font-size: 18px; }
.region-title span { color: var(--muted); font-size: 11px; }

.empty-state { padding: 34px 24px; border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; background: var(--surface); }
.empty-state > span { color: var(--faint); font-size: 44px; }
.empty-state h3 { margin: 8px 0 5px; font-size: 17px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.55; }

.guide-card { margin-top: 4px; padding: 18px; border: 1px solid var(--border); border-radius: 22px; background: var(--surface-raised); box-shadow: var(--shadow); }
.guide-title { display: flex; align-items: center; gap: 11px; }
.guide-title > span { display: grid; width: 35px; height: 35px; place-items: center; border-radius: 50%; color: #fff; background: var(--blue); font-family: Georgia, serif; font-weight: 700; }
.guide-title h2 { margin: 0; font-size: 17px; }
.guide-title p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.guide-card ol { margin: 18px 0; padding: 0; list-style: none; }
.guide-card li { display: flex; align-items: center; gap: 11px; padding: 9px 0; border-bottom: 1px solid var(--divider); }
.guide-card li:last-child { border-bottom: 0; }
.guide-card li > span { display: grid; flex: 0 0 25px; height: 25px; place-items: center; border-radius: 50%; color: var(--blue-strong); background: var(--blue-soft); font-size: 11px; font-weight: 750; }
.guide-card li p { margin: 0; font-size: 13px; line-height: 1.45; }
.privacy-note { display: flex; gap: 10px; padding: 13px; border-radius: 14px; background: var(--page); }
.privacy-note svg { flex: 0 0 23px; width: 23px; fill: none; stroke: #34c759; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.privacy-note p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.privacy-note strong { color: var(--text); font-size: 12px; }
.troubleshooting { margin-top: 12px; padding: 0 3px; }
.troubleshooting summary { min-height: 42px; padding: 12px 0 8px; color: var(--blue); font-size: 12px; font-weight: 650; cursor: pointer; }
.troubleshooting p { margin: 4px 0 8px; color: var(--muted); font-size: 11px; line-height: 1.55; }

footer { padding: 22px 0 2px; text-align: center; color: var(--faint); font-size: 10px; line-height: 1.5; }
footer p { margin: 3px 0; }
footer code { font-size: 10px; }

.install-sheet { position: fixed; z-index: 30; right: 12px; bottom: var(--safe-bottom); left: 12px; display: grid; grid-template-columns: 48px 1fr 30px; max-width: 430px; align-items: center; gap: 12px; margin: auto; padding: 14px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: 0 16px 44px rgba(0, 0, 0, 0.18); -webkit-backdrop-filter: blur(24px) saturate(160%); backdrop-filter: blur(24px) saturate(160%); }
.install-sheet img { border-radius: 11px; }
.install-sheet strong { font-size: 14px; }
.install-sheet p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.4; }
.install-dismiss { grid-column: 3; grid-row: 1; width: 30px; height: 30px; border: 0; border-radius: 50%; color: var(--muted); background: var(--page); font-size: 20px; cursor: pointer; }

.toast { position: fixed; z-index: 40; right: 20px; bottom: calc(var(--safe-bottom) + 8px); left: 20px; max-width: 390px; margin: auto; padding: 12px 16px; border-radius: 999px; color: #fff; text-align: center; background: rgba(29, 29, 31, 0.9); box-shadow: 0 10px 28px rgba(0, 0, 0, 0.24); opacity: 0; transform: translateY(18px); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; font-size: 13px; font-weight: 600; }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

@media (min-width: 700px) {
  .app-shell { padding-top: 42px; }
  .search-wrap { top: 18px; }
}

@media (max-width: 359px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .country-grid { gap: 7px; }
  .country-open { gap: 6px; padding-left: 8px; }
  .flag { font-size: 23px; }
  .favorite-toggle { flex-basis: 32px; min-width: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #000000;
    --surface: rgba(28, 28, 30, 0.9);
    --surface-solid: #1c1c1e;
    --surface-raised: #1c1c1e;
    --text: #f5f5f7;
    --muted: #a1a1a6;
    --faint: #8e8e93;
    --border: rgba(255, 255, 255, 0.11);
    --divider: rgba(255, 255, 255, 0.08);
    --blue: #0a84ff;
    --blue-strong: #64adff;
    --blue-soft: rgba(10, 132, 255, 0.16);
    --shadow: none;
  }
  body { background: radial-gradient(circle at 50% -10%, rgba(10, 132, 255, 0.16), transparent 32rem), var(--page); }
  .device-notice { border-color: rgba(255, 159, 10, 0.24); background: rgba(88, 65, 10, 0.4); }
  .device-notice p { color: #d5b96f; }
  .toast { background: rgba(242, 242, 247, 0.94); color: #1d1d1f; }
}
