/* theme-taipei101 style.css */
/* /theme-taipei101/style.css */

/* 1. global styles */
*, *::before, *::after {
    box-sizing: border-box;
}

#controls, #controls * {
    user-select: none;
    -webkit-user-select: none;
}

body {
    background: #1a1a1a;
    color: rgb(145, 145, 145);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: 100vh;
    /* height: 100dvh; */ 
    overflow: hidden;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* --- sidebar & menu button --- */
#menu-toggle {
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 2000; 
    background: #3b0202;
    border: 2px solid #d6d6d6;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    width: 36px;
    height: 36px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

#menu-toggle:hover {
    background: #680404; 
    border: 3px solid #c7c7c7;
    color: #c7c7c7;
    top: 14px;
    right: 14px;
    width: 40px;
    height: 40px;
}

#menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: #d6d6d6;
}

.zoomButton0 {
    position: fixed;
    top:80px;
    right: 15px;
    z-index: 2000; 
    background: #909090d3;
    border: 2px solid #000000;
    border-radius: 1px;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    cursor: pointer;

    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.zoomButton1 {
    position: fixed;
    top:116px;
    right: 15px;
    z-index: 2000; 
    background: #909090d3;
    border: 2px solid #000000;
    border-radius: 1px;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    cursor: pointer;

    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.zoomButton2 {
    position: fixed;
    top:156px;
    right: 15px;
    z-index: 2000; 
    background: #909090d3;
    border: 0px solid #000000;
    border-radius: 0px;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    cursor: pointer;

    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.zoomButton0:hover { 
    background: #787878e6; 
    border: 3px solid #000000;
}

.zoomButton1:hover { 
    background: #787878e6; 
    border: 3px solid #000000;
}

.zoomButton2:hover { 
    background: #787878e6; 
    border: 1px solid #000000;
}

.saveButton {
    position: fixed;
    top:196px;
    right: 15px;
    z-index: 2000; 
    background: #909090d3;
    border: 2px solid #000000;
    border-radius: 1px;
    width: 30px;
    height: 30px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    cursor: pointer;

    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.saveButton:hover { 
    background: #787878e6; 
    border: 3px solid #000000;
}

#sidebar {
    position: fixed;
    top: 0;
    right: -300px; 
    width: 180px;
    height: 100%;
    background: #f4f4f4;
    border-left: 3px solid #000000;
    box-shadow: -5px 0 15px rgba(0,0,0,0.5);
    z-index: 2001;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

#sidebar.open {
    right: 0;
}

.sidebar-header {
    background: #e8e8e8;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    margin: 0;
    font-size: 0.8rem;
    color: #000000;
}

#close-sidebar {
    background: transparent;
    border: none;
    color: #000000;
    font-size: 1rem;
    cursor: pointer;
}

.sidebar-content {
    padding: 12px;
    overflow-y: auto;
}

.menu-item {
    display: block;
    width: 100%;
    background: #fcfcfc;
    color: #000000;
    border: 2px solid #cccccc;
    padding: 8px;
    margin-bottom: 8px;
    text-align: left;
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 600; 
}

.menu-item:hover { 
    background: #e0e0e0; 
    color: #000000; 
    border: 3px solid #cccccc;
}

#open-themes {
    position: relative;
    padding-right: 34px;
}

#open-themes svg {
    position: absolute;
    right: 7px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    pointer-events: none;
}

.ig-link {
    display: flex;
    align-items: center;
    gap: 3px;
    color: #000000; 
    text-decoration: none;
    font-size: 0.75rem;
    margin-top: 20px;
    transition: opacity 0.2s ease;
    line-height: 1;
}

.ig-link svg {
    height: 1.1em; 
    width: 1.1em;
    fill: currentColor; 
    display: block;
    flex-shrink: 0;
    padding-right: 1px;
    box-sizing: content-box;
}

.ig-link:hover {
    opacity: 0.5;
}

.yt-link {
    display: flex;
    align-items: center;
    gap: 3px;
    color: #000000; 
    text-decoration: none;
    font-size: 0.75rem;
    margin-top: 12px; 
    transition: opacity 0.2s ease;
    line-height: 1;
}

.yt-link svg {
    height: 1.1em;
    width: 1.1em;
    fill: currentColor; 
    display: block;
    flex-shrink: 0;
    padding-right: 1px;
    box-sizing: content-box;
}

.yt-link:hover {
    opacity: 0.5;
}

/* sidebar footer */
.sidebar-footer {
    margin-top: auto; /* Pushes the footer to the bottom of the flex container */
    padding: 10px;
    border-top: 1px solid #ddd;
    background: #e8e8e8;
}

.sidebar-footer p {
    margin: 0 0 6px 0;
    font-size: 0.5rem;
    color: #666;
    line-height: 1.4;
}

