:root {
  --bg: #05070d;
  --card: rgba(14, 20, 34, 0.82);
  --card-solid: #0f1626;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eef3fb;
  --muted: #95a3ba;
  --faint: #66738a;
  --accent: #4ea8ff;
  --hover: rgba(255, 255, 255, 0.06);
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font: 14px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
body { overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#bg, #fg { position: fixed; inset: 0; display: block; }
#fg { touch-action: none; cursor: grab; outline: none; }
#fg:focus-visible { box-shadow: inset 0 0 0 2px rgba(78, 168, 255, 0.5); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- panel ---------- */
.panel {
  position: fixed; top: 16px; left: 16px; width: 360px; z-index: 5;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 12px;
  backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 26px; height: 26px; color: #fff; }
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; margin: 0; flex: 1; }
.brand-actions { display: flex; gap: 4px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: transparent; border: 0; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.slots { display: flex; flex-direction: column; gap: 8px; }
.slot { display: flex; align-items: center; gap: 4px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.03); transition: border-color .15s, background .15s; position: relative; }
.slot.selected { border-color: color-mix(in srgb, var(--c) 60%, transparent); background: color-mix(in srgb, var(--c) 9%, transparent); }
.pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 9px 6px 9px 12px; background: none; border: 0; cursor: pointer; text-align: left; border-radius: 12px; }
.pick:hover .chev { color: var(--text); }
.swatch { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: color-mix(in srgb, var(--c) 30%, transparent); border: 1.5px solid var(--c); flex: none; color: #fff; }
.swatch svg { width: 15px; height: 15px; stroke-width: 2; }
.slots { position: relative; }
.swap { position: absolute; right: 54px; top: 50%; transform: translateY(-50%); z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--card-solid); border: 1px solid var(--line-strong); color: var(--muted); cursor: pointer; transition: color .15s, transform .2s; }
.swap svg { width: 15px; height: 15px; }
.swap:hover:not(:disabled) { color: var(--text); transform: translateY(-50%) rotate(180deg); }
.swap:disabled { opacity: 0; pointer-events: none; }
.pick-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pick-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-meta:empty { display: none; }
.pick-area { color: var(--text); font-variant-numeric: tabular-nums; font-size: 12.5px; white-space: nowrap; opacity: .9; }
.slot.empty .pick-name { color: var(--muted); font-weight: 500; }
.chev { color: var(--faint); width: 16px; height: 16px; }
.slot .locate { width: 34px; height: 34px; margin-right: 4px; }
.slot.loading::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 2px; background: linear-gradient(90deg, transparent, var(--c), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: load 1s linear infinite; }
@keyframes load { from { background-position: -100% 0; } to { background-position: 200% 0; } }

.verdict { margin: 0; font-size: 14.5px; line-height: 1.45; color: var(--muted); min-height: 21px; }
.verdict b { color: var(--text); font-weight: 600; }
.verdict .ratio { color: #fff; font-weight: 750; font-size: 16px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin: 0 5px 1px 0; vertical-align: middle; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.actions button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 54px; padding: 0 4px; border-radius: 11px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--line); cursor: pointer; font-size: 12px; font-weight: 550; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.actions button svg { width: 18px; height: 18px; }
.actions button:hover:not(:disabled) { background: rgba(255,255,255,0.11); border-color: var(--line-strong); }
.actions button:active:not(:disabled) { transform: scale(.97); }
.actions button:disabled { opacity: .4; cursor: default; }

.prefs { display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); font-size: 12.5px; }
.seg { display: inline-flex; background: rgba(255,255,255,0.05); border-radius: 9px; padding: 2px; border: 1px solid var(--line); }
.seg button { border: 0; background: none; padding: 4px 10px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 12.5px; }
.seg button[aria-pressed="true"] { background: rgba(255,255,255,0.12); color: var(--text); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 30px; height: 18px; border-radius: 9px; background: rgba(255,255,255,0.14); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(12px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- HUD ---------- */
.hud { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; color: var(--muted); font-size: 11.5px; pointer-events: none; text-shadow: 0 1px 3px #000; z-index: 2; }
.scale { display: flex; align-items: center; gap: 8px; }
.scale-bar { height: 6px; border: 1.5px solid rgba(255,255,255,0.7); border-top: 0; transition: width .15s; }
.zoom { position: fixed; right: 16px; bottom: 64px; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); z-index: 3; padding: 2px; }
.zoom .icon-btn { color: var(--text); }

.hint, .toast {
  position: fixed; left: 50%; transform: translate(-50%, 12px); bottom: 24px; z-index: 6; width: max-content; max-width: min(560px, calc(100vw - 32px));
  background: var(--card-solid); border: 1px solid var(--line-strong); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; text-align: center; font-size: 13px; color: var(--text);
}
.hint.show, .toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast { bottom: 76px; }
.kbd { display: inline-block; min-width: 20px; padding: 0 5px; border-radius: 5px; border: 1px solid var(--line-strong); background: rgba(255,255,255,0.06); font-size: 12px; line-height: 18px; text-align: center; margin: 0 1px; }

/* ---------- search ---------- */
.search { position: fixed; inset: 0; z-index: 20; background: rgba(3, 6, 12, 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); display: flex; align-items: flex-start; justify-content: flex-start; padding: 16px; animation: fade .15s ease-out; }
.search[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.search-card { width: 420px; max-width: 100%; max-height: min(640px, calc(100vh - 32px)); display: flex; flex-direction: column; background: var(--card-solid); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; animation: pop .18s cubic-bezier(.2,.9,.3,1.2); }
@keyframes pop { from { transform: translateY(-6px) scale(.98); opacity: 0; } }
.search-top { display: flex; align-items: center; padding: 10px 8px 0 16px; }
.search-top h2 { flex: 1; margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.search-box { display: flex; align-items: center; gap: 10px; margin: 8px 12px; padding: 0 12px; border-radius: 12px; background: rgba(255,255,255,0.06); border: 1px solid var(--line-strong); }
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(78,168,255,0.18); }
.search-box svg { color: var(--muted); }
.search-box input { flex: 1; min-width: 0; height: 44px; border: 0; background: none; color: var(--text); font: 16px var(--font); outline: none; }
.search-box input::-webkit-search-cancel-button { filter: invert(1) opacity(.5); }
.cats { display: flex; gap: 6px; padding: 2px 12px 10px; overflow-x: auto; scrollbar-width: none; }
.cats::-webkit-scrollbar { display: none; }
.cats button { flex: none; height: 28px; padding: 0 11px; border-radius: 14px; border: 1px solid var(--line); background: none; color: var(--muted); font-size: 12.5px; cursor: pointer; white-space: nowrap; }
.cats button:hover { color: var(--text); border-color: var(--line-strong); }
.cats button[aria-pressed="true"] { background: var(--text); color: #0b1220; border-color: var(--text); font-weight: 600; }
.results { list-style: none; margin: 0; padding: 4px 6px 8px; overflow-y: auto; border-top: 1px solid var(--line); overscroll-behavior: contain; }
.list-head { padding: 10px 10px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 600; }
.res { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; cursor: pointer; }
.res.active { background: rgba(255,255,255,0.075); }
.res-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.res-name { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-name mark { background: none; color: var(--accent); font-weight: 700; }
.res-meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res-area { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty-msg { padding: 24px 12px; text-align: center; color: var(--muted); }
.cat-ico { width: 30px; height: 30px; border-radius: 9px; flex: none; background: rgba(255,255,255,0.06) center / 17px no-repeat; }
.cat-country { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 21V4M5 4h11l-2 4 2 4H5'/%3E%3C/svg%3E"); }
.cat-state { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M4 5h9l1 4h6v10H8l-1-5H4z'/%3E%3C/svg%3E"); }
.cat-continent { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18M12 3c3 3 3 15 0 18M12 3c-3 3-3 15 0 18'/%3E%3C/svg%3E"); }
.cat-lake { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366b3ff' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M3 9c3-2 6 2 9 0s6-2 9 0M3 15c3-2 6 2 9 0s6-2 9 0'/%3E%3C/svg%3E"); }
.cat-sea { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366b3ff' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M2 7c2.5-2 5 2 7.5 0s5-2 7.5 0 3 1 5 0M2 12c2.5-2 5 2 7.5 0s5-2 7.5 0 3 1 5 0M2 17c2.5-2 5 2 7.5 0s5-2 7.5 0 3 1 5 0'/%3E%3C/svg%3E"); }
.cat-island { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 18c3-1.5 6 1.5 9 0s6-1.5 9 0M7 15c1-3 3-5 6-5s4 2 5 5M12 10V5m0 0c-2-1-4 0-5 1m5-1c2-1 4 0 5 1'/%3E%3C/svg%3E"); }
.cat-desert { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23e0b26b' stroke-width='1.8' stroke-linecap='round'%3E%3Ccircle cx='17' cy='7' r='2.5'/%3E%3Cpath d='M2 18c4-5 8-5 12 0M10 18c3-3 7-4 12-1'/%3E%3C/svg%3E"); }
.cat-mountain { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M2 19 9 7l4 6 2-3 7 9z'/%3E%3C/svg%3E"); }
.cat-landform { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2395a3ba' stroke-width='1.8' stroke-linecap='round'%3E%3Cpath d='M3 16c3-4 5-6 9-6s6 2 9 6M3 20h18'/%3E%3C/svg%3E"); }

/* ---------- help ---------- */
.help { border: 0; padding: 0; background: none; color: var(--text); max-width: min(480px, calc(100vw - 32px)); }
.help::backdrop { background: rgba(3, 6, 12, 0.6); backdrop-filter: blur(3px); }
.help-card { background: var(--card-solid); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.help h2 { margin: 0 0 8px; font-size: 18px; }
.help p { color: var(--muted); margin: 8px 0; }
.help ul { padding-left: 18px; margin: 12px 0; display: grid; gap: 8px; }
.help .small { font-size: 12px; }
.help a { color: var(--accent); }
.primary { background: var(--text); color: #0b1220; border: 0; border-radius: 10px; height: 38px; padding: 0 18px; font-weight: 650; cursor: pointer; margin-top: 6px; }

/* ---------- mobile ---------- */
@media (max-width: 759px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; border-radius: 20px 20px 0 0; border-bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); gap: 9px;
  }
  .brand { order: -1; }
  .brand h1 { font-size: 15px; }
  .logo { width: 22px; height: 22px; }
  .icon-btn { width: 40px; height: 40px; }
  .pick { padding: 8px 4px 8px 10px; min-height: 48px; }
  .pick-name { font-size: 15px; }
  .slots { gap: 6px; }
  .verdict { font-size: 14px; }
  .actions button { height: 50px; font-size: 11.5px; }
  .prefs { padding-top: 8px; }
  .hud { top: calc(12px + env(safe-area-inset-top)); right: 12px; bottom: auto; }
  .zoom { display: none; }
  .hint { bottom: calc(var(--panel-h, 300px) + 12px); }
  .toast { bottom: calc(var(--panel-h, 300px) + 12px); }
  .search { padding: 0; }
  .search-card { width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0; padding-top: env(safe-area-inset-top); }
  .res { padding: 10px; }
}
@media (max-width: 759px) and (max-height: 640px) {
  .prefs { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
