:root {
      --primary: #2563eb;
      --primary-hover: #1d4ed8;
      --accent: #f59e0b;
      --wood: #b45309;
      --wood-light: #d97706;
      --red-cadastral: #ef4444;
      --bg-dark: rgba(15, 23, 42, 0.88);
      --bg-card: rgba(30, 41, 59, 0.94);
      --text-main: #f8fafc;
      --text-muted: #94a3b8;
      --border: rgba(255, 255, 255, 0.12);
    }

    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      user-select: none;
      -webkit-font-smoothing: antialiased;
    }

    html, body {
      overflow: hidden;
      width: 100%;
      height: 100%;
      position: fixed;
      touch-action: manipulation;
      overscroll-behavior: none;
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
      background: #0f172a;
      color: var(--text-main);
    }

    #webgl-canvas {
      position: absolute;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      display: block;
      z-index: 1;
      touch-action: none;
      -webkit-touch-callout: none;
      -webkit-user-select: none;
      user-select: none;
    }

    /* Nowy elegancki nagłówek marki "Działka Jasińskich" */
    .brand-header {
      position: absolute;
      top: 20px;
      left: 20px;
      z-index: 10;
      background: rgba(15, 23, 42, 0.72);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      border: 1px solid rgba(255, 255, 255, 0.14);
      border-radius: 16px;
      padding: 14px 22px;
      box-shadow: 0 12px 32px -4px rgba(0, 0, 0, 0.55), inset 0 1px 1px rgba(255, 255, 255, 0.12);
      pointer-events: auto;
      user-select: none;
      transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .brand-header:hover {
      background: rgba(15, 23, 42, 0.88);
      border-color: rgba(245, 158, 11, 0.45);
      box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.65), 0 0 20px rgba(245, 158, 11, 0.18);
      transform: translateY(-1px);
    }

    .brand-title {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Playfair Display", Georgia, serif;
      font-size: 1.65rem;
      font-weight: 800;
      letter-spacing: -0.025em;
      background: linear-gradient(135deg, #ffffff 15%, #fde68a 60%, #f59e0b 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      line-height: 1.2;
    }

    .brand-subtitle {
      font-size: 0.74rem;
      font-weight: 600;
      color: #94a3b8;
      letter-spacing: 0.08em;
      text-transform: uppercase;
      margin-top: 5px;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .brand-subtitle::before {
      content: "";
      display: inline-block;
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #f59e0b;
      box-shadow: 0 0 8px #f59e0b;
    }

    /* Karta Kluczowych Parametrów Architektonicznych */
    .arch-info-grid {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 8px;
      margin-top: 6px;
    }

    .arch-info-card {
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-radius: 8px;
      padding: 8px 10px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      transition: all 0.2s ease;
    }

    .arch-info-card:hover {
      background: rgba(255, 255, 255, 0.08);
      border-color: rgba(255, 255, 255, 0.16);
    }

    .arch-info-card.highlight {
      border-color: rgba(56, 189, 248, 0.3);
      background: rgba(14, 116, 144, 0.12);
    }

    .arch-info-card.wood {
      border-color: rgba(245, 158, 11, 0.35);
      background: rgba(180, 83, 9, 0.12);
    }

    .arch-info-card.plot {
      border-color: rgba(239, 68, 68, 0.3);
      background: rgba(185, 28, 28, 0.08);
    }

    .arch-info-val {
      font-size: 0.88rem;
      font-weight: 700;
      color: #f8fafc;
      line-height: 1.2;
    }

    .arch-info-card.highlight .arch-info-val {
      color: #38bdf8;
    }

    .arch-info-card.wood .arch-info-val {
      color: #fbbf24;
    }

    .arch-info-card.plot .arch-info-val {
      color: #f87171;
    }

    .arch-info-lbl {
      font-size: 0.68rem;
      color: #94a3b8;
      line-height: 1.25;
    }

    /* Górny pasek nagłówkowy (legacy) */
    .top-bar {
      position: absolute;
      top: 16px;
      left: 16px;
      z-index: 10;
      background: var(--bg-dark);
      backdrop-filter: blur(12px);
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 12px 18px;
      box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
      pointer-events: auto;
      max-width: 650px;
    }

    .top-bar h1 {
      font-size: 1.15rem;
      font-weight: 700;
      display: flex;
      align-items: center;
      gap: 10px;
      letter-spacing: -0.01em;
    }

    .badge-sapphire {
      background: linear-gradient(135deg, #1e3a8a, #0284c7);
      color: #fff;
      font-size: 0.68rem;
      font-weight: 800;
      padding: 3px 8px;
      border-radius: 6px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      border: 1px solid rgba(255, 255, 255, 0.25);
    }

    .badge-plot {
      background: linear-gradient(135deg, #b91c1c, #ef4444);
      color: #fff;
      font-size: 0.68rem;
      font-weight: 800;
      padding: 3px 8px;
      border-radius: 6px;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      border: 1px solid rgba(255, 255, 255, 0.25);
    }

    .top-bar p {
      font-size: 0.8rem;
      color: var(--text-muted);
      margin-top: 4px;
    }

    .dims-summary {
      display: flex;
      gap: 10px;
      margin-top: 8px;
      padding-top: 8px;
      border-top: 1px solid rgba(255, 255, 255, 0.08);
      font-size: 0.76rem;
      flex-wrap: wrap;
    }

    .dim-tag {
      background: rgba(255, 255, 255, 0.06);
      padding: 3px 8px;
      border-radius: 5px;
      border: 1px solid rgba(255, 255, 255, 0.08);
      color: #e2e8f0;
    }
    .dim-tag strong {
      color: #38bdf8;
    }
    .dim-tag.wood strong {
      color: #fbbf24;
    }
    .dim-tag.plot strong {
      color: #f87171;
    }

    /* Prawy panel nawigacji i narzędzi */
    .controls-panel {
      position: absolute;
      top: 16px;
      right: 16px;
      width: 340px;
      max-height: calc(100vh - 32px);
      background: var(--bg-dark);
      backdrop-filter: blur(14px);
      border: 1px solid var(--border);
      border-radius: 14px;
      z-index: 10;
      box-shadow: 0 20px 35px -10px rgba(0, 0, 0, 0.6);
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 12px;
      padding: 14px;
      pointer-events: auto;
    }

    .panel-section {
      background: rgba(255, 255, 255, 0.03);
      border: 1px solid rgba(255, 255, 255, 0.07);
      border-radius: 10px;
      padding: 10px;
    }

    .section-title {
      font-size: 0.74rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.06em;
      color: var(--text-muted);
      margin-bottom: 8px;
      display: flex;
      align-items: center;
      gap: 6px;
    }

    .btn-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 6px;
    }

    .btn-grid-3 {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 6px;
    }

    button.ctrl-btn {
      background: rgba(255, 255, 255, 0.08);
      color: var(--text-main);
      border: 1px solid rgba(255, 255, 255, 0.12);
      padding: 7px 8px;
      border-radius: 7px;
      font-size: 0.74rem;
      font-weight: 600;
      cursor: pointer;
      transition: all 0.15s ease;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 5px;
      text-align: center;
    }

    button.ctrl-btn:hover {
      background: var(--primary);
      border-color: var(--primary);
      transform: translateY(-1px);
    }

    button.ctrl-btn.active {
      background: var(--primary);
      border-color: #60a5fa;
      box-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
    }

    button.ctrl-btn.highlight {
      background: linear-gradient(135deg, #b45309, #d97706);
      border-color: #f59e0b;
    }
    button.ctrl-btn.highlight:hover {
      background: linear-gradient(135deg, #d97706, #f59e0b);
    }

    button.ctrl-btn.plot-btn {
      background: linear-gradient(135deg, #991b1b, #dc2626);
      border-color: #f87171;
    }

    .toggle-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 5px 0;
      font-size: 0.77rem;
      border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    }
    .toggle-row:last-child {
      border-bottom: none;
    }

    .switch {
      position: relative;
      display: inline-block;
      width: 36px;
      height: 20px;
    }

    .switch input {
      opacity: 0;
      width: 0;
      height: 0;
    }

    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: rgba(255, 255, 255, 0.2);
      transition: .2s;
      border-radius: 20px;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 14px;
      width: 14px;
      left: 3px;
      bottom: 3px;
      background-color: white;
      transition: .2s;
      border-radius: 50%;
    }

    input:checked + .slider {
      background-color: var(--primary);
    }
    input:checked + .slider.wood {
      background-color: var(--wood-light);
    }
    input:checked + .slider.red {
      background-color: var(--red-cadastral);
    }
    input:checked + .slider.green {
      background-color: #22c55e;
    }
    input:checked + .slider.blue {
      background-color: #0284c7;
    }

    input:checked + .slider:before {
      transform: translateX(16px);
    }

    .slider-group {
      margin-top: 8px;
    }
    .slider-label {
      display: flex;
      justify-content: space-between;
      font-size: 0.72rem;
      color: var(--text-muted);
      margin-bottom: 3px;
    }
    .range-input {
      width: 100%;
      height: 4px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 2px;
      outline: none;
      -webkit-appearance: none;
    }
    .range-input::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 14px;
      height: 14px;
      border-radius: 50%;
      background: #38bdf8;
      cursor: pointer;
    }

    .dims-table {
      width: 100%;
      font-size: 0.73rem;
      border-collapse: collapse;
      margin-top: 4px;
    }
    .dims-table td {
      padding: 3px 0;
      border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }
    .dims-table td:last-child {
      text-align: right;
      font-weight: 600;
      color: #38bdf8;
    }
    .dims-table tr.highlight td:last-child {
      color: #fbbf24;
    }
    .dims-table tr.plot td:last-child {
      color: #f87171;
    }

    .bottom-bar {
      position: absolute;
      bottom: 16px;
      left: 16px;
      z-index: 10;
      background: var(--bg-dark);
      backdrop-filter: blur(10px);
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 6px 14px;
      display: flex;
      gap: 16px;
      font-size: 0.72rem;
      color: var(--text-muted);
      pointer-events: auto;
    }
    .key-tip {
      display: flex;
      align-items: center;
      gap: 6px;
    }
    .key-badge {
      background: rgba(255, 255, 255, 0.12);
      padding: 2px 5px;
      border-radius: 4px;
      font-weight: 700;
      color: var(--text-main);
      font-size: 0.65rem;
    }

    .compass-hud {
      position: absolute;
      bottom: 16px;
      right: 370px;
      z-index: 10;
      width: 70px;
      height: 70px;
      background: var(--bg-dark);
      border: 1px solid var(--border);
      border-radius: 50%;
      backdrop-filter: blur(10px);
      display: flex;
      align-items: center;
      justify-content: center;
      box-shadow: 0 4px 15px rgba(0,0,0,0.4);
      pointer-events: none;
    }
    .compass-dial {
      position: relative;
      width: 58px;
      height: 58px;
      border-radius: 50%;
      border: 1px dashed rgba(255, 255, 255, 0.2);
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform 0.1s linear;
    }
    .compass-arrow {
      position: absolute;
      width: 0;
      height: 0;
      border-left: 5px solid transparent;
      border-right: 5px solid transparent;
      border-bottom: 24px solid #ef4444;
      top: 5px;
    }
    .compass-arrow-south {
      position: absolute;
      width: 0;
      height: 0;
      border-left: 5px solid transparent;
      border-right: 5px solid transparent;
      border-top: 24px solid #94a3b8;
      bottom: 5px;
    }
    .compass-label-n {
      position: absolute;
      top: -2px;
      font-size: 0.65rem;
      font-weight: 800;
      color: #ef4444;
    }

    #tooltip-box {
      position: absolute;
      z-index: 50;
      background: var(--bg-card);
      border: 1px solid #38bdf8;
      border-radius: 8px;
      padding: 8px 12px;
      font-size: 0.76rem;
      color: #fff;
      pointer-events: none;
      display: none;
      box-shadow: 0 10px 20px rgba(0,0,0,0.5);
      transform: translate(-50%, -120%);
    }

    /* ==========================================================================
       RESPONSYWNOŚĆ I INTERFEJS MOBILNY (Smartfony, Tablety, Dotyk)
       ========================================================================== */

    /* Elementy mobilne - domyślnie ukryte na komputerach desktop */
    .mobile-toggle-btn,
    .mobile-backdrop,
    .drawer-header,
    .mobile-tip {
      display: none;
    }

    .desktop-only {
      display: flex;
    }

    /* RWD dla urządzeń mobilnych (smartfony, tablety w pionie oraz telefony w poziomie) */
    @media (max-width: 900px), (max-height: 550px) and (orientation: landscape) {
      .desktop-only {
        display: none !important;
      }

      .mobile-tip {
        display: block;
        color: #94a3b8;
        font-weight: 500;
      }

      /* Logo i nagłówek marki dostosowane do ekranów smartfonów */
      .brand-header {
        top: max(10px, env(safe-area-inset-top));
        left: 10px;
        right: auto;
        max-width: calc(100vw - 72px);
        padding: 8px 14px;
        border-radius: 12px;
      }

      .brand-title {
        font-size: 1.12rem;
        line-height: 1.2;
      }

      .brand-subtitle {
        font-size: 0.64rem;
        letter-spacing: 0.04em;
        margin-top: 3px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .brand-subtitle::before {
        width: 5px;
        height: 5px;
        min-width: 5px;
      }

      /* Kompas przeniesiony w prawy górny róg w wersji kompaktowej */
      .compass-hud {
        top: max(10px, env(safe-area-inset-top));
        right: 10px;
        bottom: auto;
        width: 44px;
        height: 44px;
        background: rgba(15, 23, 42, 0.75);
      }

      .compass-dial {
        width: 36px;
        height: 36px;
      }

      .compass-arrow {
        border-bottom-width: 15px;
        border-left-width: 4px;
        border-right-width: 4px;
        top: 3px;
      }

      .compass-arrow-south {
        border-top-width: 15px;
        border-left-width: 4px;
        border-right-width: 4px;
        bottom: 3px;
      }

      .compass-label-n {
        font-size: 0.58rem;
        top: -4px;
      }

      /* Dolna podpowiedź gestów dotykowych */
      .bottom-bar {
        bottom: max(12px, env(safe-area-inset-bottom));
        left: 50%;
        transform: translateX(-50%);
        padding: 5px 12px;
        font-size: 0.68rem;
        white-space: nowrap;
        border-radius: 20px;
        z-index: 15;
        background: rgba(15, 23, 42, 0.75);
      }

      /* Pływający przycisk otwierania panelu na telefonie */
      .mobile-toggle-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        bottom: max(44px, calc(16px + env(safe-area-inset-bottom)));
        left: 50%;
        transform: translateX(-50%);
        z-index: 25;
        background: rgba(15, 23, 42, 0.90);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border: 1.5px solid rgba(245, 158, 11, 0.55);
        box-shadow: 0 10px 28px -4px rgba(0, 0, 0, 0.7), 0 0 18px rgba(245, 158, 11, 0.25);
        border-radius: 9999px;
        padding: 10px 22px;
        color: #f8fafc;
        font-size: 0.88rem;
        font-weight: 700;
        cursor: pointer;
        transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
        -webkit-tap-highlight-color: transparent;
      }

      .mobile-toggle-btn:active {
        transform: translateX(-50%) scale(0.95);
        background: rgba(15, 23, 42, 0.98);
        border-color: rgba(245, 158, 11, 0.8);
      }

      .mobile-toggle-btn.mobile-open {
        opacity: 0;
        pointer-events: none;
        transform: translateX(-50%) translateY(25px);
      }

      .mobile-toggle-icon {
        font-size: 1.15rem;
      }

      /* Tło przyciemniające (backdrop) */
      .mobile-backdrop {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 28;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
      }

      .mobile-backdrop.mobile-open {
        opacity: 1;
        pointer-events: auto;
      }

      /* Mobilny panel jako wysuwany od dołu arkusz (Bottom Sheet Drawer) */
      .controls-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 80vh;
        border-radius: 24px 24px 0 0;
        border-bottom: none;
        border-left: none;
        border-right: none;
        border-top: 1px solid rgba(255, 255, 255, 0.2);
        box-shadow: 0 -14px 45px rgba(0, 0, 0, 0.85);
        z-index: 30;
        transform: translateY(105%);
        transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
        padding: 12px 18px calc(20px + env(safe-area-inset-bottom));
        gap: 12px;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
      }

      .controls-panel.mobile-open {
        transform: translateY(0);
      }

      /* Nagłówek panelu z uchwytem i przyciskiem zamknięcia */
      .drawer-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        padding-bottom: 6px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
      }

      .drawer-drag-handle {
        width: 44px;
        height: 5px;
        background: rgba(255, 255, 255, 0.28);
        border-radius: 4px;
      }

      .drawer-title-row {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }

      .drawer-title {
        font-size: 0.92rem;
        font-weight: 700;
        color: #f8fafc;
      }

      .drawer-close-btn {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.15);
        color: #e2e8f0;
        font-size: 1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
      }

      .drawer-close-btn:active {
        background: rgba(255, 255, 255, 0.25);
      }

      /* Powiększenie stref klikania (touch targets) na telefonach */
      .toggle-row {
        min-height: 42px;
        padding: 6px 0;
        font-size: 0.82rem;
      }

      .switch {
        width: 42px;
        height: 24px;
      }

      .slider:before {
        height: 18px;
        width: 18px;
        left: 3px;
        bottom: 3px;
      }

      input:checked + .slider:before {
        transform: translateX(18px);
      }

      button.ctrl-btn {
        min-height: 40px;
        font-size: 0.82rem;
      }
    }

    /* Tryb horyzontalny (Landscape) na smartfonach */
    @media (max-height: 550px) and (orientation: landscape) {
      .brand-header {
        top: max(6px, env(safe-area-inset-top));
        left: max(8px, env(safe-area-inset-left));
        padding: 6px 12px;
      }

      .brand-title {
        font-size: 0.95rem;
      }

      .brand-subtitle {
        display: none;
      }

      .mobile-toggle-btn {
        bottom: max(32px, calc(8px + env(safe-area-inset-bottom)));
        padding: 7px 16px;
        font-size: 0.8rem;
      }

      .bottom-bar {
        bottom: max(6px, env(safe-area-inset-bottom));
        padding: 3px 10px;
        font-size: 0.62rem;
      }

      .controls-panel {
        max-height: 90vh;
        padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
      }

      .arch-info-grid {
        grid-template-columns: repeat(3, 1fr);
      }
    }