.sidebar-footer .copyright {
    font-size: 0.5rem;
    color: #000;
    font-weight: bold;
}

/* --- modals (hovered windows) --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-window {
    background: #f9f9f9;
    border: 5px solid #b4b4b4;
    padding: 20px;
    max-width: 300px;
    width: 90%;
    position: relative;
    color: #000000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}

.modal-window h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.1rem;
    color: #000000;
    text-transform: none;
}

/* This covers all (x) buttons in all modals */
.close-modal, 
#close-concept, 
#close-themes, 
#close-howtoplay, 
#close-projects, 
#close-about {
    position: absolute;
    top: 10px; 
    right: 10px;
    background: transparent; 
    border: none;
    color: #000000; 
    font-size: 1.5rem; 
    cursor: pointer;
    line-height: 1;
}

.close-modal:hover,
#close-concept:hover,
#close-themes:hover {
    opacity: 0.5;
}

.modal-body {
    line-height: 1.2;
    font-size: 0.8rem;
}

.modal-body p {
    margin: 0 0 10px 0;
}

.modal-body p:last-child {
    margin-bottom: 0;
}


#control-toggle {
    position: fixed;
    top: 135px;
    left: 3px;
    z-index: 2000; 
    background: #909090b2;
    border: 2px solid #000000;
    border-radius: 4px;
    width: 40px;
    height: 36px;
    min-width: 40px;
    min-height: 36px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

#control-toggle:hover {
    background: #d0d0d0; 
    border: 3px solid #000000;
    top: 134px;
    left: 3px;
    width: 48px;
    height: 40px;
}

#control-toggle svg {
    transform: scale(1.4);
    width: 20px; 
    height: 20px; 
    flex-shrink: 0; 
}


#controlBar {
    position: fixed;
    top: 15px;
    left: -300px;
    width: 170px;
    height: auto;
    max-height: 80vh; 
    background: #6c6c6c;

    border: 3px solid #000000;
    border-radius: 2px;
    z-index: 6001;
    transition: show 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

#controlBar.open {
    left: 15px;
}

#controlBar .sidebar-header {
    background: #6c6c6c;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

#controlBar .sidebar-header h3 {
    margin: 0;
    font-size: 0.8rem;
    color: #000000;
}

#close-controlBar {
    background: transparent;
    border: none;
    color: #000000;
    font-size: 1rem;
    cursor: pointer;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.controlBar-content {
    padding: 12px;
    overflow-y: auto;
    flex: 1;
}

/* Control groups inside the settings panel */
.control-group {
    margin-bottom: 12px;
}

.control-label {
    display: block;
    font-size: 0.65rem;
    color: #000000;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
    font-weight: 600;
}

.control-select {
    display: block;
    width: 100%;
    background: #a9a9a9;
    color: #000000;
    border: 2px solid #212121;
    padding: 6px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: 0;
    appearance: auto;
}

.control-select:hover {
    background: #e0e0e0;
    border-color: #d7d7d7;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.control-input {
    background: #b2b2b2;
    color: #000000;
    border: 2px solid #000000;
    padding: 6px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    width: 60px;
    border-radius: 0;
    flex-shrink: 0;
}

.control-input--full {
    width: 100%;
    display: block;
    box-sizing: border-box;
}

.control-x {
    color: #000000;
    font-size: 0.8rem;
    flex-shrink: 0;
}


#theme-toggle {
    position: fixed;
    top: 80px;
    left: 2px;
    z-index: 2000; 
    background: #909090b2;
    border: 2px solid #000000;
    border-radius: 4px;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

#theme-toggle:hover {
    background: #d0d0d0; 
    border: 3px solid #000000;
    color: #fff;
    top: 79px;
    left: 2px;
    width: 48px;
    height: 44px;
}

#theme-toggle svg {
    transform: scale(1.3);
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.theme-header {
    background: #bfbfbf;
    padding: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative; 
}

.theme-header h3 {
    margin: 0;
    font-size: 0.8rem;
    color: #000000;
}

#themeSelectPanel {
    position: fixed;
    top: 15px;
    left: -300px;
    width: 220px;
    height: auto;
    max-height: 80vh;
    background: #bfbfbf;

    border: 3px solid #ffffff; 
    border-radius: 2px;

    z-index: 6001;
    transition: show 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
}

#themeSelectPanel.open {
    left: 15px;
}

#close-themeSelectPanel {
    background: transparent;
    border: none;
    color: #000000;
    font-size: 1rem;
    cursor: pointer;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

.theme-tile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 12px;
}

.theme-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    background: #c0c0c0;
    border: none;
    padding: 6px 6px 4px 6px;
    box-shadow:
        inset -2px -2px 0 #808080,
        inset 2px 2px 0 #ffffff;
    transition: filter 0.15s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.theme-tile:hover:not(.current-theme) {
    filter: brightness(0.6);
}

