:root {
  --bg: #0b1622;
  --ocean: #0e2233;
  --panel-bg: rgba(15, 26, 38, 0.92);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eaf1f7;
  --text-dim: #9db0c0;
  --accent: #ff7a1a;   /* Rotom orange */
  --accent-2: #3E92CC;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#app { position: relative; width: 100vw; height: 100vh; background: #05070e; }
#starfield { position: absolute; inset: 0; z-index: 0; display: block; }

/* ---------- Topbar ---------- */
#topbar {
  position: absolute; z-index: 20; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 16px; padding: 12px 18px;
  background: linear-gradient(180deg, rgba(6,14,22,0.92) 0%, rgba(6,14,22,0.55) 70%, rgba(6,14,22,0) 100%);
  pointer-events: none;
}
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 40px; height: 40px; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(255,122,26,.35)); }
.brand-text h1 {
  margin: 0; font-size: 21px; font-weight: 800; letter-spacing: .015em; line-height: 1.1;
  background: linear-gradient(92deg, #ff7a1a, #ffb057); -webkit-background-clip: text;
  background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--text-dim); }
.brand-text strong { color: var(--accent); font-weight: 700; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------- Search ---------- */
.search-wrap { position: relative; width: min(400px, 40vw); }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.97); border-radius: 999px;
  padding: 7px 9px 7px 13px; box-shadow: var(--shadow);
}
.search-icon { font-size: 14px; opacity: .55; }
#search { flex: 1; border: none; outline: none; background: transparent; font-size: 14.5px; color: #14202b; min-width: 0; }
#search::placeholder { color: #8a97a3; }
#random-btn { border: none; background: var(--accent); color: #2a1600; width: 30px; height: 30px;
  border-radius: 50%; font-size: 14px; cursor: pointer; transition: transform .12s ease; flex: none; }
#random-btn:hover { transform: rotate(20deg) scale(1.08); }

.suggestions {
  position: absolute; top: calc(100% + 8px); left: 0; right: 0; margin: 0; padding: 6px;
  list-style: none; background: var(--panel-bg); backdrop-filter: blur(10px);
  border: 1px solid var(--panel-border); border-radius: 12px; box-shadow: var(--shadow);
  max-height: min(60vh, 420px); overflow-y: auto;
}
.suggestions li { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; cursor: pointer; }
.suggestions li:hover, .suggestions li.active { background: rgba(255,255,255,0.08); }
.suggestions img { width: 40px; height: 40px; object-fit: contain; flex: none; }
.sug-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sug-en { font-weight: 700; font-size: 14px; }
.sug-ja { font-size: 12px; color: var(--text-dim); }
.sug-num { margin-left: auto; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* ---------- UI language switcher ---------- */
.ui-lang-wrap {
  display: flex; align-items: center; gap: 5px; cursor: pointer;
  background: var(--panel-bg); backdrop-filter: blur(8px);
  border: 1px solid var(--panel-border); border-radius: 999px; padding: 6px 10px 6px 11px;
  box-shadow: var(--shadow);
}
.ui-lang-icon { font-size: 14px; }
#ui-lang {
  border: none; background: transparent; color: var(--text);
  font-size: 13px; font-family: inherit; cursor: pointer; outline: none;
  max-width: 108px;
}
#ui-lang option { background: #14202b; color: var(--text); }

/* ---------- Map ---------- */
#map { position: absolute; inset: 0; z-index: 1; background: transparent; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* ---------- Panel ---------- */
.panel {
  position: absolute; z-index: 15; left: 16px; bottom: 42px; width: min(350px, 84vw);
  background: var(--panel-bg); backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px 15px 11px;
  transition: transform .28s ease;
  display: flex; flex-direction: column; max-height: calc(100vh - 150px);
}
.panel.collapsed { transform: translateY(calc(100% - 56px)); }
.panel-toggle {
  position: absolute; top: 10px; right: 10px; width: 26px; height: 26px;
  border: none; border-radius: 8px; background: rgba(255,255,255,0.08);
  color: var(--text); cursor: pointer; font-size: 14px; transition: transform .2s ease;
}
.panel.collapsed .panel-toggle { transform: rotate(180deg); }

