:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #eef0f8;
  --text: #1c1d2b;
  --muted: #5f6377;
  --line: #e1e4ef;
  --accent: #5b5bd6;
  --accent-2: #7c4dbf;
  --accent-soft: #e8e8fb;
  --shadow: 0 1px 2px rgba(20, 22, 50, .06), 0 4px 16px rgba(20, 22, 50, .06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #101018; --surface: #1a1a25; --surface-2: #232331; --text: #ececf4;
    --muted: #a0a3b8; --line: #2c2c3c; --accent: #9b9bff; --accent-2: #c19bff;
    --accent-soft: #2a2a48; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #101018; --surface: #1a1a25; --surface-2: #232331; --text: #ececf4;
  --muted: #a0a3b8; --line: #2c2c3c; --accent: #9b9bff; --accent-2: #c19bff;
  --accent-soft: #2a2a48; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button, input { font: inherit; color: inherit; }

.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 12px;
}
.top-row, .search, main, .foot { max-width: 960px; margin-inline: auto; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font-size: 1.35rem; font-weight: 750; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }
.logo {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  mask: url(icons/icon-mask.svg) center/contain no-repeat;
  -webkit-mask: url(icons/icon-mask.svg) center/contain no-repeat;
}
.top-actions { display: flex; gap: 6px; }
.icon-btn, .btn-ghost {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  height: 36px; min-width: 36px; padding: 0 12px; cursor: pointer;
}
.icon-btn { padding: 0; font-size: 1.1rem; }
.btn-ghost { color: var(--accent); font-weight: 600; font-size: .9rem; }
.icon-btn:hover, .btn-ghost:hover { background: var(--surface-2); }

.search { margin-top: 10px; }
.search input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); padding: 0 14px 0 40px; font-size: 1rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='6'/%3E%3Cpath d='m17 17-4.5-4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 13px center;
}
.search input:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

main { padding: 12px 16px 24px; }
.stats { color: var(--muted); font-size: .88rem; margin-bottom: 10px; }
.list { list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.card {
  display: grid; grid-template-columns: 4.2rem minmax(0, 1fr) 56px; gap: 10px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 10px; cursor: pointer; box-shadow: var(--shadow); text-align: left; width: 100%;
  transition: transform .15s ease, border-color .15s ease;
}
.card:hover { transform: translateY(-1px); border-color: var(--accent); }
.thumb {
  width: 56px; height: 56px; border-radius: 9px; background: var(--surface-2);
  display: grid; place-items: center; overflow: hidden; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; }
.thumb .code-fallback { font-weight: 800; color: var(--muted); }
.card-main { min-width: 0; }
.num {
  font-size: 1.75rem; font-weight: 800; line-height: 1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; color: var(--accent); text-align: center;
  border-right: 2px solid var(--accent-soft); padding: 8px 10px 8px 0; align-self: stretch;
  display: flex; align-items: center; justify-content: center;
}
.card-title { display: flex; align-items: center; gap: 10px; }
.code {
  flex: none; font-weight: 800; font-variant-numeric: tabular-nums; font-size: 1.45rem; line-height: 1;
  letter-spacing: -.01em; color: #fff; background: var(--accent);
  padding: 6px 10px; border-radius: 9px; min-width: 2.6em; text-align: center;
}
:root[data-theme="dark"] .code { color: #11111a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .code { color: #11111a; } }
.name { font-weight: 700; font-size: .95rem; line-height: 1.25; overflow-wrap: anywhere; }
.sub { color: var(--muted); font-size: .82rem; line-height: 1.3; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.metric { font-size: .8rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.metric b { color: var(--text); font-weight: 650; }
mark { background: color-mix(in srgb, var(--accent) 25%, transparent); color: inherit; border-radius: 3px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

.sheet {
  border: none; padding: 0; margin: auto; width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 24px); border-radius: 20px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.sheet::backdrop { background: rgba(10, 10, 25, .5); backdrop-filter: blur(2px); }
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
.sheet[open] { animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet-close button {
  width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--surface-2); cursor: pointer;
}
.detail { padding: 22px 20px 20px; }
.detail-head { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; padding-right: 36px; }
.detail-map { width: 110px; height: 110px; flex: none; border-radius: 14px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; }
.detail-map img { width: 100%; height: 100%; object-fit: contain; }
.detail .code { font-size: 2.4rem; padding: 8px 14px; border-radius: 12px; display: inline-block; margin-bottom: 8px; }
.detail h2 { font-size: 1.4rem; line-height: 1.2; }
.detail .region { color: var(--muted); margin-top: 4px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fact { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.fact dt { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.fact dd { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; margin-top: 2px; }
.fact dd small { font-weight: 500; color: var(--muted); font-size: .78rem; display: block; }
.detail-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn {
  flex: 1; display: inline-flex; justify-content: center; align-items: center; height: 44px; border-radius: 12px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 650; border: none; cursor: pointer;
}
:root[data-theme="dark"] .btn { color: #11111a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn { color: #11111a; } }
.btn.secondary { background: var(--surface-2); color: var(--text); }

.foot { padding: 8px 16px 32px; color: var(--muted); font-size: .84rem; }
.foot p + p { margin-top: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: .9rem;
  box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px);
}
@media (max-width: 420px) { .list { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