.theme-tile:active:not(.current-theme) {
    box-shadow:
        inset 2px 2px 0 #808080,
        inset -1px -1px 0 #ffffff;
}

.theme-tile.current-theme {
    filter: brightness(0.65);
    cursor: default;
    pointer-events: none;
    box-shadow:
        inset 1px 1px 0 #808080;
}

.theme-preview {
    width: 80px;
    height: 80px;
    image-rendering: pixelated;
    display: block;
}

.theme-tile-label {
    margin-top: 5px;
    font-size: 0.6rem;
    font-weight: 700;
    color: #000000;
    text-align: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.2;
}


/* 2. top controls */
#controls {
    padding: 10px;
    background: #4F0D09;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    border-bottom: 0px solid #7c5959;
    flex-wrap: wrap;
    align-content: center; 
    box-sizing: border-box;
    /* z-index: 20; */
    flex-shrink: 0;
}

.faceEmoji {
    position: flex;
    background: #c0c0c0; 
    border: 2px solid #000000;
    border-radius: 1px;
    width: 35px;
    height: 34px;
    margin: 0 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    padding: 0;
    cursor: pointer;

    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.faceEmoji:hover { 
    background: rgb(133, 133, 133); 
    border: 2.5px solid #000000;
}

.faceEmoji svg {
    pointer-events: none;
}

#mineDisplay, #timeDisplay {
    min-width: 80px; /* Ensures both sides have equal 'weight' */
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px; 
}

button {
    background: #000000;
    color: rgb(212, 196, 183);
    border: 1px solid #d4c4b7;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 1px;
    transition: background 0.2s, color 0.2s;
    font-weight: normal;
    font-size: 0.7rem;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;

    width: auto;
    flex-grow: 0;
    flex-shrink: 0;
}

button:hover { 
    background: #444; 
    color: #fff;
}


/* 3. game viewport */
#canvas-container {
    flex: 1; 
    width: 100%;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    display: block;
    text-align: center;
    scroll-behavior: smooth;
    /* Default dark bg before sky class is applied */
    background: #1a2a3a;
}

/* 4. SKY BACKGROUNDS
   Base sky is set on .taipei-sky.
   Sky variant classes OVERRIDE it with !important.
   Ground-color classes are nested inside sky class below.
*/
#canvas-container.taipei-sky {
    background: linear-gradient(to bottom, #c6e4ff 0%, #cdf7ff 100%);
    background-attachment: fixed;
    position: relative;
    z-index: 1;
    transition: background 0.5s ease;
}