.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 11px; flex: none; }
#poke-art { width: 74px; height: 74px; object-fit: contain; flex: none; filter: drop-shadow(0 3px 8px rgba(0,0,0,.5)); }
.poke-id { min-width: 0; }
.poke-num { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.poke-en { font-size: 20px; font-weight: 800; line-height: 1.1; }
.poke-ja { font-size: 14px; color: var(--accent); }

.legend-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-dim); margin-bottom: 8px; flex: none;
}
.legend {
  list-style: none; margin: 0; padding: 0 4px 0 0; display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto; flex: 1 1 auto; min-height: 0;
}
.legend li { display: flex; align-items: center; gap: 9px; padding: 4px 6px; border-radius: 8px; }
.legend li:hover { background: rgba(255,255,255,0.06); }
.legend .swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.legend .name-block { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; flex: 1 1 auto; }
.legend .l-name { font-size: 15px; font-weight: 700; word-break: break-word; }
.legend .l-sub { font-size: 11px; color: var(--text-dim); }
.legend .play {
  flex: none; border: none; background: rgba(255,255,255,0.08); color: var(--text);
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer; font-size: 12px;
  transition: background .15s ease, transform .1s ease;
}
.legend .play:hover { background: var(--accent); transform: scale(1.1); }
.legend .play.no-voice { opacity: .38; }
.legend .l-count { flex: none; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; text-align: right; min-width: 30px; }
.legend .l-unit { display: block; font-size: 9px; opacity: .8; }

.panel-note { margin: 10px 2px 2px; font-size: 10.5px; line-height: 1.5; color: var(--text-dim); flex: none; }

/* ---------- Map controls ---------- */
.map-controls { position: absolute; z-index: 15; right: 16px; bottom: 42px; display: flex; flex-direction: column; gap: 8px; }
.ctrl-btn {
  background: var(--panel-bg); backdrop-filter: blur(8px); border: 1px solid var(--panel-border);
  color: var(--text); padding: 9px 12px; border-radius: 10px; font-size: 13px; cursor: pointer;
  box-shadow: var(--shadow); white-space: nowrap;
}
.ctrl-btn:hover { border-color: rgba(255,255,255,0.25); }

/* ---------- Tooltip ---------- */
.tooltip {
  position: absolute; z-index: 30; pointer-events: none;
  background: rgba(9,17,26,0.96); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 9px 12px; box-shadow: var(--shadow);
  transform: translate(-50%, calc(-100% - 14px)); max-width: 260px;
}
.tt-country { font-size: 12px; color: var(--text-dim); margin-bottom: 3px; }
.tt-name { font-size: 18px; font-weight: 800; line-height: 1.15; word-break: break-word; }
.tt-read { font-size: 12px; color: var(--accent); margin-top: 1px; }
.tt-lang { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* ---------- Loading ---------- */
.loading {
  position: absolute; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  gap: 12px; background: var(--bg); color: var(--text-dim); font-size: 14px; transition: opacity .4s ease;
}
.loading.hidden { opacity: 0; pointer-events: none; }
.spinner { width: 26px; height: 26px; border: 3px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Credit ---------- */
#credit {
  position: absolute; z-index: 10; left: 0; right: 0; bottom: 0; padding: 6px 14px;
  font-size: 10.5px; color: var(--text-dim);
  background: linear-gradient(0deg, rgba(6,14,22,0.85), rgba(6,14,22,0)); text-align: center; line-height: 1.5;
}
#credit a { color: var(--text-dim); text-decoration: underline; }
.disclaimer { display: block; opacity: .7; }
#author-link {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--accent); font-weight: 700; text-decoration: none;
  vertical-align: middle;
}
#author-link svg { display: inline-block; }
#author-link:hover { color: #ffb057; text-decoration: underline; }
.credit-sep { margin: 0 6px; opacity: .5; }

/* ---------- Responsive ---------- */
@media (max-width: 780px) {
  #topbar { flex-wrap: wrap; gap: 9px; padding: 9px 12px; }
  .brand-text p { display: none; }
  .topbar-right { width: 100%; margin-left: 0; }
  .search-wrap { width: auto; flex: 1 1 auto; }
  #ui-lang { max-width: 84px; }
  .panel { left: 10px; right: 10px; bottom: 46px; width: auto; max-height: 52vh; }
  .map-controls { top: 128px; bottom: auto; right: 10px; }
  .disclaimer { display: none; }
}
