* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; height: 100dvh; }
body {
  display: flex;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #14151a;
  color: #e6e6e9;
}

#sidebar {
  width: 360px;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #2a2c34;
  overflow: hidden;
}
header { padding: 14px 16px 8px; }
h1 { font-size: 22px; letter-spacing: 0.5px; }
h1 span { color: #ffb454; }
.tag { color: #8a8d98; font-size: 12px; margin-top: 2px; }

#pad-wrap { position: relative; margin: 8px auto 0; }
#pad {
  background: #1c1e26;
  border: 1px solid #2a2c34;
  border-radius: 10px;
  cursor: crosshair;
  touch-action: none;
  display: block;
  /* CSS-driven size: the backing store is fitted to this box (× dpr) in JS */
  width: 320px;
  height: 320px;
}
#pad-hint {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #4a4d58; font-size: 14px; pointer-events: none;
}

#controls {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; font-size: 12px; color: #8a8d98;
}
#controls button {
  background: #2a2c34; color: #e6e6e9; border: none;
  padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
#controls button:hover { background: #353845; }
#controls label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
#status { margin-left: auto; color: #ffb454; }

#results { flex: 1; overflow-y: auto; padding: 4px 10px 10px; }
.result {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.result:hover { background: #1c1e26; }
.result.active { background: #1f2733; border-color: #2f4a66; }
.result canvas {
  background: #1c1e26; border-radius: 6px; flex-shrink: 0;
  width: 54px; height: 54px;
}
.result .info { min-width: 0; }
.result .name {
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result .sub { font-size: 11px; color: #8a8d98; margin-top: 1px; }
.result .match { color: #6bd18a; font-weight: 600; }
.result .rank { color: #4a4d58; font-size: 11px; width: 16px; text-align: right; }

footer { padding: 8px 16px; font-size: 11px; color: #4a4d58; border-top: 1px solid #2a2c34; }

#map { flex: 1; background: #0e0f13; }
.leaflet-container { background: #0e0f13; }

/* ---- mobile: stack pad → results strip → map ---------------------- */
@media (max-width: 720px) {
  body { flex-direction: column; }
  #sidebar {
    width: 100%; min-width: 0; flex: 0 0 auto;
    border-right: none; border-bottom: 1px solid #2a2c34;
    overflow: visible;
  }
  header { padding: 8px 14px 2px; display: flex; align-items: baseline; gap: 10px; }
  h1 { font-size: 18px; }
  .tag { margin-top: 0; font-size: 11px; }
  #pad-wrap { margin: 4px auto 0; }
  #pad { width: min(58vw, 280px); height: min(58vw, 280px); }
  #controls { padding: 6px 14px; }
  /* results become a horizontal strip so the map keeps its height */
  #results {
    flex: none; display: flex; flex-direction: row; align-items: stretch;
    gap: 6px; overflow-x: auto; overflow-y: hidden;
    padding: 2px 8px 8px; -webkit-overflow-scrolling: touch;
  }
  #results:empty { display: none; }
  .result {
    flex: 0 0 auto; width: 168px; padding: 5px 6px; gap: 7px;
  }
  .result .info { flex: 1; }
  .result .rank { display: none; }
  footer { display: none; }
  #map { min-height: 180px; }
}
