/* PixieWorld — kompis.fun/game */

    @import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;600&family=Inter:wght@300;400;500&display=swap');
    
    :root {
      --pw-bg: #1a1410;
      --pw-bg-panel: #1e1812;
      --pw-bg-surface: rgba(30, 24, 18, 0.98);
      --pw-bg-hover: rgba(255, 255, 255, 0.06);
      --pw-accent: #d4a24e;
      --pw-accent-rgb: 212, 162, 78;
      --pw-accent-dim: rgba(212, 162, 78, 0.15);
      --pw-accent-glow: rgba(212, 162, 78, 0.3);
      --pw-text: #ede4d4;
      --pw-text-dim: #d4cab8;
      --pw-text-muted: #b8a98e;
      --pw-text-faint: #8a7d6a;
      --pw-text-ghost: #6b5f4e;
      --pw-border: rgba(255, 255, 255, 0.08);
      --pw-border-accent: rgba(212, 162, 78, 0.25);
      --pw-success: #4ade80;
      --pw-danger: #f87171;
      --pw-font: 'JetBrains Mono', monospace;
      --pw-font-ui: 'Inter', sans-serif;
    }

    * { margin: 0; padding: 0; box-sizing: border-box; }
    
    body {
      background: var(--pw-bg);
      color: #ede4d4;
      font-family: 'Inter', sans-serif;
      min-height: 100vh;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    body::before {
      content: '';
      position: fixed;
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      background: radial-gradient(ellipse at 30% 50%, rgba(180, 140, 60, 0.06) 0%, transparent 50%),
                  radial-gradient(ellipse at 70% 50%, rgba(200, 150, 70, 0.04) 0%, transparent 50%);
      z-index: -1;
    }

    #game-wrapper {
      position: relative;
      border: 2px solid rgba(212, 162, 78, 0.3);
      border-radius: 12px;
      overflow: hidden;
      box-shadow: 0 0 40px rgba(212, 162, 78, 0.1);
    }

    #game-container canvas {
      display: block;
      image-rendering: pixelated;
      image-rendering: crisp-edges;
    }

    .game-header {
      text-align: center;
      margin-bottom: 1.5rem;
    }

    .game-header h1 {
      font-size: 1.8rem;
      font-weight: 600;
      background: linear-gradient(135deg, #ede4d4, #d4a24e);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
      margin-bottom: 0.3rem;
    }

    .game-header p {
      font-size: 0.85rem;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
    }

    .controls {
      margin-top: 1rem;
      text-align: center;
      font-size: 0.75rem;
      color: #6b5f4e;
      font-family: 'JetBrains Mono', monospace;
    }

    .controls kbd {
      background: rgba(255,255,255,0.08);
      border: 1px solid rgba(255,255,255,0.12);
      border-radius: 4px;
      padding: 2px 6px;
      font-size: 0.7rem;
      color: #b8a98e;
    }

    .back-link {
      position: fixed;
      top: 1rem;
      left: 1rem;
      color: #8a7d6a;
      text-decoration: none;
      font-family: 'JetBrains Mono', monospace;
      font-size: 0.8rem;
      padding: 0.4rem 0.8rem;
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 8px;
      transition: all 0.2s;
    }

    .back-link:hover {
      color: #d4a24e;
      border-color: rgba(212, 162, 78, 0.3);
    }

    #dialog-box {
      display: none;
      position: absolute;
      bottom: 10px;
      left: 10px;
      right: 10px;
      background: rgba(30, 24, 18, 0.95);
      border: 2px solid rgba(212, 162, 78, 0.5);
      border-radius: 8px;
      padding: 12px 16px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
      color: #ede4d4;
      line-height: 1.5;
      z-index: 100;
    }

    #dialog-box .speaker {
      color: #d4a24e;
      font-weight: 600;
      margin-bottom: 4px;
    }

    #dialog-box .continue {
      text-align: right;
      font-size: 10px;
      color: #8a7d6a;
      margin-top: 6px;
    }

    #dialog-choices {
      display: none;
      gap: 8px;
      margin-top: 8px;
      justify-content: center;
    }

    .choice-btn {
      padding: 6px 18px;
      border-radius: 6px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      cursor: pointer;
      border: 1px solid rgba(255,255,255,0.15);
      transition: all 0.15s;
    }

    .choice-yes {
      background: rgba(74, 222, 128, 0.15);
      border-color: rgba(74, 222, 128, 0.4);
      color: #4ade80;
    }
    .choice-yes:hover { background: rgba(74, 222, 128, 0.25); }

    .choice-no {
      background: rgba(248, 113, 113, 0.15);
      border-color: rgba(248, 113, 113, 0.4);
      color: #f87171;
    }
    .choice-no:hover { background: rgba(248, 113, 113, 0.25); }

    /* Quest HUD */
    #quest-hud {
      display: none;
      position: absolute;
      top: 10px;
      right: 10px;
      max-width: 220px;
      background: rgba(30, 24, 18, 0.9);
      border: 1px solid rgba(212, 162, 78, 0.25);
      border-radius: 8px;
      padding: 8px 12px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 10px;
      color: #d4cab8;
      z-index: 100;
    }

    .quest-entry { margin-bottom: 6px; }
    .quest-entry:last-child { margin-bottom: 0; }

    .quest-name {
      color: #d4a24e;
      font-weight: 600;
      font-size: 11px;
      margin-bottom: 3px;
    }

    .quest-step {
      color: #b8a98e;
      padding-left: 4px;
      line-height: 1.6;
    }

    .quest-step.done {
      color: #4ade80;
      text-decoration: line-through;
      opacity: 0.6;
    }

    /* Inventory panel */
    #inventory-panel {
      display: none;
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 340px;
      max-height: 80vh;
      background: rgba(30, 24, 18, 0.97);
      border: 2px solid rgba(212, 162, 78, 0.4);
      border-radius: 12px;
      z-index: 1100;
      font-family: 'JetBrains Mono', monospace;
      color: #d4cab8;
      overflow-y: auto;
      box-shadow: 0 0 40px rgba(212, 162, 78, 0.15);
    }

    .inv-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 12px 16px;
      border-bottom: 1px solid rgba(255,255,255,0.08);
      font-weight: 600;
      font-size: 14px;
      color: #d4a24e;
    }

    .inv-header button {
      background: none; border: none; color: #8a7d6a;
      cursor: pointer; font-size: 16px;
    }
    .inv-header button:hover { color: #f87171; }

    .inv-section { padding: 8px 12px; }
    .inv-section-title {
      font-size: 10px;
      color: #8a7d6a;
      text-transform: uppercase;
      letter-spacing: 1px;
      margin-bottom: 6px;
    }

    .inv-grid {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
    }

    .inv-slot {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 6px 10px;
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 6px;
      cursor: default;
      transition: all 0.15s;
      font-size: 11px;
    }

    .inv-slot:hover {
      background: rgba(212, 162, 78, 0.1);
      border-color: rgba(212, 162, 78, 0.3);
    }

    .inv-icon { font-size: 16px; }
    .inv-name { color: #d4cab8; }
    .inv-qty { color: #d4a24e; font-size: 10px; }

    .inv-empty {
      color: #6b5f4e;
      font-size: 11px;
      padding: 12px;
      text-align: center;
    }

    .inv-desc {
      padding: 8px 16px 12px;
      font-size: 10px;
      color: #8a7d6a;
      min-height: 24px;
      border-top: 1px solid rgba(255,255,255,0.06);
    }

    /* Editor modals */
    /* ═══ MODALS — REVAMPED ═══ */
    .editor-modal {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 440px;
      max-height: 88vh;
      background: #1e1812;
      border: 1px solid rgba(212, 162, 78, 0.25);
      border-radius: 14px;
      z-index: 2000;
      font-family: 'JetBrains Mono', monospace;
      color: #d4cab8;
      box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 1px rgba(212,162,78,0.3);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      animation: modalFadeIn 0.15s ease;
    }

    /* Large modals — fullscreen-ish for complex features */
    .editor-modal.modal-large {
      width: min(90vw, 700px);
      max-height: 92vh;
    }

    .editor-modal.modal-fullscreen {
      width: 96vw;
      height: 92vh;
      max-height: 92vh;
      border-radius: 12px;
    }

    /* Kill nested scrolls in MODALS only — not editor panel */
    .editor-modal .modal-body > div > div {
      max-height: none;
    }

    @keyframes modalFadeIn {
      from { opacity: 0; transform: translate(-50%, -48%); }
      to { opacity: 1; transform: translate(-50%, -50%); }
    }

    .quest-wizard-modal { width: min(90vw, 520px); }

    .modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 14px 18px;
      background: rgba(212, 162, 78, 0.06);
      border-bottom: 1px solid rgba(212, 162, 78, 0.12);
      font-weight: 600;
      font-size: 13px;
      color: #d4a24e;
      flex-shrink: 0;
    }

    .modal-close {
      background: none; border: none; color: #8a7d6a;
      cursor: pointer; font-size: 18px;
      padding: 2px 6px;
      border-radius: 6px;
      transition: all 0.15s;
    }
    .modal-close:hover { color: #f87171; background: rgba(248,113,113,0.1); }

    .modal-tabs {
      display: flex;
      border-bottom: 1px solid rgba(255,255,255,0.06);
      background: rgba(0,0,0,0.15);
      flex-shrink: 0;
    }

    .modal-tab {
      flex: 1;
      padding: 10px 8px;
      background: none;
      border: none;
      border-bottom: 2px solid transparent;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      cursor: pointer;
      transition: all 0.15s;
    }

    .modal-tab:hover { color: #b8a98e; background: rgba(212,162,78,0.05); }

    .modal-tab.active {
      color: #d4a24e;
      border-bottom-color: #d4a24e;
      background: rgba(212,162,78,0.08);
    }

    .modal-body {
      padding: 16px 18px;
      overflow-y: auto;
      flex: 1;
    }

    .modal-body::-webkit-scrollbar { width: 4px; }
    .modal-body::-webkit-scrollbar-track { background: transparent; }
    .modal-body::-webkit-scrollbar-thumb { background: rgba(212,162,78,0.3); border-radius: 2px; }

    .modal-field {
      margin-bottom: 12px;
    }

    .modal-field label {
      display: block;
      font-size: 10px;
      color: #a89878;
      margin-bottom: 5px;
      text-transform: uppercase;
      letter-spacing: 0.6px;
      font-weight: 500;
    }

    .modal-field input[type="text"],
    .modal-field input[type="number"],
    .modal-field select,
    .modal-field textarea {
      width: 100%;
      padding: 8px 12px;
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 8px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      outline: none;
      transition: border-color 0.15s, background 0.15s;
    }

    .modal-field input:hover,
    .modal-field select:hover,
    .modal-field textarea:hover {
      background: rgba(255,255,255,0.06);
      border-color: rgba(255,255,255,0.12);
    }

    .modal-field textarea { resize: vertical; min-height: 60px; }

    .modal-field input:focus,
    .modal-field select:focus,
    .modal-field textarea:focus {
      border-color: rgba(212, 162, 78, 0.5);
      background: rgba(212, 162, 78, 0.04);
      box-shadow: 0 0 0 2px rgba(212, 162, 78, 0.08);
    }

    .modal-field input[type="checkbox"] {
      margin-right: 8px;
      accent-color: #d4a24e;
    }

    /* Catch-all: any input/select inside modal gets dark styling */
    .editor-modal input[type="text"],
    .editor-modal input[type="number"],
    .editor-modal select,
    .editor-modal textarea {
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 8px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      padding: 8px 12px;
      outline: none;
    }
    .editor-modal input:focus,
    .editor-modal select:focus,
    .editor-modal textarea:focus {
      border-color: rgba(212, 162, 78, 0.5);
    }

    .modal-btn {
      padding: 9px 16px;
      background: rgba(255,255,255,0.05);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 8px;
      color: #d4cab8;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      cursor: pointer;
      transition: all 0.2s;
      font-weight: 500;
    }

    .modal-btn:hover { background: rgba(255,255,255,0.1); transform: translateY(-1px); }
    .modal-btn:active { transform: translateY(0); }

    .modal-btn.primary {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.3);
      color: #d4a24e;
    }

    .modal-btn.primary:hover { background: rgba(212, 162, 78, 0.3); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(212,162,78,0.2); }

    .modal-hint {
      color: #6b5f4e;
      font-size: 11px;
      text-align: center;
      padding: 16px 0;
    }

    .item-preview {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 10px;
      background: rgba(255,255,255,0.03);
      border-radius: 8px;
      margin-bottom: 10px;
    }

    .preview-icon { font-size: 28px; }
    .item-preview small { color: #8a7d6a; }

    /* Quest wizard specifics */
    .wiz-section {
      margin-bottom: 14px;
      padding-bottom: 10px;
      border-bottom: 1px solid rgba(255,255,255,0.05);
    }

    .wiz-section:last-of-type { border-bottom: none; }

    .wiz-section-title {
      font-size: 11px;
      font-weight: 600;
      color: #d4a24e;
      margin-bottom: 8px;
    }

    .wiz-step-item {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 6px;
      margin-bottom: 4px;
      font-size: 11px;
    }

    .step-num {
      background: rgba(212, 162, 78, 0.2);
      color: #d4a24e;
      width: 20px; height: 20px;
      border-radius: 50%;
      display: flex; align-items: center; justify-content: center;
      font-size: 10px; font-weight: 600;
      flex-shrink: 0;
    }

    .step-desc { flex: 1; }
    .step-hint { color: #8a7d6a; font-size: 9px; }

    .step-remove {
      background: none; border: none; color: #8a7d6a;
      cursor: pointer; font-size: 12px; padding: 2px;
    }
    .step-remove:hover { color: #f87171; }

    .step-add-row {
      display: flex;
      gap: 6px;
      align-items: center;
      margin-top: 6px;
    }

    .step-add-row select {
      flex: 1;
      padding: 6px 8px;
      background: rgba(255,255,255,0.05);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 6px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
    }

    .step-add-row input {
      padding: 6px 8px;
      background: rgba(255,255,255,0.05);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 6px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
    }

    /* Quest list */
    .quest-list-entry {
      padding: 10px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 8px;
      margin-bottom: 6px;
    }

    .qle-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 4px;
    }

    .qle-info {
      font-size: 9px;
      color: #8a7d6a;
      margin-bottom: 6px;
    }

    .qle-step {
      font-size: 10px;
      color: #b8a98e;
      padding-left: 8px;
    }

    /* Level tabs */
    .level-tabs {
      display: flex;
      gap: 2px;
      padding: 6px 8px;
      border-bottom: 1px solid rgba(255,255,255,0.06);
      overflow-x: auto;
    }

    .level-tab {
      padding: 4px 10px;
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 6px 6px 0 0;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
      font-size: 10px;
      cursor: pointer;
      white-space: nowrap;
      transition: all 0.15s;
    }

    .level-tab:hover { background: rgba(212, 162, 78, 0.1); color: #d4cab8; }
    .level-tab.active {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.4);
      color: #d4a24e;
      border-bottom-color: transparent;
    }

    .level-tab-add {
      color: #4ade80;
      font-weight: 600;
      font-size: 14px;
      padding: 2px 10px;
    }
    .level-tab-add:hover { background: rgba(74, 222, 128, 0.1); }

    /* Tile rotation control */
    .tile-rotation-control {
      display: flex;
      align-items: center;
      gap: 4px;
      padding: 6px 0;
      margin-bottom: 6px;
      border-bottom: 1px solid rgba(255,255,255,0.06);
    }

    .rot-btn {
      padding: 3px 8px;
      background: rgba(255,255,255,0.04);
      border: 1px solid rgba(255,255,255,0.08);
      border-radius: 4px;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
      font-size: 10px;
      cursor: pointer;
      transition: all 0.15s;
    }

    .rot-btn:hover { background: rgba(212, 162, 78, 0.1); }
    .rot-btn.active {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.4);
      color: #d4a24e;
    }

    /* NPC pose grid */
    .npc-pose-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 4px;
    }

    .npc-pose-btn {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
      padding: 4px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.15s;
    }

    .npc-pose-btn:hover { background: rgba(212, 162, 78, 0.1); }
    .npc-pose-btn.selected {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.4);
    }

    .npc-pose-btn canvas {
      width: 40px;
      height: 40px;
      image-rendering: pixelated;
    }

    .npc-pose-btn span {
      font-size: 7px;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
    }

    .npc-pose-btn.selected span { color: #d4a24e; }

    /* Step form in quest wizard */
    .step-form {
      display: none;
      background: rgba(212, 162, 78, 0.05);
      border: 1px solid rgba(212, 162, 78, 0.2);
      border-radius: 8px;
      padding: 10px;
      margin: 8px 0;
    }

    .step-form-inner .modal-field { margin-bottom: 8px; }

    /* Editor panel */
        /* ═══ EDITOR PANEL — REVAMPED ═══ */
    #editor-panel {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 340px;
      height: 100vh;
      background: rgba(26, 20, 14, 0.98);
      border-right: 1px solid rgba(212, 162, 78, 0.2);
      z-index: 1000;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      color: #d4cab8;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }

    .editor-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 12px;
      background: rgba(212, 162, 78, 0.08);
      border-bottom: 1px solid rgba(212, 162, 78, 0.15);
      font-weight: 600;
      font-size: 12px;
      color: #d4a24e;
      flex-shrink: 0;
    }

    .editor-header button {
      background: none;
      border: none;
      color: #8a7d6a;
      cursor: pointer;
      font-size: 16px;
      padding: 2px 4px;
      border-radius: 4px;
      transition: all 0.15s;
    }

    .editor-header button:hover { color: #f87171; background: rgba(248,113,113,0.1); }

    /* Toolbar — compact icon strip */
    .editor-tools {
      display: flex;
      flex-wrap: wrap;
      gap: 1px;
      padding: 6px;
      border-bottom: 1px solid rgba(255,255,255,0.06);
      background: rgba(0,0,0,0.2);
      flex-shrink: 0;
    }

    .tool-group {
      display: contents;
    }

    .tool-group-label {
      display: none; /* hidden — tools are now icon-only in toolbar */
    }

    .tool-group-btns {
      display: contents;
    }

    .tool-btn {
      width: 36px;
      height: 32px;
      padding: 0;
      background: rgba(255,255,255,0.03);
      border: 1px solid transparent;
      border-radius: 6px;
      color: #9b8b6e;
      font-size: 14px;
      cursor: pointer;
      text-align: center;
      line-height: 32px;
      transition: all 0.15s;
      position: relative;
    }

    .tool-btn:hover { background: rgba(212, 162, 78, 0.12); color: #d4cab8; border-color: rgba(212,162,78,0.2); }
    .tool-btn.active { background: rgba(212, 162, 78, 0.22); border-color: rgba(212, 162, 78, 0.5); color: #d4a24e; box-shadow: 0 0 8px rgba(212,162,78,0.15); }

    /* Tooltip on hover */
    .tool-btn::after {
      content: attr(title);
      position: absolute;
      bottom: -24px;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(30,24,18,0.95);
      color: #d4a24e;
      font-size: 9px;
      padding: 2px 6px;
      border-radius: 4px;
      white-space: nowrap;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.15s;
      z-index: 10;
    }
    .tool-btn:hover::after { opacity: 1; }

    /* Divider between tool groups */
    .tool-group + .tool-group > .tool-group-btns > .tool-btn:first-child {
      margin-left: 4px;
    }

    /* Palette — takes remaining space, MUST scroll */
    .editor-palette {
      padding: 8px;
      flex: 1;
      min-height: 0; /* critical for flex scroll */
      overflow-y: auto;
      overflow-x: hidden;
      border-bottom: 1px solid rgba(255,255,255,0.06);
    }

    .editor-palette::-webkit-scrollbar { width: 4px; }
    .editor-palette::-webkit-scrollbar-track { background: transparent; }
    .editor-palette::-webkit-scrollbar-thumb { background: rgba(212,162,78,0.3); border-radius: 2px; }

    /* Footer actions — compact row */
    .editor-actions {
      display: flex;
      gap: 3px;
      padding: 4px 6px;
      flex-shrink: 0;
    }

    .editor-actions button {
      flex: 1;
      padding: 5px 4px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 5px;
      color: #9b8b6e;
      font-size: 9px;
      font-family: 'JetBrains Mono', monospace;
      cursor: pointer;
      transition: all 0.15s;
      white-space: nowrap;
    }

    .editor-actions button:hover { background: rgba(212, 162, 78, 0.12); color: #d4a24e; }

    .editor-info {
      padding: 4px 8px;
      font-size: 9px;
      color: #6b5f4e;
      border-top: 1px solid rgba(255,255,255,0.04);
      flex-shrink: 0;
    }

    .palette-item {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      padding: 4px 8px;
      margin: 2px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 4px;
      color: #b8a98e;
      font-size: 9px;
      font-family: 'JetBrains Mono', monospace;
      cursor: pointer;
      transition: all 0.15s;
    }

    .palette-item:hover { background: rgba(212, 162, 78, 0.1); }
    .palette-item.selected { background: rgba(212, 162, 78, 0.2); border-color: rgba(212, 162, 78, 0.4); color: #d4a24e; }

    .palette-item canvas {
      width: 24px;
      height: 24px;
      border-radius: 3px;
      image-rendering: pixelated;
    }

    .palette-grid-scroll {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      min-height: 0;
      max-height: calc(100vh - 380px); /* leave room for controls above + actions below */
    }

    .palette-grid-scroll::-webkit-scrollbar { width: 4px; }
    .palette-grid-scroll::-webkit-scrollbar-track { background: transparent; }
    .palette-grid-scroll::-webkit-scrollbar-thumb { background: rgba(212,162,78,0.3); border-radius: 2px; }

    .palette-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
      gap: 4px;
    }

    .palette-tile {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 3px;
      padding: 6px 4px;
      background: rgba(255,255,255,0.03);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 6px;
      cursor: pointer;
      transition: all 0.15s;
      font-family: 'JetBrains Mono', monospace;
    }

    .palette-tile:hover { background: rgba(212, 162, 78, 0.1); }
    .palette-tile.selected {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.4);
    }

    .palette-tile canvas {
      width: 40px;
      height: 40px;
      border-radius: 4px;
      image-rendering: pixelated;
      background: rgba(0,0,0,0.3);
    }

    .palette-tile img {
      border-radius: 4px;
      background: rgba(0,0,0,0.2);
    }

    .palette-tile span {
      font-size: 8px;
      color: #b8a98e;
      text-align: center;
      line-height: 1.2;
      max-width: 80px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .palette-tile.selected span { color: #d4a24e; }

    .palette-hint {
      color: #8a7d6a;
      font-size: 10px;
      padding: 8px;
      line-height: 1.5;
    }

    .editor-actions {
      display: flex;
      gap: 6px;
      padding: 8px;
    }

    .editor-actions button {
      flex: 1;
      padding: 6px 8px;
      background: rgba(212, 162, 78, 0.1);
      border: 1px solid rgba(212, 162, 78, 0.25);
      border-radius: 6px;
      color: #d4a24e;
      font-size: 10px;
      font-family: 'JetBrains Mono', monospace;
      cursor: pointer;
      transition: all 0.15s;
    }

    .editor-actions button:hover { background: rgba(212, 162, 78, 0.2); }

    .editor-info {
      padding: 6px 12px;
      font-size: 9px;
      color: #6b5f4e;
    }

    /* Mobile d-pad */
    #mobile-controls {
      display: none;
      margin-top: 1rem;
      position: relative;
      width: 150px;
      height: 150px;
    }

    .dpad-btn {
      position: absolute;
      width: 48px;
      height: 48px;
      background: rgba(212, 162, 78, 0.15);
      border: 1px solid rgba(212, 162, 78, 0.3);
      border-radius: 8px;
      color: #d4a24e;
      font-size: 1.2rem;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
    }

    .dpad-btn:active { background: rgba(212, 162, 78, 0.3); }
    .dpad-up { top: 0; left: 51px; }
    .dpad-down { bottom: 0; left: 51px; }
    .dpad-left { top: 51px; left: 0; }
    .dpad-right { top: 51px; right: 0; }
    .dpad-action {
      top: 51px;
      left: 51px;
      font-size: 0.7rem;
      font-family: 'JetBrains Mono', monospace;
    }

    @media (max-width: 768px) {
      #mobile-controls { display: block; margin: 1rem auto; }
      .controls { display: none; }
    }

    #loading {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      background: #1a1410;
      z-index: 200;
      font-family: 'JetBrains Mono', monospace;
      color: #d4a24e;
      font-size: 0.9rem;
      gap: 20px;
    }

    .loading-logo {
      width: 320px;
      max-width: 80vw;
      image-rendering: pixelated;
      animation: logoPulse 2s ease-in-out infinite;
    }

    @keyframes logoPulse {
      0%, 100% { transform: scale(1); filter: brightness(1); }
      50% { transform: scale(1.03); filter: brightness(1.15); }
    }

    .loading-bar-container {
      width: 260px;
      max-width: 70vw;
      height: 8px;
      background: rgba(255, 255, 255, 0.08);
      border-radius: 4px;
      overflow: hidden;
      border: 1px solid rgba(212, 162, 78, 0.2);
    }

    .loading-bar-fill {
      height: 100%;
      width: 0%;
      background: linear-gradient(90deg, #d4a24e, #4ade80);
      border-radius: 4px;
      transition: width 0.3s ease;
    }

    .loading-text {
      font-size: 0.75rem;
      color: #8a7d6a;
      letter-spacing: 0.5px;
    }

    /* ═══ ABILITY BAR ═══ */
    #ability-bar {
      display: none;
      position: absolute;
      bottom: 12px;
      left: 50%;
      transform: translateX(-50%);
      gap: 8px;
      z-index: 900;
      pointer-events: auto;
    }

    .ability-slot {
      width: 52px;
      height: 52px;
      background: rgba(30, 24, 18, 0.85);
      border: 2px solid rgba(212, 162, 78, 0.4);
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      cursor: pointer;
      transition: border-color 0.2s;
      overflow: hidden;
    }

    .ability-slot:hover {
      border-color: rgba(212, 162, 78, 0.8);
    }

    .ability-slot.empty {
      opacity: 0.4;
    }

    .ability-icon {
      font-size: 24px;
      z-index: 2;
      position: relative;
      text-shadow: 0 1px 4px rgba(0,0,0,0.5);
    }

    .ability-cooldown {
      position: absolute;
      bottom: 0;
      left: 0;
      right: 0;
      height: 0%;
      background: rgba(0, 0, 0, 0.6);
      z-index: 1;
      transition: height 0.1s linear;
      border-radius: 0 0 8px 8px;
    }

    .ability-keybind {
      position: absolute;
      bottom: 2px;
      right: 3px;
      font-size: 8px;
      font-family: 'JetBrains Mono', monospace;
      color: rgba(212, 162, 78, 0.6);
      z-index: 3;
      text-transform: uppercase;
    }

    /* ═══ ABILITY SWAP OVERLAY ═══ */
    #ability-swap-overlay {
      position: absolute;
      bottom: 80px;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(30, 24, 18, 0.95);
      border: 1px solid rgba(212, 162, 78, 0.4);
      border-radius: 12px;
      padding: 12px;
      z-index: 950;
      min-width: 250px;
      max-width: 350px;
      font-family: 'JetBrains Mono', monospace;
    }

    .swap-title {
      font-size: 13px;
      font-weight: 600;
      color: #d4a24e;
      margin-bottom: 4px;
    }

    .swap-hint {
      font-size: 9px;
      color: #8a7d6a;
      margin-bottom: 10px;
    }

    .swap-grid {
      display: flex;
      flex-direction: column;
      gap: 6px;
    }

    .swap-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 10px;
      background: rgba(255, 255, 255, 0.03);
      border: 1px solid rgba(255, 255, 255, 0.06);
      border-radius: 8px;
      cursor: pointer;
      transition: background 0.15s;
    }

    .swap-item:hover {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.3);
    }

    .swap-icon {
      font-size: 22px;
      flex-shrink: 0;
    }

    .swap-info {
      flex: 1;
      min-width: 0;
    }

    .swap-name {
      font-size: 12px;
      color: #ede4d4;
      font-weight: 500;
    }

    .swap-desc {
      font-size: 9px;
      color: #a89878;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .swap-stats {
      font-size: 8px;
      color: #8a7d6a;
      margin-top: 2px;
    }

    /* ═══ Combat HUD ═══ */
    #combat-hud {
      position: absolute;
      top: 12px;
      left: 12px;
      z-index: 900;
      pointer-events: none;
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-family: 'JetBrains Mono', monospace;
    }

    #combat-hud.combat-flash {
      animation: combatFlash 0.3s ease;
    }

    @keyframes combatFlash {
      0%, 100% { filter: none; }
      50% { filter: brightness(2) drop-shadow(0 0 8px rgba(239, 68, 68, 0.8)); }
    }

    .combat-row {
      display: flex;
      align-items: center;
      gap: 6px;
      background: rgba(30, 24, 18, 0.85);
      border: 1px solid rgba(212, 162, 78, 0.2);
      border-radius: 8px;
      padding: 4px 10px;
      backdrop-filter: blur(4px);
    }

    .combat-icon {
      font-size: 14px;
      line-height: 1;
    }

    .combat-bar-bg {
      width: 100px;
      height: 8px;
      background: rgba(255, 255, 255, 0.08);
      border-radius: 4px;
      overflow: hidden;
    }

    .combat-bar-fill {
      height: 100%;
      border-radius: 4px;
      transition: width 0.4s ease;
    }

    .hp-fill {
      background: #4ade80;
    }

    .mana-fill {
      background: #818cf8;
    }

    .combat-text {
      font-size: 10px;
      color: #d4cab8;
      min-width: 52px;
      text-align: right;
    }

    .combat-equip-stats {
      font-size: 11px;
      color: #d4a24e;
      letter-spacing: 1px;
      padding: 1px 0;
    }

    /* ═══ DIALOG TREE EDITOR ═══ */
    #dialog-tree-editor {
      position: fixed;
      inset: 0;
      z-index: 5000;
      background: rgba(5, 5, 12, 0.95);
      display: flex;
      flex-direction: column;
      font-family: 'JetBrains Mono', monospace;
    }

    .tree-toolbar {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 8px 16px;
      background: rgba(30, 24, 18, 0.98);
      border-bottom: 1px solid rgba(212, 162, 78, 0.3);
      z-index: 5001;
    }

    .tree-title {
      font-size: 13px;
      color: #d4a24e;
      font-weight: 600;
    }

    .tree-toolbar-btns {
      display: flex;
      gap: 6px;
    }

    .tree-tb-btn {
      padding: 4px 12px;
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 4px;
      color: #d4cab8;
      cursor: pointer;
      transition: all 0.15s;
    }

    .tree-tb-btn:hover {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.4);
    }

    .tree-tb-save {
      background: rgba(74, 222, 128, 0.1);
      border-color: rgba(74, 222, 128, 0.3);
      color: #4ade80;
    }

    .tree-tb-save:hover {
      background: rgba(74, 222, 128, 0.2);
    }

    .tree-tb-cancel {
      color: #f87171;
    }

    .tree-canvas {
      flex: 1;
      position: relative;
      overflow: auto;
      cursor: default;
    }

    .tree-canvas.connecting-mode {
      cursor: crosshair;
    }

    .tree-lines {
      position: absolute;
      top: 0;
      left: 0;
      width: 5000px;
      height: 5000px;
      pointer-events: none;
      z-index: 1;
    }

    .tree-node {
      position: absolute;
      width: 240px;
      background: rgba(15, 15, 25, 0.95);
      border: 1.5px solid rgba(212, 162, 78, 0.3);
      border-radius: 8px;
      z-index: 10;
      cursor: grab;
      transition: box-shadow 0.15s;
      user-select: none;
    }

    .tree-node:hover {
      box-shadow: 0 0 12px rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.5);
    }

    .tree-node.selected-node {
      border-color: rgba(212, 162, 78, 0.7);
      box-shadow: 0 0 16px rgba(212, 162, 78, 0.3);
    }

    .tree-node.start-node {
      border-color: rgba(74, 222, 128, 0.5);
    }

    .tree-node.start-node .node-header {
      border-bottom-color: rgba(74, 222, 128, 0.3);
    }

    .tree-node.start-node .node-speaker::before {
      content: '⭐ ';
    }

    .node-header {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 6px 10px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.06);
      font-size: 11px;
    }

    .node-speaker {
      color: #d4a24e;
      font-weight: 600;
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .node-condition-badge {
      font-size: 12px;
    }

    .node-actions-icons {
      font-size: 11px;
    }

    .node-body {
      padding: 8px 10px;
      font-size: 11px;
      color: #d0d0e0;
      line-height: 1.4;
      max-height: 60px;
      overflow: hidden;
      word-wrap: break-word;
    }

    .node-choices {
      border-top: 1px solid rgba(255, 255, 255, 0.06);
      padding: 4px 6px;
    }

    .node-choice {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 3px 6px;
      font-size: 10px;
      color: #a0a0b8;
      border-radius: 4px;
      cursor: default;
    }

    .node-choice:hover {
      background: rgba(212, 162, 78, 0.1);
    }

    .choice-text {
      flex: 1;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .node-next-port {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 4px 10px;
      border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    .next-label {
      font-size: 9px;
      color: #8a7d6a;
    }

    .node-port {
      display: inline-block;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      cursor: crosshair;
      transition: all 0.15s;
      font-size: 10px;
      line-height: 12px;
      text-align: center;
      flex-shrink: 0;
    }

    .node-port-in {
      background: rgba(74, 222, 128, 0.3);
      border: 1px solid rgba(74, 222, 128, 0.5);
      color: transparent;
    }

    .node-port-in:hover {
      background: rgba(74, 222, 128, 0.6);
      box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
    }

    .node-port-out {
      background: rgba(212, 162, 78, 0.3);
      border: 1px solid rgba(212, 162, 78, 0.5);
      color: transparent;
    }

    .node-port-out:hover {
      background: rgba(212, 162, 78, 0.6);
      box-shadow: 0 0 8px rgba(212, 162, 78, 0.4);
    }

    /* Tree context menu */
    .tree-context-menu {
      position: fixed;
      background: rgba(30, 24, 18, 0.97);
      border: 1px solid rgba(212, 162, 78, 0.4);
      border-radius: 6px;
      z-index: 6000;
      padding: 4px 0;
      min-width: 160px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
    }

    .tree-ctx-item {
      padding: 6px 14px;
      color: #d4cab8;
      cursor: pointer;
    }

    .tree-ctx-item:hover {
      background: rgba(212, 162, 78, 0.15);
    }

    /* Tree edit form (node editor) */
    .tree-edit-form {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 420px;
      max-height: 85vh;
      overflow-y: auto;
      background: rgba(30, 24, 18, 0.98);
      border: 1px solid rgba(212, 162, 78, 0.4);
      border-radius: 10px;
      z-index: 6000;
      font-family: 'JetBrains Mono', monospace;
    }

    .tef-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 14px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.08);
      font-size: 12px;
      color: #d4a24e;
      font-weight: 600;
    }

    .tef-close {
      background: none;
      border: none;
      color: #8a7d6a;
      font-size: 16px;
      cursor: pointer;
    }

    .tef-body {
      padding: 12px 14px;
    }

    .tef-body label {
      display: block;
      font-size: 10px;
      color: #a89878;
      margin-top: 10px;
      margin-bottom: 4px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .tef-body label small {
      text-transform: none;
      letter-spacing: 0;
      color: #555;
    }

    .tef-body input[type="text"],
    .tef-body textarea,
    .tef-body select {
      width: 100%;
      padding: 6px 8px;
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 4px;
      color: #d0d0e0;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      box-sizing: border-box;
    }

    .tef-body textarea {
      resize: vertical;
    }

    .tef-choice {
      display: flex;
      gap: 4px;
      margin-bottom: 4px;
      align-items: center;
    }

    .tef-choice input {
      flex: 1;
    }

    .tef-choice select {
      width: 140px;
      flex-shrink: 0;
    }

    .tef-choice-del,
    .tef-action-del {
      background: none;
      border: none;
      color: #f87171;
      cursor: pointer;
      font-size: 13px;
      padding: 2px 4px;
    }

    .tef-action {
      display: flex;
      gap: 4px;
      margin-bottom: 4px;
      align-items: center;
    }

    .tef-action select {
      width: 120px;
      flex-shrink: 0;
    }

    .tef-action input {
      flex: 1;
    }

    .tef-cond-row {
      display: flex;
      gap: 6px;
    }

    .tef-cond-row select {
      width: 140px;
    }

    .tef-cond-row input {
      flex: 1;
    }

    .tef-add-btn {
      padding: 4px 10px;
      font-size: 10px;
      font-family: 'JetBrains Mono', monospace;
      background: rgba(212, 162, 78, 0.1);
      border: 1px solid rgba(212, 162, 78, 0.2);
      border-radius: 4px;
      color: #d4a24e;
      cursor: pointer;
      margin-top: 4px;
    }

    .tef-add-btn:hover {
      background: rgba(212, 162, 78, 0.2);
    }

    .tef-btns {
      display: flex;
      gap: 8px;
      margin-top: 16px;
    }

    .tef-save {
      flex: 1;
      padding: 8px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      background: rgba(74, 222, 128, 0.15);
      border: 1px solid rgba(74, 222, 128, 0.4);
      border-radius: 6px;
      color: #4ade80;
      cursor: pointer;
    }

    .tef-save:hover {
      background: rgba(74, 222, 128, 0.25);
    }

    .tef-cancel-btn {
      flex: 1;
      padding: 8px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      background: rgba(248, 113, 113, 0.1);
      border: 1px solid rgba(248, 113, 113, 0.3);
      border-radius: 6px;
      color: #f87171;
      cursor: pointer;
    }

    .tef-cancel-btn:hover {
      background: rgba(248, 113, 113, 0.2);
    }

    /* Dialog tree choice buttons (in-game) */
    .choice-btn.choice-tree {
      background: rgba(212, 162, 78, 0.1);
      border: 1px solid rgba(212, 162, 78, 0.3);
      color: #c0b0f0;
      display: block;
      width: 100%;
      text-align: left;
      margin-bottom: 4px;
      padding: 6px 12px;
    }

    .choice-btn.choice-tree:hover {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.5);
    }

    /* Dialog choices flex-direction for tree choices */
    #dialog-choices:has(.choice-tree) {
      flex-direction: column;
    }

    /* ═══ WORLD MAP VIEW ═══ */
    #world-map-overlay {
      position: fixed;
      inset: 0;
      z-index: 6000;
      background: rgba(5, 5, 12, 0.97);
      display: flex;
      flex-direction: column;
      font-family: 'JetBrains Mono', monospace;
    }

    .wm-toolbar {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 8px 16px;
      background: rgba(30, 24, 18, 0.95);
      border-bottom: 1px solid rgba(212, 162, 78, 0.2);
      flex-shrink: 0;
    }

    .wm-toolbar-title {
      font-size: 14px;
      font-weight: 700;
      color: #d4a24e;
      margin-right: 8px;
    }

    .wm-toolbar-btn {
      background: rgba(212, 162, 78, 0.1);
      border: 1px solid rgba(212, 162, 78, 0.3);
      color: #d4cab8;
      padding: 4px 10px;
      border-radius: 4px;
      font-family: inherit;
      font-size: 11px;
      cursor: pointer;
      transition: all 0.15s;
    }

    .wm-toolbar-btn:hover {
      background: rgba(212, 162, 78, 0.2);
      color: #e0e0f0;
    }

    .wm-toolbar-btn.active {
      background: rgba(212, 162, 78, 0.25);
      border-color: #d4a24e;
      color: #fff;
    }

    .wm-toolbar-spacer { flex: 1; }

    .wm-toolbar-info {
      font-size: 11px;
      color: #6b7280;
    }

    .wm-close-btn {
      background: rgba(248, 113, 113, 0.1);
      border: 1px solid rgba(248, 113, 113, 0.3);
      color: #f87171;
      padding: 4px 10px;
      border-radius: 4px;
      font-family: inherit;
      font-size: 11px;
      cursor: pointer;
    }

    .wm-close-btn:hover {
      background: rgba(248, 113, 113, 0.25);
    }

    .wm-canvas-container {
      flex: 1;
      position: relative;
      overflow: hidden;
      cursor: grab;
    }

    .wm-canvas-container.panning {
      cursor: grabbing;
    }

    .wm-canvas {
      position: absolute;
      top: 0;
      left: 0;
      transform-origin: 0 0;
    }

    .wm-svg-layer {
      position: absolute;
      top: 0;
      left: 0;
      pointer-events: none;
      overflow: visible;
    }

    .wm-level-card {
      position: absolute;
      background: rgba(20, 20, 35, 0.95);
      border: 2px solid rgba(212, 162, 78, 0.3);
      border-radius: 8px;
      padding: 8px;
      cursor: pointer;
      transition: border-color 0.2s, box-shadow 0.2s;
      min-width: 140px;
      user-select: none;
    }

    .wm-level-card:hover {
      border-color: rgba(212, 162, 78, 0.6);
      box-shadow: 0 0 16px rgba(212, 162, 78, 0.15);
    }

    .wm-level-card.current {
      border-color: #d4a24e;
      box-shadow: 0 0 20px rgba(212, 162, 78, 0.3);
    }

    .wm-level-card.dragging {
      opacity: 0.85;
      z-index: 100;
      box-shadow: 0 0 24px rgba(212, 162, 78, 0.4);
      cursor: grabbing;
    }

    .wm-card-name {
      font-size: 12px;
      font-weight: 700;
      color: #e0e0f0;
      margin-bottom: 2px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .wm-card-info {
      font-size: 10px;
      color: #6b7280;
      margin-bottom: 4px;
    }

    .wm-card-minimap {
      width: 100%;
      aspect-ratio: auto;
      max-height: 80px;
      border-radius: 4px;
      image-rendering: pixelated;
      background: rgba(0, 0, 0, 0.3);
      margin-bottom: 4px;
    }

    .wm-card-teleports {
      font-size: 9px;
      color: #9ca3af;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    /* Teleport connection lines */
    .wm-connection-line {
      stroke-width: 2;
      fill: none;
    }

    .wm-connection-twoway { stroke: #4ade80; }
    .wm-connection-oneway { stroke: #fb923c; }

    .wm-connection-arrow {
      stroke-width: 2;
    }

    .wm-connection-label {
      font-family: 'JetBrains Mono', monospace;
      font-size: 9px;
      fill: #6b7280;
    }

    /* Right-click context menu */
    .wm-context-menu {
      position: fixed;
      background: rgba(30, 24, 18, 0.97);
      border: 1px solid rgba(212, 162, 78, 0.4);
      border-radius: 6px;
      z-index: 7000;
      padding: 4px 0;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      min-width: 160px;
    }

    .wm-context-item {
      padding: 6px 12px;
      color: #d4cab8;
      cursor: pointer;
    }

    .wm-context-item:hover {
      background: rgba(212, 162, 78, 0.15);
    }

    .wm-grid-line {
      stroke: rgba(212, 162, 78, 0.06);
      stroke-width: 1;
    }

    /* ═══ Visual Event Blocks ═══ */

    .event-block-list {
      max-height: 50vh;
      overflow-y: auto;
      display: flex;
      flex-direction: column;
      gap: 2px;
      margin-top: 8px;
      padding: 4px;
    }

    /* Tile group header */
    .event-tile-group {
      margin-bottom: 6px;
    }

    .event-tile-header {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 4px 8px;
      font-size: 9px;
      color: #8a7d6a;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .event-tile-header .coord {
      background: rgba(255,255,255,0.05);
      padding: 1px 5px;
      border-radius: 3px;
      font-size: 8px;
    }

    .event-chain-stack {
      display: flex;
      flex-direction: column;
      gap: 2px;
      position: relative;
      padding-left: 12px;
    }

    .event-chain-stack::before {
      content: '';
      position: absolute;
      left: 5px;
      top: 8px;
      bottom: 8px;
      width: 2px;
      background: rgba(212, 162, 78, 0.15);
      border-radius: 1px;
    }

    .event-chain-stack .event-block:last-child::after {
      display: none;
    }

    /* Individual event block */
    .event-block {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      border-radius: 8px;
      font-size: 10px;
      color: #e0e0f0;
      cursor: grab;
      transition: all 0.15s ease;
      position: relative;
      border: 1px solid transparent;
      min-height: 30px;
    }

    .event-block:hover {
      filter: brightness(1.15);
      border-color: rgba(255,255,255,0.1);
    }

    .event-block.dragging {
      opacity: 0.5;
      cursor: grabbing;
    }

    .event-block.drag-over {
      border-color: rgba(212, 162, 78, 0.5);
      box-shadow: 0 0 8px rgba(212, 162, 78, 0.2);
    }

    .event-block-icon {
      font-size: 14px;
      flex-shrink: 0;
      width: 20px;
      text-align: center;
    }

    .event-block-text {
      flex: 1;
      line-height: 1.4;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .event-block-text .ev-label {
      font-weight: 600;
    }

    .event-block-text .ev-detail {
      color: rgba(255,255,255,0.5);
      font-size: 9px;
    }

    .event-block-badge {
      font-size: 8px;
      padding: 1px 5px;
      border-radius: 3px;
      background: rgba(255,255,255,0.08);
      color: #a89878;
      flex-shrink: 0;
    }

    .event-block-actions {
      display: flex;
      gap: 2px;
      opacity: 0;
      transition: opacity 0.15s;
      flex-shrink: 0;
    }

    .event-block:hover .event-block-actions {
      opacity: 1;
    }

    .event-block-actions button {
      background: none;
      border: none;
      color: #8a7d6a;
      cursor: pointer;
      font-size: 11px;
      padding: 2px 4px;
      border-radius: 3px;
      transition: all 0.1s;
    }

    .event-block-actions button:hover {
      background: rgba(255,255,255,0.1);
      color: #e0e0f0;
    }

    .event-block-actions button.del-btn:hover {
      color: #ef4444;
      background: rgba(239, 68, 68, 0.1);
    }

    /* Color categories */
    .event-block.cat-dialog { background: rgba(59, 130, 246, 0.12); }
    .event-block.cat-movement { background: rgba(200, 150, 70, 0.12); }
    .event-block.cat-items { background: rgba(34, 197, 94, 0.12); }
    .event-block.cat-visual { background: rgba(249, 115, 22, 0.12); }
    .event-block.cat-world { background: rgba(239, 68, 68, 0.10); }
    .event-block.cat-logic { background: rgba(234, 179, 8, 0.12); }
    .event-block.cat-sound { background: rgba(20, 184, 166, 0.12); }
    .event-block.cat-ability { background: rgba(236, 72, 153, 0.12); }
    .event-block.cat-combat { background: rgba(239, 68, 68, 0.15); }

    /* Condition blocks */
    .event-block.is-condition {
      border-left: 3px solid rgba(234, 179, 8, 0.5);
    }

    .event-block .condition-branch {
      font-size: 9px;
      color: rgba(234, 179, 8, 0.7);
      margin-top: 2px;
    }

    /* Chain insert button */
    .event-chain-insert {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 16px;
      opacity: 0;
      transition: opacity 0.15s;
      cursor: pointer;
    }

    .event-chain-stack:hover .event-chain-insert {
      opacity: 1;
    }

    .event-chain-insert button {
      background: rgba(212, 162, 78, 0.15);
      border: 1px dashed rgba(212, 162, 78, 0.3);
      color: #d4a24e;
      font-size: 10px;
      padding: 0 8px;
      border-radius: 4px;
      cursor: pointer;
      height: 14px;
      line-height: 12px;
    }

    .event-chain-insert button:hover {
      background: rgba(212, 162, 78, 0.25);
    }

    /* ═══ Event Modal V2 — Category Tabs ═══ */

    .ev-category-tabs {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin-bottom: 10px;
    }

    .ev-category-tab {
      padding: 5px 10px;
      font-size: 10px;
      font-family: 'JetBrains Mono', monospace;
      border-radius: 6px;
      cursor: pointer;
      border: 1px solid rgba(255,255,255,0.06);
      background: rgba(255,255,255,0.03);
      color: #a89878;
      transition: all 0.15s;
    }

    .ev-category-tab:hover {
      background: rgba(255,255,255,0.06);
      color: #d4cab8;
    }

    .ev-category-tab.active {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.3);
      color: #d4a24e;
    }

    .ev-type-grid {
      display: flex;
      flex-direction: column;
      gap: 3px;
      max-height: 200px;
      overflow-y: auto;
      margin-bottom: 10px;
    }

    .ev-type-option {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      border-radius: 6px;
      cursor: pointer;
      border: 1px solid rgba(255,255,255,0.04);
      background: rgba(255,255,255,0.02);
      transition: all 0.15s;
    }

    .ev-type-option:hover {
      background: rgba(255,255,255,0.06);
      border-color: rgba(255,255,255,0.1);
    }

    .ev-type-option.selected {
      background: rgba(212, 162, 78, 0.12);
      border-color: rgba(212, 162, 78, 0.3);
    }

    .ev-type-option .ev-type-icon {
      font-size: 16px;
      width: 24px;
      text-align: center;
    }

    .ev-type-option .ev-type-info {
      flex: 1;
    }

    .ev-type-option .ev-type-name {
      font-size: 11px;
      color: #e0e0f0;
      font-weight: 500;
    }

    .ev-type-option .ev-type-desc {
      font-size: 9px;
      color: #8a7d6a;
      margin-top: 1px;
    }

    .ev-type-option .ev-type-preview {
      font-size: 9px;
      color: #d4a24e;
      margin-top: 2px;
      font-style: italic;
    }

    .ev-modal-preview {
      background: rgba(0,0,0,0.3);
      border: 1px solid rgba(255,255,255,0.06);
      border-radius: 8px;
      padding: 8px 12px;
      margin: 8px 0;
      font-size: 11px;
      color: #d4cab8;
    }

    .ev-modal-preview .event-block {
      cursor: default;
    }

    .ev-modal-preview .event-block:hover {
      filter: none;
      border-color: transparent;
    }

    /* ═══ Rule Editor ═══ */
    #terrain-rules-list > div {
      transition: opacity 0.15s ease, border-color 0.15s ease;
    }
    #terrain-rules-list > div:hover {
      border-color: rgba(212,162,78,0.3) !important;
    }
    #terrain-rules-list input[type="range"] {
      -webkit-appearance: none;
      height: 4px;
      border-radius: 2px;
      background: rgba(255,255,255,0.1);
    }
    #terrain-rules-list input[type="range"]::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 12px;
      height: 12px;
      border-radius: 50%;
      background: #d4a24e;
      cursor: pointer;
    }

    /* ═══ VIRTUAL JOYSTICK + ACTION BUTTONS ═══ */
    #mobile-controls-v2 {
      display: none;
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      height: 200px;
      pointer-events: none;
      z-index: 1500;
    }

    @media (max-width: 768px) {
      #mobile-controls-v2 { display: block; }
    }

    /* Also show on any touch device regardless of width */
    @media (pointer: coarse) {
      #mobile-controls-v2 { display: block; }
    }

    #joystick-area {
      position: absolute;
      left: 20px;
      bottom: 20px;
      width: 120px;
      height: 120px;
      pointer-events: auto;
      touch-action: none;
    }

    #joystick-outer {
      width: 120px;
      height: 120px;
      border-radius: 50%;
      background: rgba(212, 162, 78, 0.08);
      border: 2px solid rgba(212, 162, 78, 0.25);
      position: relative;
      box-shadow: inset 0 0 20px rgba(212, 162, 78, 0.05);
    }

    #joystick-knob {
      position: absolute;
      top: 50%;
      left: 50%;
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background: rgba(212, 162, 78, 0.3);
      border: 2px solid rgba(212, 162, 78, 0.5);
      transform: translate(-50%, -50%);
      box-shadow: 0 0 12px rgba(212, 162, 78, 0.2);
      transition: background 0.1s;
    }

    #joystick-knob:active,
    #joystick-outer:active #joystick-knob {
      background: rgba(212, 162, 78, 0.45);
    }

    #action-buttons {
      position: absolute;
      right: 20px;
      bottom: 20px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      pointer-events: auto;
      touch-action: none;
    }

    .action-btn {
      width: 56px;
      height: 56px;
      border-radius: 50%;
      background: rgba(212, 162, 78, 0.1);
      border: 2px solid rgba(212, 162, 78, 0.3);
      font-size: 22px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      user-select: none;
      -webkit-user-select: none;
      touch-action: manipulation;
      transition: background 0.1s, transform 0.1s;
    }

    .action-btn.pressed,
    .action-btn:active {
      background: rgba(212, 162, 78, 0.3);
      transform: scale(0.92);
    }

    .action-interact {
      border-color: rgba(74, 222, 128, 0.4);
      background: rgba(74, 222, 128, 0.1);
    }
    .action-interact.pressed { background: rgba(74, 222, 128, 0.3); }

    .action-ability1 {
      border-color: rgba(248, 113, 113, 0.4);
      background: rgba(248, 113, 113, 0.1);
    }
    .action-ability1.pressed { background: rgba(248, 113, 113, 0.3); }

    .action-ability2 {
      border-color: rgba(96, 165, 250, 0.4);
      background: rgba(96, 165, 250, 0.1);
    }
    .action-ability2.pressed { background: rgba(96, 165, 250, 0.3); }

    /* ═══ GAMEPAD NOTIFICATION ═══ */
    #gamepad-notification {
      position: fixed;
      top: 20px;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(30, 24, 18, 0.95);
      border: 1px solid rgba(74, 222, 128, 0.4);
      border-radius: 8px;
      padding: 8px 20px;
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
      color: #4ade80;
      z-index: 9999;
      pointer-events: none;
      transition: opacity 0.5s ease;
      box-shadow: 0 0 20px rgba(74, 222, 128, 0.15);
    }

    /* ═══ SCRIPT CONSOLE ═══ */
    .script-console {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      height: 320px;
      background: rgba(30, 24, 18, 0.97);
      border-top: 2px solid rgba(212, 162, 78, 0.4);
      z-index: 10001;
      display: flex;
      flex-direction: column;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      backdrop-filter: blur(10px);
    }
    .sc-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 6px 12px;
      background: rgba(212, 162, 78, 0.1);
      border-bottom: 1px solid rgba(212, 162, 78, 0.2);
      color: #d4a24e;
      font-size: 11px;
      font-weight: 600;
    }
    .sc-header-btns { display: flex; gap: 4px; }
    .sc-btn {
      background: rgba(255,255,255,0.05);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 4px;
      color: #d4cab8;
      cursor: pointer;
      padding: 2px 6px;
      font-size: 11px;
    }
    .sc-btn:hover { background: rgba(212,162,78,0.15); }
    .sc-output {
      flex: 1;
      overflow-y: auto;
      padding: 8px 12px;
      color: #d4cab8;
    }
    .sc-entry { padding: 1px 0; white-space: pre-wrap; word-break: break-all; line-height: 1.5; }
    .sc-log { color: #d4cab8; }
    .sc-warn { color: #fbbf24; }
    .sc-error { color: #f87171; }
    .sc-info { color: #60a5fa; }
    .sc-input-row {
      display: flex;
      align-items: center;
      border-top: 1px solid rgba(255,255,255,0.1);
      padding: 0 8px;
      background: rgba(0,0,0,0.3);
    }
    .sc-prompt { color: #d4a24e; font-size: 14px; margin-right: 6px; }
    .sc-input {
      flex: 1;
      background: transparent;
      border: none;
      outline: none;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      padding: 8px 0;
    }
    .sc-input::placeholder { color: #6b5f4e; }
    .sc-autocomplete {
      position: absolute;
      bottom: 36px;
      left: 40px;
      background: rgba(20, 20, 35, 0.98);
      border: 1px solid rgba(212, 162, 78, 0.3);
      border-radius: 6px;
      padding: 4px 0;
      max-height: 200px;
      overflow-y: auto;
      z-index: 10002;
    }
    .sc-ac-item {
      padding: 4px 12px;
      color: #d4cab8;
      cursor: pointer;
      font-size: 11px;
    }
    .sc-ac-item:hover { background: rgba(212,162,78,0.15); color: #d4a24e; }

    /* ═══ CODE EDITOR MODAL ═══ */
    .code-editor-modal {
      position: fixed;
      inset: 20px;
      background: rgba(30, 24, 18, 0.98);
      border: 1px solid rgba(212, 162, 78, 0.3);
      border-radius: 12px;
      z-index: 10000;
      display: flex;
      flex-direction: column;
      font-family: 'JetBrains Mono', monospace;
      box-shadow: 0 8px 48px rgba(0,0,0,0.6);
    }
    .ce-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 10px 16px;
      background: rgba(212, 162, 78, 0.08);
      border-bottom: 1px solid rgba(212, 162, 78, 0.2);
      color: #d4a24e;
      font-size: 13px;
      font-weight: 600;
      border-radius: 12px 12px 0 0;
    }
    .ce-body {
      flex: 1;
      display: flex;
      overflow: hidden;
    }
    .ce-sidebar {
      width: 240px;
      padding: 12px;
      border-right: 1px solid rgba(255,255,255,0.08);
      overflow-y: auto;
      flex-shrink: 0;
    }
    .ce-field { margin-bottom: 8px; }
    .ce-field label {
      display: block;
      font-size: 10px;
      color: #a89878;
      margin-bottom: 3px;
    }
    .ce-field input {
      width: 100%;
      padding: 4px 8px;
      background: rgba(255,255,255,0.05);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 4px;
      color: #ede4d4;
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
    }
    .ce-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 4px;
      margin: 12px 0;
    }
    .ce-actions .modal-btn { flex: 1; min-width: 70px; font-size: 10px; padding: 5px 8px; }
    .ce-ref-toggle {
      font-size: 10px;
      color: #d4a24e;
      cursor: pointer;
      padding: 6px 0;
      border-top: 1px solid rgba(255,255,255,0.08);
    }
    .ce-ref-toggle:hover { color: #c4b5fd; }
    .ce-reference {
      font-size: 9px;
      color: #8a7d6a;
      max-height: 40vh;
      overflow-y: auto;
    }
    .ce-ref-section {
      color: #d4a24e;
      font-size: 10px;
      font-weight: 600;
      margin: 8px 0 4px;
    }
    .ce-reference code {
      display: block;
      padding: 2px 0;
      color: #a89878;
      cursor: pointer;
    }
    .ce-reference code:hover { color: #c4b5fd; }
    .ce-main {
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow: hidden;
    }
    .ce-editor-wrap {
      flex: 1;
      display: flex;
      overflow: hidden;
      position: relative;
    }
    .ce-line-numbers {
      width: 36px;
      padding: 10px 4px;
      text-align: right;
      font-size: 10px;
      color: #6b5f4e;
      background: rgba(0,0,0,0.2);
      overflow: hidden;
      line-height: 1.5;
      user-select: none;
    }
    .ce-textarea {
      flex: 1;
      resize: none;
      background: rgba(0,0,0,0.15);
      border: none;
      outline: none;
      padding: 10px 12px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      line-height: 1.5;
      tab-size: 2;
      white-space: pre;
      overflow: auto;
    }
    .ce-textarea::placeholder { color: #6b5f4e; }
    .ce-output {
      height: 120px;
      border-top: 1px solid rgba(255,255,255,0.08);
      display: flex;
      flex-direction: column;
    }
    .ce-output-header {
      font-size: 10px;
      color: #8a7d6a;
      padding: 4px 12px;
      background: rgba(0,0,0,0.2);
    }
    .ce-output-log {
      flex: 1;
      overflow-y: auto;
      padding: 4px 12px;
      font-size: 11px;
    }

    /* Plugin action buttons in list */
    .pe-action-btn {
      background: none;
      border: none;
      cursor: pointer;
      font-size: 13px;
      padding: 2px;
      opacity: 0.7;
    }
    .pe-action-btn:hover { opacity: 1; }

    /* ═══ MAIN MENU ═══ */
    #main-menu {
      position: fixed;
      inset: 0;
      z-index: 15000;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #1a1410;
      overflow-y: auto;
    }

    #main-menu::before {
      content: '';
      position: fixed;
      top: -50%;
      left: -50%;
      width: 200%;
      height: 200%;
      background: radial-gradient(ellipse at 30% 50%, rgba(180, 140, 60, 0.08) 0%, transparent 50%),
                  radial-gradient(ellipse at 70% 50%, rgba(200, 150, 70, 0.06) 0%, transparent 50%);
      z-index: -1;
      animation: menuBgPulse 8s ease-in-out infinite;
    }

    @keyframes menuBgPulse {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.6; }
    }

    .menu-container {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
      padding: 40px;
      max-width: 420px;
      width: 90%;
    }

    .menu-logo {
      width: 300px;
      max-width: 80vw;
      image-rendering: pixelated;
      animation: logoPulse 3s ease-in-out infinite;
      margin-bottom: 8px;
    }

    .menu-meta {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }

    .menu-welcome {
      font-family: 'JetBrains Mono', monospace;
      font-size: 14px;
      color: #d4a24e;
      text-align: center;
    }

    .menu-diamonds {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 12px;
      border-radius: 999px;
      background: rgba(103, 232, 249, 0.12);
      border: 1px solid rgba(103, 232, 249, 0.22);
      color: #67e8f9;
      font-size: 11px;
      font-family: 'JetBrains Mono', monospace;
    }

    .menu-buttons {
      display: flex;
      flex-direction: column;
      gap: 10px;
      width: 100%;
    }

    .menu-btn {
      width: 100%;
      padding: 12px 20px;
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 10px;
      color: #d4cab8;
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
      cursor: pointer;
      transition: all 0.2s;
      text-align: left;
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .menu-btn:hover {
      background: rgba(212, 162, 78, 0.1);
      border-color: rgba(212, 162, 78, 0.3);
      color: #ede4d4;
    }

    .menu-btn-primary {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.4);
      color: #d4a24e;
      font-weight: 600;
    }

    .menu-btn-primary:hover {
      background: rgba(212, 162, 78, 0.25);
      box-shadow: 0 0 20px rgba(212, 162, 78, 0.15);
    }

    .menu-btn-small {
      padding: 8px 16px;
      font-size: 11px;
    }

    .menu-btn-ghost {
      background: none;
      border: none;
      color: #8a7d6a;
      font-size: 12px;
      text-align: center;
      justify-content: center;
    }

    .menu-btn-ghost:hover {
      color: #d4a24e;
      background: none;
      border: none;
    }

    .menu-btn-danger {
      background: rgba(248, 113, 113, 0.1);
      border-color: rgba(248, 113, 113, 0.3);
      color: #f87171;
    }

    .menu-btn-danger:hover {
      background: rgba(248, 113, 113, 0.2);
    }

    .menu-btn:disabled {
      opacity: 0.4;
      cursor: not-allowed;
    }

    .menu-lock {
      margin-left: auto;
      font-size: 11px;
    }

    .menu-online {
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      color: #6b5f4e;
      margin-top: 8px;
    }

    /* ═══ PW MODALS ═══ */
    .pw-modal {
      position: fixed;
      inset: 0;
      z-index: 16000;
      display: flex;
      align-items: center;
      justify-content: center;
      background: rgba(0, 0, 0, 0.75);
    }

    .pw-modal-content {
      background: rgba(30, 24, 18, 0.98);
      border: 2px solid rgba(212, 162, 78, 0.4);
      border-radius: 14px;
      width: 560px;
      max-width: 95vw;
      max-height: 85vh;
      overflow-y: auto;
      box-shadow: 0 0 60px rgba(212, 162, 78, 0.15);
      font-family: 'JetBrains Mono', monospace;
    }

    /* Browse worlds needs a wider modal for the grid */
    #browse-worlds-modal .pw-modal-content {
      width: 720px;
    }

    .pw-modal-sm {
      width: 380px;
    }

    .pw-modal-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 14px 20px;
      border-bottom: 1px solid rgba(255, 255, 255, 0.08);
      font-size: 14px;
      font-weight: 600;
      color: #d4a24e;
    }

    .pw-modal-close {
      background: none;
      border: none;
      color: #8a7d6a;
      cursor: pointer;
      font-size: 18px;
    }

    .pw-modal-close:hover { color: #f87171; }

    .pw-modal-body {
      padding: 20px;
    }

    .pw-loading {
      text-align: center;
      color: #8a7d6a;
      padding: 40px;
      font-size: 12px;
    }

    /* ═══ AUTH FORM ═══ */
    .auth-field {
      margin-bottom: 12px;
    }

    .auth-field label {
      display: block;
      font-size: 10px;
      color: #8a7d6a;
      margin-bottom: 4px;
      text-transform: uppercase;
      letter-spacing: 0.5px;
    }

    .auth-field input {
      width: 100%;
      padding: 10px 14px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 8px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 13px;
      outline: none;
      transition: border-color 0.2s;
    }

    .auth-field input:focus {
      border-color: rgba(212, 162, 78, 0.5);
    }

    .auth-error {
      background: rgba(248, 113, 113, 0.1);
      border: 1px solid rgba(248, 113, 113, 0.3);
      border-radius: 8px;
      padding: 8px 12px;
      font-size: 11px;
      color: #f87171;
      margin-bottom: 8px;
    }

    .auth-divider {
      display: flex;
      align-items: center;
      gap: 12px;
      margin: 14px 0;
      color: #6b5f4e;
      font-size: 10px;
    }

    .auth-divider::before,
    .auth-divider::after {
      content: '';
      flex: 1;
      height: 1px;
      background: rgba(255, 255, 255, 0.08);
    }

    .auth-oauth {
      justify-content: center !important;
    }

    /* ═══ PROFILE ═══ */
    .profile-header {
      display: flex;
      align-items: center;
      gap: 16px;
      padding: 16px;
      background: rgba(212, 162, 78, 0.06);
      border: 1px solid rgba(212, 162, 78, 0.15);
      border-radius: 10px;
      margin-bottom: 16px;
    }

    .profile-avatar {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background: rgba(212, 162, 78, 0.2);
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 24px;
      flex-shrink: 0;
    }

    .profile-name {
      font-size: 16px;
      font-weight: 600;
      color: #ede4d4;
    }

    .profile-email {
      font-size: 11px;
      color: #8a7d6a;
      margin-top: 2px;
    }

    .profile-stats {
      font-size: 11px;
      color: #a89878;
      padding: 10px 0;
    }

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

    .profile-stat-card {
      display: flex;
      flex-direction: column;
      gap: 4px;
      padding: 10px;
      border-radius: 10px;
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.08);
    }

    .profile-stat-card .k {
      font-size: 10px;
      color: #8a7d6a;
    }

    .profile-stat-card .v {
      font-size: 14px;
      color: #ede4d4;
      font-weight: 700;
    }

    /* ═══ WORLD CARDS (Browse) ═══ */
    /* ═══ BROWSE WORLDS — Community Hub ═══ */
    .browse-controls {
      display: flex;
      flex-direction: column;
      gap: 10px;
      margin-bottom: 16px;
    }

    .browse-search-wrap {
      width: 100%;
    }

    .browse-search {
      width: 100%;
      padding: 10px 14px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 8px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 12px;
      outline: none;
      transition: border-color 0.2s;
      box-sizing: border-box;
    }

    .browse-search:focus {
      border-color: rgba(212, 162, 78, 0.5);
    }

    .browse-sort-row,
    .browse-filter-row {
      display: flex;
      align-items: center;
      gap: 6px;
      flex-wrap: wrap;
    }

    .browse-label {
      font-size: 10px;
      color: #6b5f4e;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      flex-shrink: 0;
    }

    .browse-pill {
      padding: 5px 10px;
      background: rgba(255, 255, 255, 0.04);
      border: 1px solid rgba(255, 255, 255, 0.1);
      border-radius: 20px;
      color: #8a7d6a;
      font-family: 'JetBrains Mono', monospace;
      font-size: 10px;
      cursor: pointer;
      transition: all 0.2s;
      white-space: nowrap;
    }

    .browse-pill:hover {
      background: rgba(212, 162, 78, 0.1);
      border-color: rgba(212, 162, 78, 0.3);
      color: #d4a24e;
    }

    .browse-pill.active {
      background: rgba(212, 162, 78, 0.15);
      border-color: rgba(212, 162, 78, 0.4);
      color: #d4a24e;
    }

    /* ═══ BROWSE GRID ═══ */
    .browse-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
      gap: 12px;
    }

    .browse-card {
      background: rgba(255, 255, 255, 0.03);
      border: 1px solid rgba(255, 255, 255, 0.08);
      border-radius: 10px;
      overflow: hidden;
      cursor: pointer;
      transition: all 0.25s ease;
    }

    .browse-card:hover {
      background: rgba(212, 162, 78, 0.08);
      border-color: rgba(212, 162, 78, 0.35);
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    }

    .browse-card-thumb {
      position: relative;
      width: 100%;
      aspect-ratio: 16 / 9;
      background: rgba(0, 0, 0, 0.3);
      overflow: hidden;
    }

    .browse-card-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    .browse-card-thumb-placeholder {
      width: 100%;
      height: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 32px;
      background: linear-gradient(135deg, rgba(212, 162, 78, 0.08), rgba(212, 162, 78, 0.02));
    }

    .browse-card-online {
      position: absolute;
      top: 6px;
      right: 6px;
      background: rgba(74, 222, 128, 0.2);
      border: 1px solid rgba(74, 222, 128, 0.4);
      border-radius: 12px;
      padding: 2px 8px;
      font-size: 10px;
      color: #4ade80;
    }

    .browse-card-body {
      padding: 10px 12px;
    }

    .browse-card-name {
      font-size: 13px;
      font-weight: 600;
      color: #ede4d4;
      margin-bottom: 4px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .browse-card-stats {
      display: flex;
      gap: 10px;
      font-size: 11px;
      color: #8a7d6a;
      margin-bottom: 4px;
    }

    .browse-card-badge {
      font-size: 10px;
      color: #6b5f4e;
    }

    /* ═══ WORLD DETAIL ═══ */
    .world-detail {
      display: flex;
      flex-direction: column;
      gap: 12px;
    }

    .world-detail-header {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .world-detail-title {
      font-size: 16px;
      font-weight: 700;
      color: #ede4d4;
    }

    .world-detail-thumb {
      width: 100%;
      border-radius: 10px;
      overflow: hidden;
      background: rgba(0, 0, 0, 0.3);
    }

    .world-detail-thumb img {
      width: 100%;
      max-height: 240px;
      object-fit: cover;
      display: block;
    }

    .world-detail-desc {
      font-size: 12px;
      color: #c4b8a4;
      font-style: italic;
      padding: 0 4px;
    }

    .world-detail-meta {
      display: flex;
      flex-direction: column;
      gap: 4px;
      font-size: 12px;
      color: #8a7d6a;
      padding: 0 4px;
    }

    .world-detail-tags {
      display: flex;
      flex-wrap: wrap;
      gap: 6px;
      align-items: center;
    }

    .browse-tag {
      background: rgba(212, 162, 78, 0.1);
      border: 1px solid rgba(212, 162, 78, 0.2);
      border-radius: 12px;
      padding: 2px 8px;
      font-size: 10px;
      color: #d4a24e;
    }

    .world-detail-actions {
      display: flex;
      flex-direction: column;
      gap: 8px;
      padding: 8px 0;
    }

    .world-detail-section {
      border-top: 1px solid rgba(255, 255, 255, 0.08);
      padding-top: 12px;
    }

    .world-detail-section-title {
      font-size: 12px;
      color: #d4a24e;
      font-weight: 600;
      margin-bottom: 8px;
    }

    /* ═══ REVIEWS ═══ */
    .review-item {
      padding: 8px 10px;
      background: rgba(255, 255, 255, 0.02);
      border-radius: 8px;
      margin-bottom: 6px;
    }

    .review-stars {
      font-size: 11px;
      margin-bottom: 2px;
    }

    .review-comment {
      font-size: 11px;
      color: #c4b8a4;
      font-style: italic;
      margin-bottom: 2px;
    }

    .review-author {
      font-size: 10px;
      color: #6b5f4e;
    }

    /* ═══ RATING FORM ═══ */
    .rating-form {
      background: rgba(212, 162, 78, 0.05);
      border: 1px solid rgba(212, 162, 78, 0.2);
      border-radius: 10px;
      padding: 14px;
      margin-top: 8px;
    }

    .rating-form-title {
      font-size: 12px;
      color: #d4a24e;
      font-weight: 600;
      margin-bottom: 10px;
    }

    .rating-stars-picker {
      display: flex;
      gap: 4px;
      margin-bottom: 10px;
    }

    .rating-star {
      font-size: 28px;
      cursor: pointer;
      color: rgba(255, 255, 255, 0.15);
      transition: color 0.15s, transform 0.15s;
      user-select: none;
    }

    .rating-star:hover,
    .rating-star.hover {
      color: rgba(212, 162, 78, 0.6);
      transform: scale(1.1);
    }

    .rating-star.active {
      color: #d4a24e;
    }

    .rating-comment {
      width: 100%;
      padding: 8px 10px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.12);
      border-radius: 8px;
      color: #ede4d4;
      font-family: 'JetBrains Mono', monospace;
      font-size: 11px;
      outline: none;
      resize: vertical;
      margin-bottom: 10px;
      box-sizing: border-box;
    }

    .rating-comment:focus {
      border-color: rgba(212, 162, 78, 0.5);
    }

    /* ═══ RESPONSIVE ═══ */
    @media (max-width: 480px) {
      .browse-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
      }
      .browse-card-name {
        font-size: 12px;
      }
      .browse-card-stats {
        font-size: 10px;
      }
    }

    /* ═══ BACK TO MENU BUTTON (in-game) ═══ */
    #back-to-menu-btn {
      position: fixed;
      top: 10px;
      right: 10px;
      z-index: 1200;
      padding: 6px 12px;
      background: rgba(30, 24, 18, 0.85);
      border: 1px solid rgba(212, 162, 78, 0.3);
      border-radius: 8px;
      color: #d4a24e;
      font-family: 'JetBrains Mono', monospace;
      font-size: 10px;
      cursor: pointer;
      display: none;
      transition: all 0.2s;
      backdrop-filter: blur(4px);
    }

    #back-to-menu-btn:hover {
      background: rgba(212, 162, 78, 0.2);
      border-color: rgba(212, 162, 78, 0.6);
    }

    /* ═══ MULTIPLAYER UI ═══ */

    /* Name entry overlay */
    #name-entry-overlay input:focus {
      border-color: rgba(212, 162, 78, 0.6) !important;
      box-shadow: 0 0 12px rgba(212, 162, 78, 0.15);
    }

    #name-entry-overlay button:hover {
      background: rgba(212, 162, 78, 0.3) !important;
    }

    /* Connection indicator */
    #mp-connection {
      backdrop-filter: blur(4px);
    }

    #mp-connection:hover {
      border-color: rgba(212, 162, 78, 0.4) !important;
      background: rgba(30, 24, 18, 0.95) !important;
    }

    /* Player list popup */
    #mp-player-list {
      backdrop-filter: blur(4px);
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    }

    /* Chat panel */
    #mp-chat-panel {
      backdrop-filter: blur(4px);
      scrollbar-width: thin;
      scrollbar-color: rgba(212, 162, 78, 0.2) transparent;
    }

    #mp-chat-panel::-webkit-scrollbar {
      width: 4px;
    }

    #mp-chat-panel::-webkit-scrollbar-thumb {
      background: rgba(212, 162, 78, 0.2);
      border-radius: 2px;
    }

    /* Chat input bar */
    #mp-chat-input-bar {
      backdrop-filter: blur(8px);
      box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.3);
    }

    #mp-chat-text:focus {
      outline: none;
    }

    /* Chat input animation */
    #mp-chat-input-bar {
      animation: chatSlideIn 0.15s ease-out;
    }

    @keyframes chatSlideIn {
      from { transform: translateY(10px); opacity: 0; }
      to { transform: translateY(0); opacity: 1; }
    }
  
    /* ═══ UTILITY CLASSES (replacing inline styles) ═══ */
    .pw-btn-icon { background:none; border:none; cursor:pointer; font-size:14px; padding:2px; color:var(--pw-text-faint); }
    .pw-btn-icon:hover { color:var(--pw-accent); }
    .pw-btn-icon-sm { background:none; border:none; cursor:pointer; font-size:12px; padding:2px; color:var(--pw-text-faint); }
    .pw-btn-icon-sm:hover { color:var(--pw-danger); }
    .pw-full-mb { width:100%; margin-bottom:6px; }
    .pw-menu-opt { padding:6px 12px; color:var(--pw-text-dim); cursor:pointer; font-size:11px; }
    .pw-menu-opt:hover { background:rgba(var(--pw-accent-rgb),0.15); }
    .pw-img-40 { width:40px; height:40px; object-fit:contain; image-rendering:pixelated; }
    .pw-img-32 { width:32px; height:32px; object-fit:contain; image-rendering:pixelated; }
    .pw-img-24 { width:24px; height:24px; object-fit:contain; image-rendering:pixelated; }
    .pw-thumb { width:24px; height:24px; border-radius:4px; overflow:hidden; flex-shrink:0; }
    .pw-flex-fill { flex:1; min-width:0; }
    .pw-section-title { font-size:11px; color:var(--pw-accent); font-weight:600; margin:8px 0 6px; }
    .pw-section-divider { border-top:1px solid rgba(255,255,255,0.08); margin-top:10px; padding-top:10px; }
    .pw-row { display:flex; align-items:center; gap:6px; }
    .pw-row-between { display:flex; align-items:center; justify-content:space-between; margin-bottom:6px; }
    .pw-row-wrap { display:flex; flex-wrap:wrap; gap:2px; margin-bottom:6px; }
    .pw-list { display:flex; flex-direction:column; gap:3px; }
    .pw-list-scroll { display:flex; flex-direction:column; gap:3px; max-height:40vh; overflow-y:auto; }
    .pw-list-item { display:flex; align-items:center; gap:6px; padding:4px 8px; background:rgba(255,255,255,0.03); border:1px solid rgba(255,255,255,0.06); border-radius:6px; font-size:11px; color:var(--pw-text-dim); }
    .pw-list-item:hover { background:rgba(var(--pw-accent-rgb),0.1); }
    .pw-hint { font-size:9px; color:var(--pw-text-ghost); }
    .pw-badge { font-size:9px; color:var(--pw-text-faint); }
    .pw-success { margin-top:6px; color:var(--pw-success); }
    .pw-ctx-menu { position:fixed; background:rgba(30,24,18,0.97); border:1px solid rgba(var(--pw-accent-rgb),0.4); border-radius:6px; z-index:3000; padding:4px 0; font-family:var(--pw-font); font-size:11px; min-width:160px; }

/* ═══ Create World — Button Group ═══ */
.create-btn-group { display:flex; gap:6px; flex-wrap:wrap; }
.create-btn-group .create-option {
  padding:6px 14px; border-radius:6px; border:1px solid rgba(212,162,78,0.3);
  background:rgba(255,255,255,0.04); color:#ede4d4; font-family:var(--pw-font,'JetBrains Mono',monospace);
  font-size:12px; cursor:pointer; transition:all 0.15s;
}
.create-btn-group .create-option:hover { border-color:rgba(212,162,78,0.5); background:rgba(212,162,78,0.08); }
.create-btn-group .create-option.active { border-color:rgba(212,162,78,0.8); background:rgba(212,162,78,0.15); color:#d4a24e; font-weight:600; }
.create-size-input {
  padding:6px 8px; border-radius:6px; border:1px solid rgba(212,162,78,0.3);
  background:rgba(255,255,255,0.04); color:#ede4d4; font-family:var(--pw-font,'JetBrains Mono',monospace);
  font-size:12px; outline:none;
}
.create-size-input:focus { border-color:rgba(212,162,78,0.6); }
