/* TTC Streetcar Snake
 * --------------------
 * The game UI is intentionally CSS-only: layout responds to device capabilities
 * and the canvas handles the world rendering. Keep component styles near their
 * markup and responsive overrides together at the end of this file.
 */

  /* Global canvas and document behavior. */
  :root {
    --ttc-red: #d71920;
    --ink: #101114;
    --paper: #f1eee5;
    --hud: rgba(13, 15, 18, .91);
  }

  * { box-sizing: border-box; }
  html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: #e9e5db;
    touch-action: none;
    overscroll-behavior: none;
  }
  body {
    color: white;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    touch-action: none;
    overscroll-behavior: none;
    user-select: none;
  }

  #game {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    display: block;
    background: var(--paper);
    touch-action: none;
  }

  /* Persistent in-game HUD and network map. */
  .hud {
    position: fixed;
    z-index: 5;
    left: max(12px, env(safe-area-inset-left));
    top: max(12px, env(safe-area-inset-top));
    display: grid;
    grid-template-columns: repeat(5, auto);
    gap: 8px;
    pointer-events: none;
  }

  .brand, .stat, .tip {
    background: var(--hud);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 6px 20px rgba(0,0,0,.22);
    backdrop-filter: blur(8px);
  }

  .brand {
    grid-column: 1 / -1;
    max-width: min(660px, calc(100vw - 24px));
    padding: 10px 12px 9px;
    border-radius: 12px;
  }

  .brand .badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 43px;
    height: 30px;
    padding: 0 8px;
    margin-right: 8px;
    border: 2px solid #fff;
    border-radius: 5px;
    background: var(--ttc-red);
    font-size: 18px;
    font-weight: 900;
    vertical-align: 1px;
  }

  .brand strong { font-size: 18px; letter-spacing: -.02em; }
  .brand small { display: block; margin-top: 3px; color: #c8ccd2; font-size: 11px; line-height: 1.25; }

  .stat { min-width: 78px; padding: 8px 10px; border-radius: 10px; }
  .stat b { display: block; font-size: 18px; line-height: 1.1; }
  .stat span { display: block; margin-top: 2px; color: #aeb4bd; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }

  .tip {
    grid-column: 1 / -1;
    max-width: min(660px, calc(100vw - 24px));
    padding: 7px 10px;
    border-radius: 10px;
    color: #e9edf2;
    font-size: 11px;
  }

  /* Fixed map overview; JavaScript supplies its drawing contents. */
  #minimap {
    position: fixed;
    z-index: 4;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    width: min(29vw, 300px);
    height: min(19vw, 190px);
    min-width: 180px;
    min-height: 112px;
    border: 1px solid rgba(0,0,0,.22);
    border-radius: 13px;
    background: rgba(248,246,239,.95);
    box-shadow: 0 7px 24px rgba(0,0,0,.2);
    pointer-events: none;
  }

  .mini-label {
    position: fixed;
    z-index: 5;
    top: calc(max(12px, env(safe-area-inset-top)) + 7px);
    right: calc(max(12px, env(safe-area-inset-right)) + 9px);
    color: #4f555d;
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
    pointer-events: none;
  }

  /* Source panel is deliberately separate from the driving HUD. */
  #aboutBtn {
    position: fixed;
    z-index: 8;
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    appearance: none;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 999px;
    padding: 9px 12px;
    background: rgba(12,14,17,.84);
    color: white;
    font: 700 12px system-ui, sans-serif;
  }

  #aboutPanel {
    position: fixed;
    z-index: 30;
    left: max(14px, env(safe-area-inset-left));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px);
    display: none;
    width: min(530px, calc(100vw - 28px));
    max-height: min(66vh, 600px);
    overflow: auto;
    padding: 16px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 16px;
    background: rgba(17,19,23,.97);
    box-shadow: 0 16px 45px rgba(0,0,0,.36);
    font-size: 12px;
    line-height: 1.5;
  }
  #aboutPanel.open { display: block; }
  #aboutPanel h2 { margin: 0 0 7px; font-size: 17px; }
  #aboutPanel p { margin: 8px 0; color: #d4d7dc; }
  #aboutPanel a { color: #ffb9bc; }

  /* Start, resume, and game-over card. */
  #overlay {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(6,8,10,.50);
    backdrop-filter: blur(3px);
  }
  #overlay.hidden { display: none; }

  .card {
    width: min(570px, calc(100vw - 30px));
    padding: 22px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 20px;
    background: rgba(17,19,23,.97);
    box-shadow: 0 20px 60px rgba(0,0,0,.4);
  }
  .card h1 {
    margin: 5px 0 5px;
    font-size: clamp(30px, 7vw, 44px);
    line-height: .92;
    letter-spacing: -.045em;
  }
  .card p { margin: 7px 0; color: #d1d5dc; line-height: 1.4; font-size: 13px; }
  .card .big { color: white; font-size: 17px; font-weight: 800; }

  .start-kicker {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 8px;
    border-radius: 7px;
    background: var(--ttc-red);
    color: #fff;
    font: 900 9px/1 system-ui, sans-serif;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .start-kicker::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255,255,255,.22);
  }

  .toy-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 12px 0 8px;
    padding: 10px 12px;
    border-radius: 16px;
    background:
      linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.015)),
      repeating-linear-gradient(90deg, transparent 0 30px, rgba(255,255,255,.025) 30px 31px);
    border: 1px solid rgba(255,255,255,.10);
    overflow: hidden;
  }
  .toy-copy {
    min-width: 0;
    color: #fff;
    font: 900 clamp(15px, 3.5vw, 19px)/1.08 system-ui, sans-serif;
  }
  .toy-copy small {
    display: block;
    margin-top: 5px;
    color: #aeb4bc;
    font: 700 10px/1.2 system-ui, sans-serif;
  }
  .toy-car {
    position: relative;
    flex: 0 0 auto;
    width: 116px;
    height: 52px;
    border: 3px solid #f4f4f1;
    border-radius: 15px 15px 11px 11px;
    background: var(--ttc-red);
    box-shadow: 0 8px 18px rgba(0,0,0,.25);
  }
  .toy-car::before {
    content: "SNAKE";
    position: absolute;
    left: 30px;
    top: 5px;
    width: 56px;
    height: 12px;
    border-radius: 3px;
    background: #111;
    color: #ffb000;
    font: 900 7px/12px system-ui, sans-serif;
    text-align: center;
    letter-spacing: .08em;
  }
  .toy-car::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -7px;
    height: 9px;
    background:
      radial-gradient(circle at 8px 4px, #111 0 4px, transparent 4.5px),
      radial-gradient(circle at calc(100% - 8px) 4px, #111 0 4px, transparent 4.5px);
  }
  .toy-windows {
    position: absolute;
    left: 9px;
    right: 9px;
    top: 22px;
    height: 16px;
    border-radius: 5px;
    background:
      linear-gradient(90deg,
        #dbeafe 0 21%, transparent 21% 25%,
        #dbeafe 25% 46%, transparent 46% 50%,
        #dbeafe 50% 71%, transparent 71% 75%,
        #dbeafe 75% 100%);
  }

  .quick-rules {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 11px 0 2px;
  }
  .quick-rule {
    padding: 6px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,.07);
    border: 1px solid rgba(255,255,255,.10);
    color: #e7e9ed;
    font: 800 10px/1 system-ui, sans-serif;
  }
  .transit-joke {
    margin-top: 10px;
    color: #8f97a2;
    font: 700 9px/1.2 system-ui, sans-serif;
    text-align: center;
  }
  .card button {
    margin-top: 14px;
    border: 0;
    border-radius: 12px;
    padding: 12px 16px;
    background: var(--ttc-red);
    color: white;
    font: 800 15px system-ui, sans-serif;
    cursor: pointer;
  }
  #startBtn, #resumeBtn { width: 100%; }
  #resumeBtn {
    display: none;
    background: #087f5b;
  }
  #resumeBtn.show { display: block; }

  .mode-picker {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 14px;
  }
  .mode-field label {
    display: block;
    margin-bottom: 5px;
    color: #bfc5cc;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
  }
  .mode-field select {
    width: 100%;
    min-height: 44px;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 10px;
    padding: 0 10px;
    background: #292d33;
    color: #fff;
    font: 800 13px system-ui, sans-serif;
  }
  .sound-option {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    color: #d7dbe1;
    font-size: 12px;
    font-weight: 700;
  }
  .sound-option input {
    width: 18px;
    height: 18px;
    accent-color: var(--ttc-red);
  }

  /* Driving controls, route mission, and upcoming-switch UI. */
  #locationHud {
    grid-column: 1 / -1;
    max-width: min(660px, calc(100vw - 24px));
    padding: 7px 10px;
    border-radius: 10px;
    background: rgba(12,14,17,.90);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 6px 20px rgba(0,0,0,.22);
    color: #f3f4f6;
    font-size: 11px;
  }
  #locationHud strong { color: #fff; }
  .stop-diamond {
    display: inline-block;
    margin-right: 5px;
    color: #ff5a60;
    font-size: 9px;
    vertical-align: 1px;
  }

  #speedControls {
    position: fixed;
    z-index: 9;
    left: max(14px, env(safe-area-inset-left));
    bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px);
    display: grid;
    grid-template-columns: 92px 92px;
    gap: 8px;
  }
  .pedal {
    min-width: 108px;
    min-height: 62px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 14px;
    background: rgba(12,14,17,.88);
    color: white;
    box-shadow: 0 5px 16px rgba(0,0,0,.22);
    font: 900 14px/1.1 system-ui, sans-serif;
    touch-action: none;
  }
  .pedal small { display: block; margin-top: 4px; color: #adb5bd; font-size: 9px; letter-spacing: .06em; }
  .pedal:active, .pedal.active { transform: translateY(1px); }
  #accelerator.active { background: #087f5b; }
  #brake.active { background: #a61e24; }
  #missionHud {
    grid-column: 1 / -1;
    display: none;
    max-width: min(660px, calc(100vw - 24px));
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(12,14,17,.90);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 6px 20px rgba(0,0,0,.22);
  }
  #missionHud.show { display: flex; align-items: center; gap: 10px; }
  #missionRoute {
    min-width: 58px;
    padding: 4px 7px;
    border-radius: 6px;
    background: var(--ttc-red);
    color: #fff;
    text-align: center;
    font: 900 15px/1 system-ui, sans-serif;
  }
  #missionText { min-width: 0; }
  #missionText b { display: block; font-size: 12px; }
  #missionText span { display: block; margin-top: 2px; color: #bfc5cc; font-size: 10px; }

  #switchPanel {
    position: fixed;
    z-index: 9;
    left: 50%;
    bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    width: min(390px, calc(100vw - 220px));
    padding: 9px;
    border-radius: 14px;
    background: rgba(12,14,17,.90);
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 7px 24px rgba(0,0,0,.26);
  }
  #switchPanel[hidden] { display: none; }
  #switchTitle { font-size: 10px; color: #c8ccd2; text-transform: uppercase; letter-spacing: .08em; }
  #switchMeta { margin-top: 2px; font-size: 11px; font-weight: 800; color: #fff; }
  #switchChoices { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 6px; margin-top: 7px; }
  .switch-choice {
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 9px;
    padding: 8px 5px;
    background: #2a2e34;
    color: white;
    font: 800 10px/1 system-ui, sans-serif;
    touch-action: none;
  }
  .switch-choice.selected { background: #087f5b; }
  .switch-choice.blocked { opacity: .45; text-decoration: line-through; }

  /* Temporary disruptions and responsive layout rules. */
  #eventBanner {
    position: fixed;
    z-index: 10;
    left: 50%;
    top: max(12px, env(safe-area-inset-top));
    transform: translateX(-50%);
    max-width: min(520px, calc(100vw - 28px));
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(129,76,0,.94);
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: 0 6px 20px rgba(0,0,0,.23);
    color: white;
    font: 800 11px/1.2 system-ui, sans-serif;
    text-align: center;
  }
  #eventBanner[hidden] { display: none; }

  @media (max-width: 760px) {
    .hud {
      grid-template-columns: repeat(3, minmax(62px, auto));
      right: auto;
      gap: 5px;
    }
    .brand { min-height: 0; padding: 8px 10px; }
    .brand small { display: none; }
    .stat { min-width: 0; padding: 6px 9px; }
    .stat b { font-size: 16px; }
    #minimap { width: 150px; height: 88px; min-width: 0; min-height: 0; }
    #switchPanel { width: min(330px, calc(100vw - 190px)); }
  }

  /* Keyboard hints belong on keyboard-oriented layouts, not touch-first
     devices even when they happen to have a large display. */
  @media (hover: none), (pointer: coarse), (max-width: 760px) {
    .pedal small { display: none; }
  }

  @media (max-width: 540px) {
    /* Mobile is a separate cockpit, not a squeezed desktop HUD. */
    .hud {
      left: max(8px, env(safe-area-inset-left));
      top: max(8px, env(safe-area-inset-top));
      width: calc(100vw - 166px);
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 5px;
    }

    .brand {
      grid-column: 1 / -1;
      height: 46px;
      display: flex;
      align-items: center;
      white-space: nowrap;
      overflow: hidden;
    }
    .brand .badge {
      min-width: 34px;
      height: 26px;
      margin-right: 7px;
      padding: 0 5px;
      font-size: 15px;
    }
    .brand strong {
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 13px;
      letter-spacing: -.01em;
    }

    /* Keep only the information needed while driving. */
    .stat-cars, .stat-length { display: none; }
    .stat { height: 43px; }
    .stat b { font-size: 15px; }
    .stat span { margin-top: 1px; font-size: 7px; }
    .stat-speed b { color: #ffb8bb; }

    #locationHud {
      position: fixed;
      z-index: 6;
      left: max(8px, env(safe-area-inset-left));
      right: max(8px, env(safe-area-inset-right));
      top: calc(max(8px, env(safe-area-inset-top)) + 96px);
      width: auto;
      max-width: none;
      padding: 6px 9px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 9px;
      border-radius: 8px;
    }

    #minimap {
      top: max(8px, env(safe-area-inset-top));
      right: max(8px, env(safe-area-inset-right));
      left: auto;
      width: 150px;
      height: 94px;
      border-radius: 10px;
    }
    .mini-label {
      top: calc(max(8px, env(safe-area-inset-top)) + 5px);
      right: calc(max(8px, env(safe-area-inset-right)) + 7px);
      left: auto;
      font-size: 7px;
    }

    .tip { display: none; }

    #missionHud {
      position: fixed;
      z-index: 6;
      left: max(8px, env(safe-area-inset-left));
      right: max(8px, env(safe-area-inset-right));
      top: calc(max(8px, env(safe-area-inset-top)) + 126px);
      width: auto;
      max-width: none;
      padding: 5px 7px;
      border-radius: 8px;
    }
    #missionRoute { min-width: 46px; padding: 3px 5px; font-size: 12px; }
    #missionText b { font-size: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #missionText span { display: none; }

    #eventBanner {
      top: calc(max(8px, env(safe-area-inset-top)) + 170px);
      width: calc(100vw - 28px);
      max-width: none;
      padding: 7px 10px;
      border-radius: 10px;
      font-size: 9px;
      line-height: 1.25;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    }
    #eventBanner[hidden] { display: none; }

    #speedControls {
      left: 0;
      right: 0;
      bottom: max(10px, env(safe-area-inset-bottom));
      transform: none;
      display: block;
      pointer-events: none;
    }
    #speedControls .pedal {
      position: fixed;
      bottom: max(10px, env(safe-area-inset-bottom));
      width: 82px;
      min-width: 0;
      min-height: 58px;
      padding: 4px;
      border-radius: 16px;
      font-size: 11px;
      pointer-events: auto;
    }
    #brake { left: max(10px, env(safe-area-inset-left)); }
    #accelerator { right: max(10px, env(safe-area-inset-right)); }
    .pedal small { display: none; }


    #switchPanel {
      left: 102px;
      right: 102px;
      bottom: max(10px, env(safe-area-inset-bottom));
      width: auto;
      min-height: 58px;
      padding: 5px;
      transform: none;
      border-radius: 14px;
      display: flex;
      flex-direction: column;
      justify-content: center;
    }
    #switchPanel[hidden] { display: none; }
    #switchTitle { display: none; }
    #switchMeta {
      margin: 0 0 3px;
      font-size: 8px;
      text-align: center;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    #switchChoices { margin-top: 1px; gap: 3px; }
    .switch-choice {
      min-height: 38px;
      padding: 5px 2px;
      border-radius: 10px;
      font-size: 8px;
    }

    #aboutBtn { display: none; }

    .mode-picker { grid-template-columns: 1fr; }
    .card {
      width: min(420px, calc(100vw - 20px));
      padding: 17px;
      max-height: calc(100dvh - 28px);
      overflow: auto;
    }
    .card p { font-size: 12px; }
    .card .big { font-size: 16px; }
    .toy-wrap { padding: 9px 10px; margin-top: 10px; }
    .toy-car { width: 96px; height: 46px; }
    .toy-car::before { left: 24px; width: 48px; }
    .toy-windows { top: 21px; height: 13px; }
    .quick-rule { font-size: 9px; padding: 6px 7px; }
  }
