:root { font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif; }
    body { margin: 0; height: 100vh; display: grid; --sidebar-w: 360px; grid-template-columns: var(--sidebar-w) 1fr; transition: grid-template-columns 180ms ease; background: #0b0d12; color: #e8ecf3; }
    body.sidebar-collapsed { --sidebar-w: 0px; }
    body.sidebar-collapsed #sidebar { padding: 0; border-right: none; overflow: hidden; }
    body.sidebar-collapsed #sidebar > * { display: none; }

    #toggleSidebar { position: absolute; top: 12px; left: 12px; z-index: 60; padding: 10px 12px; border-radius: 12px; }

    #sidebarBackdrop {
      position: fixed;
      inset: 0;
      z-index: 74;
      background: rgba(0,0,0,.45);
      opacity: 0;
      pointer-events: none;
      transition: opacity 160ms ease;
    }

    #sidebar { padding: 14px; border-right: 1px solid #222a3a; overflow: auto; min-width: 0; }
    #main { position: relative; overflow: hidden; min-width: 0; }
    .card { background: #121826; border: 1px solid #222a3a; border-radius: 14px; padding: 12px; margin-bottom: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
    .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
    button, input, select {
      background: #0e1422; color: #e8ecf3; border: 1px solid #2a3550; border-radius: 10px;
      padding: 10px 10px; font-size: 14px;
    }
    button { cursor: pointer; }
    button:hover { border-color: #3b4b75; }
    button.primary { background: #1b2a4a; border-color: #3b5aa0; }
    button.danger { border-color: #7a2d2d; }
    button:disabled { opacity: .55; cursor: not-allowed; }
    label { font-size: 12px; opacity: .85; }
    small { opacity: .75; display: block; margin-top: 6px; line-height: 1.35; }
    #canvasWrap { position: absolute; inset: 0; overflow: auto; padding: 12px; box-sizing: border-box; touch-action: none; overscroll-behavior: contain; }
    canvas { display: block; border-radius: 16px; border: 1px solid #222a3a; background: #0e1422; touch-action: none; }

    #mobileMapControls {
      position: absolute;
      right: 12px;
      bottom: 12px;
      z-index: 65;
      display: none;
      flex-direction: column;
      gap: 8px;
      pointer-events: none;
    }
    #mobileMapControls > button {
      min-width: 52px;
      min-height: 44px;
      padding: 10px 12px;
      border-radius: 14px;
      box-shadow: 0 10px 24px rgba(0,0,0,.28);
      pointer-events: auto;
      font-weight: 700;
    }

    /* Route hover tooltip (shows ? or answer near cursor) */
    #routeHoverTip{
      position: fixed;
      z-index: 90;
      pointer-events: none;
      left: 0; top: 0;
      opacity: 0;
      transform: translate(-50%, -110%);
      transition: opacity 80ms ease, transform 80ms ease;
      padding: 6px 10px;
      border-radius: 12px;
      border: 2px solid rgba(110,160,255,0.95);
      background: rgba(0,0,0,0.72);
      color: rgba(255,255,255,0.98);
      font-size: 14px;
      font-weight: 650;
      letter-spacing: .2px;
      box-shadow: 0 10px 24px rgba(0,0,0,.35);
      max-width: min(360px, 70vw);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    #routeHoverTip.answered{
      color: rgba(251,188,4,0.98); /* deep yellow */
    }
    .pill { padding: 6px 10px; border-radius: 999px; border: 1px solid #2a3550; background:#0e1422; font-size: 12px; }
    .muted { opacity: .75; }
    #targetsList { max-height: 260px; overflow: auto; border-radius: 12px; border:1px solid #222a3a; }
    .targetItem {
      display:flex; justify-content:space-between; gap: 8px; padding: 10px; border-bottom:1px solid #1c2436;
      cursor: pointer;
    }
    .targetItem:last-child { border-bottom: none; }
    .targetItem:hover { background: rgba(255,255,255,.03); }
    .targetItem.selected { outline: 2px solid rgba(110,160,255,.6); outline-offset: -2px; }
    .kbd { font-family: ui-monospace, Menlo, Consolas, monospace; border:1px solid #2a3550; border-bottom-width:2px; padding:2px 6px; border-radius: 6px; }
    .ok { color: #a9f5c8; }
    .bad { color: #ffb4b4; }
/* Tabs (multi-map) */
.tabRow { display:flex; gap:8px; flex-wrap: wrap; }
.tabBtn {
  flex: 1 1 140px;
  min-width: 0;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid #2a3550;
  background: #0e1422;
  color: #e8ecf3;
  cursor: pointer;
}
.tabBtn:hover { border-color:#3b4b75; }
.tabBtn.active { background:#1b2a4a; border-color:#3b5aa0; }

/* Drag-to-pan (quiz mode) */
body.mode-quiz #canvasWrap { cursor: grab; }
body.mode-quiz #canvasWrap.panning { cursor: grabbing; }


/* Legal quiz */
#legalQuizPanel {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 72px 18px 18px;
  box-sizing: border-box;
}

.legalShell {
  max-width: 980px;
  margin: 0 auto;
}

.legalHero {
  margin-bottom: 14px;
}

.legalSectionLabel {
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .72;
  margin-bottom: 6px;
}

.legalCrimeTitle {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
}

.legalDefinition {
  margin-top: 10px;
  color: rgba(232,236,243,.82);
  line-height: 1.45;
}

.legalElementCard {
  border: 1px solid #222a3a;
  border-radius: 14px;
  padding: 14px;
  background: rgba(14,20,34,.72);
  margin-top: 12px;
}

.legalElementHeader {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 8px;
  opacity: .82;
}

.legalPrompt {
  font-size: 18px;
  line-height: 1.7;
  margin-bottom: 10px;
  word-break: break-word;
}

.legalBlank {
  display: inline-block;
  min-width: 3.75ch;
  color: rgba(110,160,255,0.98);
  font-weight: 700;
  letter-spacing: .03em;
}

.legalInputLabel {
  display: block;
  margin-bottom: 6px;
}

.legalAnswerInput,
.legalInput {
  width: min(560px, 100%);
}

.legalAnswerInput.goodInput,
.legalInput.goodInput {
  border-color: #3f8f5c;
  box-shadow: 0 0 0 1px rgba(63,143,92,.35) inset;
}

.legalAnswerInput.badInput,
.legalInput.badInput {
  border-color: #9f4141;
  box-shadow: 0 0 0 1px rgba(159,65,65,.35) inset;
}

.legalAnswerKey {
  margin-top: 8px;
  font-size: 14px;
  color: #a9f5c8;
}

.legalFeedback {
  margin-top: 14px;
  min-height: 1.5em;
  line-height: 1.45;
}

.legalEmpty {
  padding: 16px;
  border: 1px dashed #2a3550;
  border-radius: 14px;
  opacity: .78;
}

body.legal-active #main {
  overflow: auto;
}


.legalDefinition.isHidden {
  color: rgba(232,236,243,.55);
  font-style: italic;
}


.legalTitleLink {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: rgba(110,160,255,0.72);
  text-underline-offset: 0.12em;
}

.legalTitleLink:hover {
  color: #a8c4ff;
}

.legalTitleLink:focus-visible {
  outline: 2px solid rgba(110,160,255,0.9);
  outline-offset: 4px;
  border-radius: 6px;
}

@media (max-width: 900px) {
  body {
    display: block;
    height: 100dvh;
    min-height: 100dvh;
    overflow: hidden;
  }

  #main {
    height: 100dvh;
  }

  #toggleSidebar {
    position: fixed;
    top: max(12px, calc(env(safe-area-inset-top) + 8px));
    left: 12px;
    z-index: 85;
    min-width: 48px;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 14px;
    box-shadow: 0 10px 24px rgba(0,0,0,.28);
  }

  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(92vw, 420px);
    max-width: 420px;
    z-index: 80;
    background: #0b0d12;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    border-right: 1px solid #222a3a;
    padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
    box-sizing: border-box;
    overflow: auto;
  }

  body.mobile-sidebar-open #sidebar {
    transform: translateX(0);
  }

  body.mobile-sidebar-open #sidebarBackdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.sidebar-collapsed #sidebar {
    padding: calc(env(safe-area-inset-top) + 14px) 14px calc(env(safe-area-inset-bottom) + 14px);
    border-right: 1px solid #222a3a;
    overflow: auto;
  }

  body.sidebar-collapsed #sidebar > * {
    display: block;
  }

  #canvasWrap {
    padding: calc(env(safe-area-inset-top) + 64px) 8px calc(env(safe-area-inset-bottom) + 84px);
  }

  canvas {
    border-radius: 14px;
  }

  .card {
    border-radius: 16px;
  }

  .tabRow {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .tabBtn,
  button,
  select,
  input {
    min-height: 44px;
    font-size: 16px;
  }

  #mobileMapControls {
    display: flex;
    position: fixed;
    right: 12px;
    bottom: max(12px, calc(env(safe-area-inset-bottom) + 8px));
  }

  #routeHoverTip {
    max-width: min(92vw, 420px);
    font-size: 15px;
    padding: 8px 12px;
    white-space: normal;
    text-align: center;
  }

  #legalQuizPanel {
    padding: calc(env(safe-area-inset-top) + 72px) 12px calc(env(safe-area-inset-bottom) + 14px);
  }

  .legalCrimeTitle {
    font-size: 24px;
  }

  .legalPrompt {
    font-size: 17px;
    line-height: 1.6;
  }
}