.sky-day    { background: linear-gradient(to bottom, #c6e4ff 0%, #cdf7ff 100%) !important; }
.sky-sunset { background: linear-gradient(to bottom, #e88181 0%, #ffa276 100%) !important; }
.sky-dusk   { background: linear-gradient(to bottom, #ffb347 0%, #cd5d03 100%) !important; }
.sky-night  { background: linear-gradient(to bottom, #050a1e 0%, #141e50 70%, #c05c05 100%) !important; }
.sky-dawn   { background: linear-gradient(to bottom, #110932 0%, #2e1957 10%, #31125c 35%, #d24d19 85%, #efa80e 100%) !important; }

/* 5. CLOUDS — attached to the base .taipei-sky class */
#canvas-container.taipei-sky::before {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 400%; height: 100%;
    background-image:
        radial-gradient(ellipse 15% 6% at 10% 20%, rgba(255,255,255,0.8) 40%, transparent 100%),
        radial-gradient(ellipse 20% 8% at 60% 40%, rgba(255,255,255,0.6) 35%, transparent 100%),
        radial-gradient(ellipse 18% 7% at 35% 70%, rgba(255,255,255,0.5) 30%, transparent 100%);
    background-size: 25% 100%;
    mix-blend-mode: soft-light;
    pointer-events: none;
    /* z-index MUST be below 10 (canvas) so it doesn't block clicks */
    z-index: 3;
    filter: blur(8px);
    animation: moveClouds 150s linear infinite;
    transition: opacity 0.5s ease, filter 0.5s ease;
}

@keyframes moveClouds {
    from { transform: translateX(0); }
    to   { transform: translateX(-50%); }
}

/* Cloud appearance per sky */
.sky-day::before    { opacity: 0.6; filter: blur(10px) brightness(1.5); }
.sky-sunset::before { opacity: 0.7; filter: blur(50px) brightness(1.2) sepia(0.4); }
.sky-dusk::before   { opacity: 0.3; filter: blur(50px) brightness(1.3) sepia(0.2); }
.sky-night::before  { opacity: 0.1; filter: blur(15px) brightness(0.2); }
.sky-dawn::before   { opacity: 0; filter: blur(11px) brightness(1.1) hue-rotate(20deg); }

/* 6. ATMOSPHERE OVERLAY — must NOT intercept pointer events */
.sky-day::after,
.sky-sunset::after,
.sky-dusk::after,
.sky-night::after,
.sky-dawn::after {
    content: "";
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none; /* CRITICAL: never block canvas clicks */
    /* z-index 9 = below canvas (10) but above clouds (3) */
    z-index: 9;
    transition: background 0.5s ease;
}

.sky-day::after    { background: transparent; }
.sky-sunset::after { background: transparent; }
.sky-dusk::after   { background: rgba(255, 210, 100, 0.2); }
.sky-night::after  { background: rgba(20, 30, 80, 0.4); }
.sky-dawn::after   { background: rgba(180, 170, 230, 0.2); }

/* 7. CANVAS — THE BUILDING
   Key fix: use height-based sizing to preserve aspect ratio.
   The canvas pixel dimensions are 960px wide × 5400px tall (80col × 450row × 12px).
   We display it at a fixed height so the narrow tower stays tall and thin.
*/
#canvas-container canvas {
    display: block;
    margin: 80px auto 0 auto; /* top gap shows sky above spire */
    image-rendering: pixelated;
    image-rendering: crisp-edges; /* Firefox */
    position: relative;
    z-index: 10; /* above clouds(3) and overlay(9), below road(11) */
    background: transparent !important;
    touch-action: auto;
    user-select: none;
    transform-origin: bottom center;
    transition: height 0.4s ease-out, margin-top 0.4s ease-out;

    /* Correct sizing: tall canvas, scale by height, let width be auto */
    height: 68vh;
    width: auto;
}

#canvas-container canvas.zoomed {
    /* handle the specific width/height in JS to ensure it matches dynamic grid size */
    margin-top: 40px; 
    margin-bottom: 100px;
}

/* Building tint per sky */
.sky-day    canvas { filter: brightness(1)   saturate(1); }
.sky-sunset canvas { filter: brightness(0.8) saturate(1.2) sepia(0.2); }
.sky-dusk   canvas { filter: brightness(0.8) saturate(1) sepia(0.1); }
.sky-night  canvas { filter: brightness(0.5) saturate(0.6); }
.sky-dawn   canvas { filter: brightness(0.7) saturate(0.8); }

/* 8. ROAD / GROUND */
#taipei-ground {
    display: none;
    height: 120px;
    position: relative;
    z-index: 11;
    margin: -1px auto 0 auto;
    min-width: 100vw;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    transition: background 0.3s ease, height 0.4s ease;
}

/* Ground color per sky */
.sky-day    #taipei-ground { background: #3e3e3e; }
.sky-sunset #taipei-ground { background: #473a3a; }
.sky-dusk   #taipei-ground { background: #393326; }
.sky-night  #taipei-ground { background: #0a0a12; }
.sky-dawn   #taipei-ground { background: #1d1d24; }

/* Show road only in taipei-sky mode */
#canvas-container.taipei-sky #taipei-ground {
    display: block;
}

#canvas-container.full-view #taipei-ground {
    height: 80px;
}

/* Road lane lines */
.road-markings {
    position: absolute;
    top: 0; left: 0;
    height: 100%; width: 5000px;
    background-image:
        linear-gradient(90deg, #fff 50%, transparent 50%),
        linear-gradient(90deg, #fff 50%, transparent 50%);
    background-repeat: repeat-x;
    background-size: 60px 2px;
    background-position: 0 26%, 0 56%;
    -webkit-mask-image: linear-gradient(to right,
        black 4130px,
        transparent 4130px,
        transparent 4425px,
        black 4425px
    );
    mask-image: linear-gradient(to right,
        black 4130px,
        transparent 4130px,
        transparent 4425px,
        black 4425px
    );
}

.road-markings::after {
    content: "";
    position: absolute;
    top: 88%; left: 0; height: 4px; width: 5000px;
    border-top: 2.5px solid #ffcc00;
    border-bottom: 2.5px solid #ffcc00;
}

.lane-1 { top: 11%; }
.lane-2 { top: 40%; }
.lane-3 { top: 71%; }

.road-name, .road-arrow {
    position: absolute;
    font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
    white-space: nowrap;
    z-index: 15;
    transform: translateY(-50%);
}

.road-arrow {
    opacity: 0.8;
}

.road-arrow span {
    display: inline-block;
    font-size: 1rem;
    color: #fff;
    transform: rotate(180deg) scaleX(4) scaleY(0.7);
    transform-origin: center;
}

.road-name span {
    display: inline-block;
    color: rgba(255, 255, 255, 0.4);
    transform: rotate(-90deg) scaleY(4.5);
    transform-origin: center;
    margin-right: 4.5rem;
    font-size: 0.8rem;
}

.lane-3.road-name span {
    color: rgba(231, 190, 26, 0.8);
}

#canvas-container.full-view #taipei-ground .road-name span { font-size: 0.6rem; }

.name-pos-1       { left: 200px; }
.arrow-split-pos  { left: 3600px; }
.arrow-pos-1      { left: 3600px; }
.name-pos-2       { left: 1600px; }
.arrow-pos-2      { left: 3600px; }

.road-speed {
    position: absolute;
    z-index: 15;
    transform: translateY(-50%);
}

.road-speed span {
    display: inline-block;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-weight: 700;
    font-size: 0.6rem;
    color: rgba(231, 190, 26, 0.7);
    transform: rotate(-90deg) scaleY(6.5);
    transform-origin: center;
    white-space: nowrap;
}

.speed-pos { left: 3400px; }

/* Zebra crossing */
.zebra-crossing.horizontal-zebra {
    position: absolute;
    top: 0;
    left: 4340px;
    height: 100%;
    width: 52px;
    z-index: 11;
    background-image: linear-gradient(
        to bottom,
        rgba(255,255,255,0.99) 0%,
        rgba(255,255,255,0.99) 50%,
        transparent 50%,
        transparent 100%
    );
    background-size: 100% 7px;
    opacity: 0.9;
    transition: width 0.3s ease, left 0.3s ease;
}

#canvas-container.full-view .zebra-crossing.horizontal-zebra {
    width: 32px;
    left: 4370px;
}

.stop-line {
    position: absolute;
    top: 0;
    left: 4425px;
    height: 100%;
    width: 4px;
    background: rgba(255,255,255,0.8);
    z-index: 11;
}

/* 9. VEHICLES */
.vehicle {
    position: absolute;
    font-size: 1.2rem;
    z-index: 25;
    transform: translateY(-50%);
    pointer-events: none;
    will-change: left;
}

.lane1-pos { top: 11%; }
.lane2-pos { top: 40%; }
.lane3-pos { top: 71%; }

.truck-2 { font-size: 1rem; top: 12%; }

.race-1    { animation: driveLeft 15s  linear infinite; }
.truck-1   { animation: driveLeft 45s  linear infinite; animation-delay: -10s; }
.car-1     { animation: driveLeft 35s  linear infinite; animation-delay: -20s; }
.suv-1     { animation: driveLeft 38s  linear infinite; animation-delay: -5s; }
.taxi-1    { animation: driveLeft 32s  linear infinite; animation-delay: -15s; }
.scooter-1 { animation: driveLeft 42s  linear infinite; animation-delay: -2s; }
.scooter-2 { animation: driveLeft 40s  linear infinite; animation-delay: -25s; }
.truck-2   { animation: driveLeft 80s  linear infinite; animation-delay: -12s; }

@keyframes driveLeft {
    from { left: 5200px; }
    to   { left: -200px; }
}

#canvas-container.full-view .vehicle { font-size: 0.8rem; }

/* 10. PEDESTRIANS */
.pedestrian-wrapper {
    position: absolute;
    left: 4345px;
    top: 0;
    height: 100%;
    width: 40px;
    z-index: 12;
    pointer-events: none;
    transition: left 0.3s ease;
}

#canvas-container.full-view .pedestrian-wrapper {
    left: 4368px;
}

.pedestrian {
    position: absolute;
    font-size: 0.9rem;
    will-change: top;
}

.p1 { animation: walkDown 12s linear infinite; left: 0px; }
.p2 { animation: walkUp   8s linear infinite; left: 20px; animation-delay: -2s; }
.p3 { animation: walkDown 15s linear infinite; left: 10px; animation-delay: -5s; }
.p4 { animation: walkUp   10s linear infinite; left: 5px;  animation-delay: -7s; }

@keyframes walkDown {
    from { top: -20%; opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    to   { top: 120%; opacity: 0; }
}

@keyframes walkUp {
    from { top: 120%; opacity: 0; }
    10%  { opacity: 1; }
    90%  { opacity: 1; }
    to   { top: -20%; opacity: 0; }
}

/* ── cassette / FM radio ── */
#radioPlayer {
    position: fixed;
    bottom: -220px;
    left: -36px;
    width: fit-content;
    height: fit-content;
    overflow: visible;
    font-family: sans-serif;
    user-select: none;
    -webkit-touch-callout: none;
    z-index: 5000;
    cursor: default;
    pointer-events: none;
    will-change: transform; /* promotes to compositor layer — prevents full-page repaints on drag */
}

#bb-drag-handle {
    position: absolute;
    top: -10px;
    right: 22%;
    width: 54%;
    height: 30px;
    background: #4b1e1c;
    border: 3px solid #3c0706; 
    
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #bca990;
    cursor: grab;
    z-index: 10;
    transition: background 0.15s, color 0.15s;
}

#bb-drag-handle:hover {
    background: #6a2926;
    color: #bca990;
}

#bb-drag-handle:active {
    cursor: grabbing;
    background: #6a2926;
    color: #3c0706;
}

/* OUTER SHELL */
.bb-shell {
    background: linear-gradient(160deg, #d4c0a8 0%, #bca990 35%, #a89278 70%, #c8b49a 100%);
    box-shadow: 
        4px 8px 16px 4px rgba(0,0,0,0.7),
        inset 0 1px 0 rgba(255,255,255,0.7),
        inset 0 -2px 4px rgba(0,0,0,0.3);
    border-top: none; 
    border-radius: 18px 18px 12px 12px;
    padding: 0 0 7px 0;
    position: relative;
    width: 100%;
    overflow: visible;
    transform: scale(0.741);
    transform-origin: top left;
    pointer-events: auto;
    contain: layout style; /* internal changes don't trigger recalc on the rest of the document */
}

.bb-antenna {
    position: absolute;
    left: 44px;
    top: -49px;
    width: 5px;
    height: 58px;
    background: linear-gradient(to right, #b7b7b7, #727272, #a9a9a9);
    border-radius: 3px 3px 2px 2px;
    transform-origin: bottom center;
    transform: rotate(30deg);
    z-index: 4999;
    pointer-events: none;
}
.bb-antenna::before {
    /* base ball joint */
    content: '';
    position: absolute;
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #a0a0a0, #5e5e5e);
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.bb-antenna::after {
    /* tip ball */
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #a9a9a9, #6e6e6e);
}


/* KNOBS ROW */
.bb-knobs {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 5px 14px 4px;
}
.bb-knob {
    width: 8px;
    height: 12px;
    background: linear-gradient(to bottom, #ffdea5, #937541);
    border-radius: 3px;
    box-shadow: 0px 1px 4px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
    cursor: pointer;
    transition: transform 0.1s;
}

.bb-knob:active { transform: scaleY(0.9); }
.bb-knob-group { display: flex; gap: 5px; }

.bb-knob-small {
    width: 7px;
    height: 10px;
    background: linear-gradient(to bottom, #ffdea5, #937541);
    border-radius: 2px;
    box-shadow: 0px 0px 2px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
}
.bb-knob-small:hover { transform: scaleY(0.9); }

.bb-knob-group-right { display: flex; gap: 4px; align-items: flex-end; }

.bb-knob.bb-knob-power {
    width: 16px;
    height: 15px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1px 1px 0;
    overflow: hidden;
}
.bb-knob.bb-knob-power svg {
    width: 12px;
    height: 12px;
    display: block;
    fill: #6b4e1a;
    padding-bottom: 1px; 
}

/* TOP RED SECTION */
.bb-top {
    background: #6a2926;
    border: 1px solid #472624; 
    margin: 0 8px;
    border-radius: 4px;
    padding: 3px;
    display: flex;
    gap: 6px;
    align-items: stretch;
}

/* Tuner/radio strip */
.bb-tuner {
    flex: 1;
    background: #111;
    border-radius: 3px;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 3px 4px;
    cursor: grab;
}
.bb-tuner-stripe {
    height: 7px;
    background: repeating-linear-gradient(to right, #2a2a2a 0px, #2a2a2a 8px, #1a1a1a 8px, #1a1a1a 10px);
    border-radius: 1px;
}
.bb-tuner-needle {
    position: absolute;
    top: 0; bottom: 0;
    left: 55%;
    width: 4px;
    background: rgb(224, 22, 0);
    cursor: grab;
    z-index: 5;
    user-select: none;
    touch-action: none;
    box-shadow: 0 0 8px rgba(224, 80, 0, 3.9);
}
.bb-tuner-needle:active { cursor: grabbing; }

.bb-tuner-tick {
    position: absolute;
    top: 2px; bottom: 2px;
    width: 1px;
    background: rgba(255, 200, 80, 0.35);
    pointer-events: none;
    transition: background 0.2s;
}
.bb-tuner-tick.active {
    background: rgba(255, 200, 80, 0.9);
    box-shadow: 0 0 3px rgba(255,200,80,0.6);
}

/* MAIN BODY */
.bb-body {
    background-color: rgb(89, 21, 19);
    background-image: radial-gradient(rgba(0,0,0,0.2) 1px, transparent 2px);
    background-size: 2.5px 4px;
    margin: 4px 8px 0;
    border-radius: 4px;
    border: 2px solid #270e0e; 
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.4), inset 0 -1px 3px rgba(0,0,0,0.3);
    padding: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Large speakers */
.bb-speaker {
    width: 78px;
    height: 78px;
    flex-shrink: 0;
    border-radius: 50%;
    box-shadow: 
        inset 0 3px 6px rgba(0,0,0,0.6),
        0 2px 4px rgba(255,255,255,0.08);
    background: radial-gradient(circle at center, #2a2a2a 0%, #380000 65%, #000 100%);
    display: grid;
    place-items: center;
}

.bb-speaker-inner {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at 45% 40%, #000000 0%, #2e2e2e 45%, #2a2a2a 85%, #000000 100%);
    display: grid;
    place-items: center;
    border: 3px solid #1a1a1a;
    box-shadow: inset 0 2px 8px rgba(0,0,0,0.25);
}

.bb-speaker-center {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 30%, #3a3a3a 0%, #2e2e2e 50%, rgb(59, 59, 59) 100%);
    border: 1px solid #1e1e1e;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}

.bb-speaker-center:active {
    background: radial-gradient(circle at 60% 70%, #3a3a3a 0%, #2e2e2e 50%, rgb(59, 59, 59) 100%);
    border: 0;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.7), inset 0 1px 2px rgba(0,0,0,0.5);
    cursor: pointer;
}

/* CENTER CONTROLS */
.bb-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Cassette / iframe area */
.bb-cassette {
    background: #390000;
    border-radius: 4px;
    border: 2px solid #310000;
    overflow: hidden;
    width: 150px;
    height: 150px;
    display: flex;
    align-items: stretch;
    justify-content: center;
    position: relative;
}
.bb-cassette iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
.bb-cassette-panel {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.bb-cassette-panel iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}
/* height = cassette_height / scale, width = 100% / scale */
#bb-radio-iframe {
    position: absolute;
    top: -4px; left: -1px;
    width: 110%;
    height: 185px;
    transform: scale(0.92);
    transform-origin: top left;
    border: 0;
}
.bb-station-display {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
}
.bb-station-lcd {
    background: #140908;
    border: 1px solid #3a1d19eb;
    border-radius: 3px;
    width: 100%;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    box-shadow: inset 0 0 12px rgba(0,0,0,0.6);
}
.bb-station-name {
    color: #e8a840;
    font-family: 'Courier New', monospace;
    font-size: 0.65rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    text-align: center;
    text-shadow: 0 0 6px rgba(212,170,48,0.5);
    text-transform: uppercase;
}
.bb-station-freq {
    color: #e8b640;
    font-family: 'Courier New', monospace;
    font-size: 1.4rem;
    font-weight: bold;
    letter-spacing: 0.1em;
    text-shadow: 0 0 10px rgba(232,200,64,0.7);
}
.bb-station-status {
    color: #7a6010;
    font-family: 'Courier New', monospace;
    font-size: 0.55rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.bb-station-status.playing  { color: #90b840; text-shadow: 0 0 4px rgba(144,184,64,0.5); }
.bb-station-status.buffering { color: #d4aa30; }
.bb-station-status.error    { color: #c04020; }

/* Dial glows orange when in radio mode */
#bb-mode-dial.radio-mode {
    box-shadow: 0 0 6px rgba(224, 80, 0, 0.7);
    background: radial-gradient(circle at 35% 35%, #f0c080, #c07030);
    transform: rotate(36deg);
}
#bb-mode-dial.radio-mode:active {transform: rotate(110deg);}


/* BOTTOM RED STRIP */
.bb-bottom {
    background: rgb(102, 25, 21);
    border: 2px solid #321c1c; 
    margin: 4px 8px 0;
    border-radius: 3px;
    box-shadow: inset 0 2px 3px rgba(0,0,0,0.3), 0 1px 0 rgba(255,255,255,0.6);
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Round buttons */
.bb-roundbtn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid rgba(0, 0, 0, 0.4);
    box-shadow: 
        0 3px 5px rgba(0,0,0,0.5),
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 -1px 2px rgba(0,0,0,0.3);
    transition: filter 0.1s, transform 0.1s;
    flex-shrink: 0;
}
.bb-roundbtn:active { 
    transform: scale(0.98); 
    filter: brightness(0.9); 
    border: 3px solid rgba(0, 0, 0, 0.4);
    box-shadow: 
        0 2px 2px rgba(0,0,0,0.4),
        inset 0 1px 0 rgba(255,255,255,0.3),
        inset 0 -1px 2px rgba(0,0,0,0.3);
}
.bb-roundbtn.yellow  { background: radial-gradient(circle at 35% 35%, #ded0ad, #fde5a7); }
.bb-roundbtn.yellow.big { width: 30px; height: 30px; }

.bb-roundbtn svg {
    width: 100%;
    height: 100%;
    display: block;
    margin: auto;
    pointer-events: none;
}

/* Square buttons */
.bb-sqbtn-group { display: flex; gap: 2px; }
.bb-sqbtn {
    width: 28px;
    height: 27px;
    border-radius: 1px;
    cursor: pointer;
    border: 2px solid rgba(0,0,0,0.4);
    transition: filter 0.1s;
}
.bb-sqbtn:active { filter: brightness(0.8); }
.bb-sqbtn.sq-yellow { background: #f0b800; }
.bb-sqbtn.sq-blue   { background: #2196c9; }
.bb-sqbtn.sq-red    { background: #e74c3c; }

.bb-sqbtn:hover {filter: brightness(1.3);}

/* Big dial knob */
.bb-dial {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%, #fff6da, #928464);
    border: 2px solid rgba(0,0,0,0.5);
    cursor: pointer;
    position: relative;
    margin-left: auto;
    flex-shrink: 0;
    transition: transform 0.2s;
}
.bb-dial::after {
    content: '';
    position: absolute;
    top: 3px; left: 50%;
    transform: translateX(-50%);
    width: 3px;
    height: 10px;
    background: rgba(0,0,0,0.5);
    border-radius: 2px;
}
.bb-dial:active { transform: rotate(80deg); }

/* spacer */
.bb-sp { flex: 1; }

/* 12. MOBILE */
@media (max-width: 768px) {
    #controls { 
        padding: 8px 5px; 
        gap: 8px; 
        justify-content: center; /* Ensures items stay centered */
    }
    
    .input-group label { display: none; }

    button { 
        padding: 8px 10px; 
        /* FIXED: Changed flex-grow from 1 to 0 and removed max-width */
        flex-grow: 0; 
        width: auto;
        max-width: none; 
    }
    
    #canvas-container canvas { height: auto; }
}

@media (max-width: 500px) {
    #radioPlayer {
        bottom: -200px;
        left: -100px;
    }
}

/* ── end game pop-up ── */
.end-popup-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    pointer-events: none;
}

.end-popup-window {
    pointer-events: all;
    width: 180px;
    background: #ece9d8;
    border: 1px solid #0a246a;
    box-shadow: inset 0 0 0 1px #a4b4d4, 3px 3px 8px rgba(0,0,0,0.5);
    font-family: Tahoma, 'MS Sans Serif', Arial, sans-serif;
    animation: popup-drop 0.15s cubic-bezier(.22,.68,0,1.15) both;
}

@keyframes popup-drop {
    from { transform: translateY(-14px) scale(0.95); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ── Title bar ── */
.end-popup-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 3px 4px 3px 6px;
    background: linear-gradient(to bottom, #0f4ece 0%, #3a7bd5 40%, #245fcc 60%, #1a52c2 100%);
    border-bottom: 1px solid #0a246a;
    user-select: none;
}

.end-popup-titlebar-left {
    display: flex;
    align-items: center;
    gap: 5px;
}

.end-popup-titlebar-icon {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.end-popup-title {
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    letter-spacing: 0;
}

/* ── X button ── */
.end-popup-close {
    width: 21px;
    height: 21px;
    font-size: 10px;
    line-height: 1;
    color: #000;
    background: linear-gradient(to bottom, #f0f0ea, #d4d0c8);
    border: 1px solid #888;
    border-top-color: #fff;
    border-left-color: #fff;
    box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #888;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Marlett, 'Courier New', monospace;
}
.end-popup-close:active {
    background: linear-gradient(to bottom, #d4d0c8, #f0f0ea);
    border-top-color: #888;
    border-left-color: #888;
    border-bottom-color: #fff;
    border-right-color: #fff;
}

/* ── Body ── */
.end-popup-body-wrap {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 18px 20px 14px 16px;
    background: #ece9d8;
}

.end-popup-icon {
    font-size: 2.2rem;
    line-height: 1;
    flex-shrink: 0;
    margin-top: 2px;
}

.end-popup-body {
    font-size: 11px;
    color: #000;
    line-height: 1.6;
    flex: 1;
}

.end-popup-body strong {
    display: block;
    font-size: 12px;
    margin-bottom: 5px;
}

.end-popup-body strong.is-gameover { color: #a00000; }
.end-popup-body strong.is-win      { color: #005500; }

/* ── Footer ── */
.end-popup-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 8px 16px 12px;
    gap: 8px;
    border-top: 1px solid #aca899;
    background: #ece9d8;
}

/* ── OK / New Game button ── */
.end-popup-btn {
    min-width: 75px;
    height: 23px;
    font-family: Tahoma, 'MS Sans Serif', Arial, sans-serif;
    font-size: 11px;
    color: #000;
    background: linear-gradient(to bottom, #f4f2ec, #dbd8cc);
    border: 1px solid #888;
    border-top-color: #fff;
    border-left-color: #fff;
    box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #888, 1px 1px 2px rgba(0,0,0,0.2);
    cursor: pointer;
    padding: 0 12px;
}

.end-popup-btn:hover {
    background: linear-gradient(to bottom, #f9f8f4, #e8e4d8);
}

.end-popup-btn:active {
    background: linear-gradient(to bottom, #dbd8cc, #f4f2ec);
    border-top-color: #888;
    border-left-color: #888;
    border-bottom-color: #fff;
    border-right-color: #fff;
    box-shadow: inset 1px 1px 0 #888;
    transform: translate(1px, 1px);
}