@font-face {
  font-family: 'PixelFont';
  src: url('assets/font.woff2') format('woff2');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
* { 
  margin: 0; padding: 0; box-sizing: border-box;
  font-family: 'PixelFont', monospace;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-smooth: never;
  text-rendering: geometricPrecision;
}
body { 
  background: #1a1a2e; 
  min-height: 100vh;
  font-family: 'PixelFont', monospace; 
  font-size: 10px;
  color: #eee;
  padding-top: 20px;
  margin: 0;
}

h1 { 
  margin: 0 auto 20px auto; 
  font-size: 20px;
  text-shadow: 2px 2px 0 #888;
  width: fit-content;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}
#game { 
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid #333; border-radius: 4px;
  box-shadow: 0 0 30px rgba(0,0,0,0.6); cursor: crosshair;
}
canvas {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.canvas-wrapper {
  position: relative;
  display: inline-block;
}
.name-overlay {
  position: absolute;
  top: 3px; left: 3px; /* Account for canvas border */
  pointer-events: none;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}
.player-name {
  position: absolute;
  font-family: 'PixelFont', monospace;
  font-size: 10px;
  white-space: nowrap;
  z-index: 10;
  image-rendering: pixelated;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}
.player-name.local { color: #0f0; text-shadow: 2px 2px 0 #070; }
.player-name.remote { color: #fff; text-shadow: 2px 2px 0 #888; }
.controls { 
  margin: 8px auto 0 auto;
  background: rgba(0,0,0,0.3); padding: 6px 10px;
  border-radius: 4px; font-size: 10px;
  width: fit-content;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}
.controls p { margin: 2px 0; opacity: 0.9; }
.controls strong { color: #7dd; text-shadow: 1px 1px 0 #3a6a6a; }
.section { display: inline-block; margin: 0 8px; padding: 2px 6px;
  background: rgba(0,0,0,0.2); border-radius: 4px; vertical-align: top; }
.section-title { color: #fa0; font-weight: bold; margin-bottom: 2px; text-shadow: 1px 1px 0 #853; }
.debug { position: fixed; bottom: 10px; left: 10px; color: #0f0; 
  font-family: 'PixelFont', monospace; font-size: 10px;
  background: rgba(0,0,0,0.85); padding: 10px; border-radius: 4px;
  text-shadow: 2px 2px 0 #070; transform: scale(1); transform-origin: bottom left;
  width: fit-content; white-space: nowrap; z-index: 50; }
.legend { position: fixed; top: 10px; right: 10px; font-family: 'PixelFont', monospace;
  font-size: 10px; background: rgba(0,0,0,0.85); padding: 10px; border-radius: 4px;
  transform: scale(1); transform-origin: top right; }
.legend.hidden { display: none; }
.legend-item { display: flex; align-items: center; justify-content: flex-start; gap: 6px; cursor: pointer; 
  padding: 3px 5px; margin: 1px -5px; border-radius: 3px; transition: background 0.15s; }
.legend-item:hover { background: rgba(255,255,255,0.1); }
.legend-item.selected { background: rgba(255,170,0,0.3); outline: 2px solid #fa0; }
.legend-color { width: 14px; height: 14px; border: 1px solid #555; }

/* Tabbed Edit Panel */
.edit-panel { position: fixed; top: 40px; right: 10px; bottom: 10px; font-family: 'PixelFont', monospace;
  font-size: 10px; background: rgba(0,0,0,0.85); padding: 0; border-radius: 4px;
  transform: scale(1); transform-origin: top right; min-width: 200px; max-width: 220px;
  display: flex; flex-direction: column; overflow: hidden; }
.edit-panel.hidden { display: none; }
.edit-tabs { display: flex; border-bottom: 1px solid #444; }
.edit-tab { flex: 1; padding: 8px 12px; background: transparent; border: none;
  color: #888; cursor: pointer; font-size: 10px; font-family: 'PixelFont', monospace;
  transition: all 0.15s; border-radius: 4px 4px 0 0; }
.edit-tab:hover { color: #ccc; background: rgba(255,255,255,0.05); }
.edit-tab.active { color: #fa0; background: rgba(255,170,0,0.15); 
  text-shadow: 1px 1px 0 #853; }
.edit-tab-content { padding: 10px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.edit-tab-content.hidden { display: none; }
.global-undo-row { display: flex; gap: 4px; padding: 6px 10px; border-bottom: 1px solid #333;
  background: rgba(0,0,0,0.3); flex-shrink: 0; }
.global-undo-btn { padding: 4px 10px; border: none; border-radius: 3px;
  background: #444; color: #aaa; font-size: 10px; cursor: pointer;
  font-family: 'PixelFont', monospace; transition: all 0.15s; }
.global-undo-btn:hover:not(:disabled) { background: #555; color: #fff; }
.global-undo-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Tileset Tab Styles */
.tileset-subtabs { display: flex; gap: 2px; margin-bottom: 8px; }
.tileset-subtab { flex: 1; padding: 4px 6px; background: #333; border: none;
  color: #888; cursor: pointer; font-size: 10px; font-family: 'PixelFont', monospace;
  border-radius: 3px; transition: all 0.15s; }
.tileset-subtab:hover { color: #ccc; background: #444; }
.tileset-subtab.active { color: #7dd; background: rgba(100,180,220,0.2); }
.tileset-subtab-content { display: none; }
.tileset-subtab-content.active { display: block; }

/* Tileset + Collision Row Layout */
.tileset-collision-row { display: flex; gap: 6px; margin-bottom: 4px; flex-shrink: 0; }
.tileset-viewport-column { flex: 1; min-width: 0; }
.collision-palette-column { flex-shrink: 0; width: 52px; }
.collision-palette { display: flex; flex-direction: column; gap: 0px; align-items: flex-start; }
.collision-palette .legend-item { padding: 1px 2px; margin: 0; font-size: 7px; gap: 2px; justify-content: flex-start; width: 100%; }
.collision-palette .legend-color { width: 10px; height: 10px; flex-shrink: 0; }

/* Browse Top Row with Tile Preview */
.browse-top-row { display: flex; gap: 10px; margin-bottom: 8px; align-items: flex-start; }
.tile-preview-large { flex-shrink: 0; }
.tile-preview-large canvas { display: block; border: 1px solid #444; border-radius: 3px;
  image-rendering: pixelated; background: #111; }
.browse-top-info { flex: 1; display: flex; flex-direction: column; gap: 4px; }

/* Tileset Viewport with Scrollbar */
.tileset-viewport-wrapper { 
  border: 1px solid #444; border-radius: 3px; margin-bottom: 8px;
  overflow: scroll; background: #111; position: relative; height: 256px; max-width: 100%; }
.tileset-viewport-wrapper canvas { display: block; cursor: crosshair; }
.tileset-viewport-wrapper::-webkit-scrollbar { width: 8px; height: 8px; }
.tileset-viewport-wrapper::-webkit-scrollbar-track { background: #222; }
.tileset-viewport-wrapper::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
.tileset-viewport-wrapper::-webkit-scrollbar-thumb:hover { background: #666; }


.tile-info { display: flex; gap: 10px; color: #aaa; font-size: 10px; }
.tile-info span { color: #7dd; }
.tileset-controls { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.tileset-zoom-btn { width: 20px; height: 20px; border: none; border-radius: 3px;
  background: #444; color: #fff; font-size: 16px; font-weight: bold; cursor: pointer;
  display: flex; justify-content: center; align-items: center;
  line-height: 1; padding: 0; font-family: Arial, sans-serif; }
.tileset-zoom-btn:hover { background: #555; }
.tileset-action-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.tile-selection-info { color: #8f8; font-size: 10px; min-height: 14px; flex: 1; }
.merge-btn { padding: 2px 8px; border: none; border-radius: 3px;
  background: #c44; color: #fff; font-size: 9px; cursor: pointer;
  font-family: 'PixelFont', monospace; transition: all 0.15s; flex-shrink: 0; }
.merge-btn:hover { background: #e55; }
.merge-btn.hidden { display: none; }

/* Pixel Editor Styles */
.pixel-editor-container { border: 1px solid #444; border-radius: 3px; 
  background: #111; margin-bottom: 8px; overflow: hidden; width: 100%; }
.pixel-editor-container canvas { display: block; cursor: crosshair; }
.pixel-editor-scroll { width: 100%; max-height: 220px; overflow: auto; 
  background: #111; border: 1px solid #333; }
.pixel-editor-scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.pixel-editor-scroll::-webkit-scrollbar-track { background: #222; }
.pixel-editor-scroll::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
.pixel-editor-scroll::-webkit-scrollbar-thumb:hover { background: #666; }
.pixel-editor-scroll::-webkit-scrollbar-corner { background: #222; }
.pixel-zoom-row { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; font-size: 10px; color: #aaa; }
.pixel-zoom-row span:first-child { flex: 1; }
.pixel-zoom-row span { min-width: 24px; text-align: center; }
.pixel-zoom-btn { width: 20px; height: 20px; border: none; border-radius: 3px;
  background: #444; color: #fff; font-size: 16px; font-weight: bold; cursor: pointer;
  display: flex; justify-content: center; align-items: center;
  line-height: 1; padding: 0; font-family: Arial, sans-serif; }
.pixel-zoom-btn:hover { background: #555; }
.pixel-tools { display: flex; gap: 2px; margin-bottom: 8px; flex-wrap: wrap; }
.pixel-tool-btn { width: 28px; height: 28px; border: none; border-radius: 3px;
  background: #333; color: #fff; cursor: pointer;
  text-align: center; line-height: 26px; font-size: 15px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  transition: all 0.15s; }
.pixel-tool-btn:hover { background: #444; }
.pixel-tool-btn.active { background: rgba(255,170,0,0.3); outline: 2px solid #fa0; }
.pixel-color-row { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.pixel-color-input { width: 32px; height: 24px; border: none; border-radius: 3px;
  cursor: pointer; padding: 0; }
.pixel-color-preview { width: 24px; height: 24px; border: 1px solid #555; border-radius: 3px; }
.pixel-editor-actions { display: flex; gap: 4px; margin-top: 8px; flex-wrap: nowrap; }
.pixel-action-btn { padding: 4px 6px; border: none; border-radius: 3px;
  font-size: 9px; cursor: pointer; font-family: 'PixelFont', monospace; white-space: nowrap; }
.pixel-action-btn.apply { background: #4a7c2d; color: #fff; }
.pixel-action-btn.apply:hover { background: #5a9c3d; }
.pixel-action-btn.cancel { background: #7c2d2d; color: #fff; }
.pixel-action-btn.cancel:hover { background: #9c3d3d; }
.pixel-action-btn.undo { background: #555; color: #fff; }
.pixel-action-btn.undo:hover { background: #666; }
.pixel-action-btn.import { background: #2d5a7c; color: #fff; }
.pixel-action-btn.import:hover { background: #3d7a9c; }

/* Color Palette */
.pixel-palette { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 8px; align-items: center; }
.palette-color { width: 16px; height: 16px; border: 1px solid #333; border-radius: 2px;
  cursor: pointer; transition: all 0.1s; }
.palette-color:hover { transform: scale(1.15); border-color: #888; }
.palette-color.selected { outline: 2px solid #fa0; outline-offset: 1px; }
.palette-add-btn { width: 16px; height: 16px; border: 1px dashed #666; border-radius: 2px;
  background: transparent; color: #666; cursor: pointer; font-size: 14px; font-weight: bold;
  display: flex; justify-content: center; align-items: center;
  line-height: 1; padding: 0; font-family: Arial, sans-serif; }
.palette-add-btn:hover { border-color: #aaa; color: #aaa; }

/* Pixel Editor Context Menu */
.pixel-context-menu { position: fixed; background: #2a2a2a; border: 1px solid #444;
  border-radius: 4px; padding: 4px 0; z-index: 10000; min-width: 120px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.pixel-context-menu.hidden { display: none; }
.pixel-context-item { padding: 6px 12px; color: #ccc; font-size: 11px; cursor: pointer;
  font-family: 'PixelFont', monospace; display: flex; justify-content: space-between; }
.pixel-context-item:hover { background: #444; color: #fff; }
.pixel-context-item.disabled { color: #666; pointer-events: none; }
.pixel-context-separator { height: 1px; background: #444; margin: 4px 0; }
.pixel-context-shortcut { color: #888; font-size: 9px; margin-left: 12px; }

/* Tag Filter and Edit Section */
.tag-filter-section { margin-top: 4px; border-top: 1px solid #333; padding-top: 3px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tag-section-row { display: flex; gap: 3px; flex: 1; min-height: 0; }
.tag-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tag-column-title { color: #555; font-size: 6px; margin-bottom: 1px; text-align: center; text-transform: uppercase; flex-shrink: 0; }
.tag-list { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; padding-right: 6px; }
.tag-list::-webkit-scrollbar { width: 4px; }
.tag-list::-webkit-scrollbar-track { background: #1a1a1a; }
.tag-list::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }
.tag-filter-btn { padding: 0px 3px; border: none; border-radius: 1px;
  background: #2a2a2a; color: #777; font-size: 7px; cursor: pointer;
  font-family: 'PixelFont', monospace; transition: all 0.15s; text-align: left;
  display: flex; align-items: center; gap: 3px; min-height: 17px; }
.tag-filter-btn:hover { background: #3a3a3a; color: #999; }
.tag-filter-btn.highlight { background: rgba(255,170,0,0.25); color: #fa0; }
.tag-filter-btn.only { background: rgba(100,200,100,0.3); color: #8f8; }
.tag-edit-list { display: flex; flex-direction: column; gap: 1px; flex: 1; overflow-y: auto; padding-right: 6px; }
.tag-edit-list::-webkit-scrollbar { width: 4px; }
.tag-edit-list::-webkit-scrollbar-track { background: #1a1a1a; }
.tag-edit-list::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }
.tag-edit-btn { padding: 0px 3px; border: none; border-radius: 1px;
  background: #2a2a2a; color: #777; font-size: 7px; cursor: pointer;
  font-family: 'PixelFont', monospace; transition: all 0.15s; text-align: left;
  display: flex; align-items: center; gap: 3px; min-height: 17px; }
.tag-edit-btn:hover:not(.disabled) { background: #3a3a3a; color: #999; }
.tag-edit-btn.active { background: rgba(100,200,100,0.25); color: #8f8; }
.tag-edit-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.tag-edit-btn.selected { outline: 1px solid #fa0; }
.tag-icon { width: 16px; height: 16px; border: 1px solid #444; border-radius: 1px; flex-shrink: 0; image-rendering: pixelated; }

/* Section divider */
.section-divider { height: 1px; background: #444; margin: 6px 0; flex-shrink: 0; }

/* Pixel editor section - fixed size at top */
.pixel-editor-section { flex-shrink: 0; }

/* Browse section - can flex and scroll */
.browse-section { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* Compact browse row */
.browse-compact-row { display: flex; gap: 4px; align-items: center; margin-bottom: 3px; flex-shrink: 0; }
.browse-compact-row .tile-preview-large canvas { width: 32px; height: 32px; }
.browse-compact-info { flex: 1; font-size: 7px; color: #888; }
.browse-compact-info div { margin-bottom: 0px; }
.tileset-controls { display: flex; gap: 2px; align-items: center; }
.tileset-zoom-btn { width: 14px; height: 14px; font-size: 10px; padding: 0; }

/* Tileset collision row in browse section */
.browse-section .tileset-collision-row { flex-shrink: 0; }

/* Stamp Preview Overlay */
.stamp-preview { position: absolute; pointer-events: none; opacity: 0.6;
  border: 2px dashed #fa0; box-sizing: border-box; }

/* Admin Panel */
.admin-panel { position: fixed; top: 10px; left: 10px; font-family: 'PixelFont', monospace;
  font-size: 10px; background: rgba(139, 0, 0, 0.9); padding: 10px; border-radius: 4px;
  border: 2px solid #f44; z-index: 200; min-width: 160px; }
.admin-panel.hidden { display: none; }
.admin-title { color: #ff8; font-weight: bold; margin-bottom: 8px; 
  display: flex; align-items: center; gap: 6px; }
.admin-btn { width: 100%; padding: 6px 8px; margin-bottom: 4px; border: none;
  border-radius: 3px; font-size: 10px; cursor: pointer; text-align: left;
  font-family: 'PixelFont', monospace; transition: all 0.15s; }
.admin-btn.danger { background: #c00; color: #fff; }
.admin-btn.danger:hover { background: #f00; }
.admin-btn.upload { background: #555; color: #fff; }
.admin-btn.upload:hover { background: #666; }
.admin-status { color: #8f8; font-size: 10px; margin-top: 8px; min-height: 14px; }
.admin-status.error { color: #f88; }
.admin-file-input { display: none; }

/* Asset Manager Panel */
.bottom-buttons {
  position: fixed; top: 10px; right: 10px;
  display: flex; gap: 4px; z-index: 150;
}
.collision-editor-btn {
  background: rgba(138, 43, 226, 0.9); color: white;
  border: none; border-radius: 4px; padding: 4px 8px;
  cursor: pointer; font-size: 10px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  text-shadow: 1px 1px 0 #430a70;
  height: 22px; box-sizing: border-box;
}
.collision-editor-btn:hover { background: rgba(158, 63, 246, 0.95); }
.collision-editor-btn.active { background: rgba(255, 170, 0, 0.9); }
.collision-editor-btn.active:hover { background: rgba(255, 190, 50, 0.95); }
.collision-editor-btn canvas { display: block; }
.asset-manager-btn {
  background: rgba(74, 124, 45, 0.9); color: white;
  border: none; border-radius: 4px; padding: 4px 8px;
  cursor: pointer; font-size: 10px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  text-shadow: 1px 1px 0 #253d17;
  height: 22px; box-sizing: border-box;
}
.asset-manager-btn:hover { background: rgba(90, 156, 61, 0.95); }
.asset-manager-btn canvas { display: block; }
.settings-btn {
  background: rgba(100, 100, 100, 0.9); color: white;
  border: none; border-radius: 4px; padding: 0;
  cursor: pointer;
  height: 22px; width: 22px; box-sizing: border-box;
  text-align: center;
  line-height: 20px;
  font-size: 13px;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
}
.settings-btn:hover { background: rgba(130, 130, 130, 0.95); }
.settings-btn.active { background: rgba(255, 170, 0, 0.9); }
.settings-panel {
  position: fixed; top: 40px; right: 10px;
  background: rgba(30, 30, 50, 0.95); border-radius: 6px;
  padding: 8px 12px; z-index: 150;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}
.settings-panel.hidden { display: none; }
.settings-row {
  display: flex; align-items: center; gap: 10px;
  padding: 5px 0; font-size: 10px; color: #eee;
}
.settings-toggle {
  width: 36px; height: 20px; background: #444; border-radius: 10px;
  position: relative; cursor: pointer; transition: background 0.2s;
}
.settings-toggle.on { background: #4a7c2d; }
.settings-toggle::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  transition: left 0.2s;
}
.settings-toggle.on::after { left: 18px; }
.settings-zoom {
  display: flex; align-items: center; gap: 8px;
}
.settings-zoom-btn {
  width: 24px; height: 24px; border: none; border-radius: 4px;
  background: #4a7c2d; color: white; font-size: 18px; font-weight: bold;
  cursor: pointer; display: flex; justify-content: center; align-items: center;
  line-height: 1; padding: 0; font-family: Arial, sans-serif;
}
.settings-zoom-btn:hover { background: #5a9c3d; }
.settings-zoom-btn:active { transform: scale(0.95); }
.settings-zoom-level {
  min-width: 30px; text-align: center; font-size: 10px; color: #eee;
}
.asset-panel { 
  position: fixed; top: 40px; right: 10px;
  background: rgba(30, 30, 50, 0.95); border-radius: 6px;
  padding: 12px; z-index: 150; 
  width: fit-content;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
}
.asset-panel.hidden { display: none; }
.asset-panel h3 { margin: 0 0 15px 0; color: #fa0; font-size: 10px; text-shadow: 2px 2px 0 #853; }
.asset-section { margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.asset-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.asset-section-title { font-size: 10px; color: #7dd; margin-bottom: 8px; font-weight: bold; text-shadow: 2px 2px 0 #3a6a6a; }
.asset-btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.asset-btn {
  flex: 1; padding: 8px 12px; border: none; border-radius: 5px;
  cursor: pointer; font-size: 10px; transition: all 0.2s;
}
.asset-btn.download { background: #2a5a8a; color: white; text-shadow: 2px 2px 0 #152d45; }
.asset-btn.download:hover { background: #3a7aba; }
.asset-btn.upload { background: #5a3a8a; color: white; text-shadow: 2px 2px 0 #2d1d45; }
.asset-btn.upload:hover { background: #7a4aba; }
.asset-file-input { display: none; }
.asset-status { font-size: 10px; color: #8f8; margin-top: 5px; min-height: 14px; text-shadow: 2px 2px 0 #474; }
.asset-status.error { color: #f88; text-shadow: 2px 2px 0 #844; }
.asset-info { font-size: 10px; color: #888; margin-top: 4px; text-shadow: 2px 2px 0 #444; }
.loading { position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: #1a1a2e; display: flex; flex-direction: column;
  justify-content: center; align-items: center; font-size: 10px; z-index: 300;
  text-shadow: 2px 2px 0 #888; }
.loading.hidden { display: none; }
#joinModal { position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.8); display: flex; justify-content: center;
  align-items: center; z-index: 200; padding: 20px; }
#joinModal.hidden { display: none; }
.modal-content { background: #2a2a4e; padding: 60px 70px; border-radius: 10px;
  width: 100%; max-width: 620px;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1); }
.modal-content h2 { 
  margin: 0 auto 50px auto; 
  font-size: 20px; 
  text-shadow: 2px 2px 0 #888; 
  width: fit-content;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}
.modal-content input { padding: 10px; font-size: 10px; width: 100%;
  margin-bottom: 15px; border-radius: 5px; border: none; display: block;
  font-family: 'PixelFont', monospace;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1); }
.modal-content button { padding: 10px 20px; font-size: 10px; width: 100%;
  background: #4a7c2d; color: white; border: none; border-radius: 5px;
  cursor: pointer; margin-top: 5px; font-family: 'PixelFont', monospace;
  text-shadow: 2px 2px 0 #253d17;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1); }
.modal-content button:hover { background: #5a9c3d; }
.online-count { position: fixed; top: 10px; left: 10px;
  background: rgba(0,100,0,0.8); padding: 8px 12px; border-radius: 20px;
  font-size: 10px; transform: scale(1); transform-origin: top left;
  text-shadow: 2px 2px 0 #030; width: fit-content; display: flex; align-items: center; gap: 4px; }
.online-count canvas { display: block; }
.online-count.hidden { display: none; }

.game-container { 
  display: block; 
  width: fit-content;
  margin: 0 auto;
  text-align: left;
  -webkit-font-smoothing: antialiased;
  filter: contrast(1);
}

/* Mobile Touch Controls */
.touch-controls { display: none; }
.touch-controls.hidden { display: none !important; }

/* Mobile Portrait Mode */
@media (pointer: coarse) and (orientation: portrait), (max-width: 768px) and (orientation: portrait) {
  body { padding-top: 40px; }
  h1 { font-size: 10px; margin-bottom: 8px; }
  .controls { display: none; }
  .bottom-buttons { top: 10px; right: 10px; }
  .collision-editor-btn { padding: 4px 8px; }
  .asset-manager-btn { padding: 4px 8px; }
  .settings-btn { padding: 0; }
  .settings-panel { bottom: auto; top: 40px; right: 10px; }
  .asset-panel { bottom: auto; top: 40px; right: 10px; width: fit-content; }
  .legend { top: 40px; right: 10px; font-size: 10px; padding: 8px; }
  .edit-panel { top: 40px; right: 10px; bottom: 10px; font-size: 10px; }
  .online-count { top: 10px; right: auto; left: 10px; width: fit-content; }
  
  /* Debug info - hide on mobile for performance */
  .debug { 
    display: none;
  }
  
  .game-container { 
    display: flex;
    flex-direction: column;
    align-items: center;
    width: fit-content;
    margin: 0 auto;
  }
  
  .canvas-wrapper {
    max-width: calc(100vw - 20px);
  }
  
  #game {
    max-width: 100% !important;
    height: auto !important;
  }
  
  .name-overlay {
    /* Scale overlay to match CSS-scaled canvas */
    transform-origin: top left;
  }
  
  .touch-controls {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 50vh;
    background: linear-gradient(to top, rgba(0,0,0,0.6) 0%, rgba(0,0,0,0.3) 80%, transparent 100%);
    padding: 10px; z-index: 100;
  }
  
  .dpad-container { width: 50%; display: flex; justify-content: center; align-items: center; }
  .action-container { width: 50%; display: flex; justify-content: center; align-items: center; }
  
  /* Maximize D-pad: largest square that fits in left half without overflow */
  .dpad { 
    position: relative; 
    --dpad-size: min(calc(50vw - 30px), calc(50vh - 30px));
    width: var(--dpad-size); 
    height: var(--dpad-size); 
  }
  .dpad-btn { 
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.25);
    -webkit-user-select: none; user-select: none; 
    touch-action: manipulation;
    border: none;
  }
  .dpad-btn:active, .dpad-btn.active { background: rgba(255,255,255,0.5); }
  
  /* Triangle clip-paths - pizza slice style meeting at center */
  .dpad-up { 
    clip-path: polygon(0% 0%, 100% 0%, 50% 50%);
    padding-bottom: 20%;
  }
  .dpad-down { 
    clip-path: polygon(100% 100%, 0% 100%, 50% 50%);
    padding-top: 20%;
  }
  .dpad-left { 
    clip-path: polygon(0% 100%, 0% 0%, 50% 50%);
    padding-right: 20%;
  }
  .dpad-right { 
    clip-path: polygon(100% 0%, 100% 100%, 50% 50%);
    padding-left: 20%;
  }
  
  /* Subtle borders between triangles */
  .dpad::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(45deg, transparent 49%, rgba(255,255,255,0.3) 49%, rgba(255,255,255,0.3) 51%, transparent 51%),
                linear-gradient(-45deg, transparent 49%, rgba(255,255,255,0.3) 49%, rgba(255,255,255,0.3) 51%, transparent 51%);
    pointer-events: none;
  }
  
  .dpad-center { display: none; }
  
  .action-btns { display: flex; flex-direction: column; gap: 5vw; }
  .action-btn { width: 22vw; height: 22vw; border-radius: 50%; 
    font-size: 10vw; font-weight: bold; display: flex; justify-content: center; 
    align-items: center; color: #fff; -webkit-user-select: none; user-select: none; 
    touch-action: manipulation; border: 5px solid rgba(255,255,255,0.6); 
    box-shadow: 0 6px 12px rgba(0,0,0,0.3);
    font-family: Arial, sans-serif; line-height: 1; box-sizing: border-box; }
  .action-btn:active, .action-btn.active { transform: scale(0.95); }
  .btn-a { background: rgba(50,150,220,0.7); }
  .btn-b { background: rgba(220,50,50,0.7); }
  
  /* Start/Select buttons at very bottom */
  .menu-btns-container {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    z-index: 101;
    pointer-events: auto;
  }
  .menu-btn {
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(80, 80, 80, 0.8);
    color: #fff;
    font-size: 12px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    border: 2px solid rgba(255,255,255,0.4);
    letter-spacing: 1px;
  }
  .menu-btn:active, .menu-btn.active {
    background: rgba(120, 120, 120, 0.9);
    transform: scale(0.95);
  }
}

/* Mobile Landscape Mode */
@media (pointer: coarse) and (orientation: landscape), (max-width: 1024px) and (orientation: landscape) and (max-height: 500px) {
  html, body { 
    height: 100vh; /* Fallback */
    height: 100dvh; 
    overflow: hidden;
    margin: 0;
    padding: 0;
  }
  h1 { display: none; }
  .controls { display: none; }
  .bottom-buttons { display: none; }
  .asset-panel { display: none; }
  .legend { display: none; }
  .edit-panel { display: none; }
  .admin-panel { display: none; }
  
  /* Small debug info - hide on mobile for performance */
  .debug {
    display: none;
  }
  
  /* Small online count - fit to text */
  .online-count {
    position: fixed;
    top: 5px; left: 5px;
    transform: scale(0.6);
    transform-origin: top left;
    font-size: 10px;
    padding: 3px 6px;
    z-index: 150;
    width: fit-content;
  }
  
  .online-count canvas {
    flex-shrink: 0;
  }
  
  .game-container {
    width: 100%;
    height: 100vh; /* Fallback */
    height: 100dvh;
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
  }
  
  .canvas-wrapper {
    height: 100vh; /* Fallback */
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  
  /* Scale canvas to fill full vertical height, width scales proportionally (240:160 = 1.5:1) */
  #game {
    height: 100vh !important; /* Fallback */
    height: 100dvh !important;
    width: auto !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  
  .touch-controls {
    display: flex; position: fixed; top: 0; bottom: 0; left: 0; right: 0;
    justify-content: space-between; align-items: center;
    padding: 15px; z-index: 100; pointer-events: none;
  }
  
  .dpad-container { pointer-events: auto; display: flex; justify-content: flex-start; align-items: center; }
  .action-container { pointer-events: auto; display: flex; justify-content: flex-end; align-items: center; }
  
  /* Maximize D-pad: fill available height, but cap at 1/3 screen width */
  .dpad { 
    position: relative; 
    --dpad-size: min(calc(100vh - 30px), 33vw);
    width: var(--dpad-size); 
    height: var(--dpad-size); 
  }
  .dpad-btn { 
    position: absolute; 
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.25);
    -webkit-user-select: none; user-select: none; 
    touch-action: manipulation;
    border: none; border-radius: 0;
    transform: none;
  }
  .dpad-btn:active, .dpad-btn.active { background: rgba(255,255,255,0.5); }
  
  .dpad-up { 
    clip-path: polygon(0% 0%, 100% 0%, 50% 50%);
    padding-bottom: 20%;
  }
  .dpad-down { 
    clip-path: polygon(100% 100%, 0% 100%, 50% 50%);
    padding-top: 20%;
  }
  .dpad-left { 
    clip-path: polygon(0% 100%, 0% 0%, 50% 50%);
    padding-right: 20%;
  }
  .dpad-right { 
    clip-path: polygon(100% 0%, 100% 100%, 50% 50%);
    padding-left: 20%;
  }
  
  .dpad::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(45deg, transparent 49%, rgba(255,255,255,0.3) 49%, rgba(255,255,255,0.3) 51%, transparent 51%),
                linear-gradient(-45deg, transparent 49%, rgba(255,255,255,0.3) 49%, rgba(255,255,255,0.3) 51%, transparent 51%);
    pointer-events: none;
  }
  
  .dpad-center { display: none; }
  
  /* Action buttons also scale with viewport height */
  .action-btns { display: flex; flex-direction: column; gap: 15px; align-items: center; }
  .action-btn { 
    --btn-size: min(80px, calc(45vh - 20px));
    width: var(--btn-size); height: var(--btn-size); border-radius: 50%; 
    font-size: calc(var(--btn-size) * 0.35); font-weight: bold; display: flex; justify-content: center; 
    align-items: center; color: #fff; -webkit-user-select: none; user-select: none; 
    touch-action: manipulation; border: 4px solid rgba(255,255,255,0.6); 
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    font-family: Arial, sans-serif; line-height: 1; box-sizing: border-box; }
  .action-btn:active, .action-btn.active { transform: scale(0.95); }
  .btn-a { background: rgba(50,150,220,0.7); }
  .btn-b { background: rgba(220,50,50,0.7); }
  
  /* Start/Select buttons at bottom center in landscape */
  .menu-btns-container {
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
    z-index: 101;
    pointer-events: auto;
  }
  .menu-btn {
    padding: 6px 12px;
    border-radius: 15px;
    background: rgba(80, 80, 80, 0.7);
    color: #fff;
    font-size: 10px;
    font-weight: bold;
    font-family: Arial, sans-serif;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
    border: 2px solid rgba(255,255,255,0.4);
    letter-spacing: 1px;
  }
  .menu-btn:active, .menu-btn.active {
    background: rgba(120, 120, 120, 0.9);
    transform: scale(0.95);
  }
}

/* Fullscreen mode - canvas overlays everything (must override media queries) */
body.fullscreen-mode { overflow: hidden; margin: 0; padding: 0; }
body.fullscreen-mode .game-container,
body.fullscreen-mode .canvas-wrapper {
  position: static !important;
  transform: none !important;
  margin: 0 !important;
  padding: 0 !important;
}
body.fullscreen-mode #game,
body.fullscreen-mode .game-container #game,
body.fullscreen-mode .canvas-wrapper #game {
  position: fixed !important;
  /* width/height set by JavaScript inline style - don't override with auto */
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  padding: 0 !important;
  transform: none !important;
  z-index: 9999 !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
body.fullscreen-mode .online-count { 
  display: block !important; 
  position: fixed !important; 
  top: 10px !important; 
  left: 10px !important; 
  right: auto !important;
  z-index: 10000 !important;
}
body.fullscreen-mode .controls {
  display: none !important;
}
body.fullscreen-mode .debug {
  display: none !important;
}
/* ================================================
   STYLE ADDITIONS
   New classes to replace inline styles
   Append this to the end of style.css
   ================================================ */

/* ========== PIXEL COLOR PREVIEW ========== */
.pixel-color-preview {
  background: #000000;
}

/* ========== TILE SELECTION INFO TEXT ========== */
.tile-selection-info-text {
  color: #fa0;
  font-size: 7px;
}

/* ========== TILESET ZOOM LEVEL TEXT ========== */
.tileset-zoom-level-text {
  min-width: 18px;
  text-align: center;
  font-size: 8px;
}

/* ========== TILESET VIEWPORT HEIGHT ========== */
.tileset-viewport-height {
  height: 200px;
}

/* ========== MERGE BUTTON MARGIN ========== */
.merge-btn {
  margin-top: 2px;
  font-size: 8px;
}

/* ========== ASSET SELECT (character, sprites, doors) ========== */
.asset-select {
  flex: 2;
  padding: 8px;
  border-radius: 5px;
  border: none;
  font-size: 10px;
  font-family: 'PixelFont', monospace;
}

/* ========== NAME COLOR PICKER ========== */
.name-color-picker {
  flex: 1;
  height: 32px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
}

/* ========== NAME COLOR PREVIEW ========== */
.name-color-preview {
  flex: 2;
  padding: 8px;
  border-radius: 5px;
  text-align: center;
  font-size: 10px;
  background: #222;
  color: #0f0;
  text-shadow: 1px 1px 0 #070;
  font-family: 'PixelFont', monospace;
}

/* ========== ASSET COLOR ROW ========== */
.asset-color-row {
  align-items: center;
}

/* ========== SETTINGS FIT/FILL BUTTON ========== */
.settings-fit-fill-btn {
  margin-left: 8px;
  width: auto;
  padding: 0 6px;
  font-size: 9px;
}

/* ========== HIDDEN LEGEND OVERRIDE ========== */
.legend.hidden {
  display: none !important;
}

/* ========== PIXEL ZOOM BUTTONS IN EDIT PANEL ========== */
.pixel-zoom-row .pixel-zoom-btn {
  /* Inherits from .pixel-zoom-btn, no extra styles needed */
}

/* ========== DATA ATTRIBUTE SELECTORS FOR EVENT BINDING ========== */
/* These don't add visual styles but help with JS querying */
[data-action] {
  cursor: pointer;
}

[data-tool] {
  cursor: pointer;
}

[data-collision] {
  cursor: pointer;
}

[data-delta] {
  cursor: pointer;
}

[data-key] {
  cursor: pointer;
}

/* ========== MODAL SEMANTIC STYLING ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

/* ========== ASIDE PANELS COMMON STYLING ========== */
aside.edit-panel,
aside.admin-panel,
aside.settings-panel,
aside.asset-panel {
  /* Inherits from their specific classes */
}

/* ========== SECTION SEMANTIC ELEMENTS ========== */
section.pixel-editor-section {
  /* Inherits from .pixel-editor-section */
}

section.browse-section {
  /* Inherits from .browse-section */
}

/* ========== NAV BOTTOM BUTTONS ========== */
nav.bottom-buttons {
  /* Inherits from .bottom-buttons */
}

/* ========== MAIN GAME CONTAINER ========== */
main.game-container {
  /* Inherits from .game-container */
}

/* ========== IMPROVED CONTRAST FOR DATA LABELS ========== */
.browse-compact-info {
  flex: 1;
  font-size: 7px;
  color: #888;
}

.browse-compact-info div {
  margin-bottom: 0;
}

/* ========== CONTEXT MENU POSITIONING FIX ========== */
.pixel-context-menu {
  position: fixed;
  z-index: 10000;
}

/* ========== AREAS/BORDERS PANEL (B key) ========== */
.areas-panel {
  position: fixed;
  top: 40px;
  right: 240px;
  background: rgba(30, 30, 50, 0.95);
  border-radius: 6px;
  padding: 10px;
  z-index: 150;
  min-width: 180px;
  max-width: 200px;
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.1);
  font-family: 'PixelFont', monospace;
  font-size: 10px;
}

.areas-panel.hidden {
  display: none;
}

.areas-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.areas-header-btns {
  display: flex;
  gap: 4px;
}

.areas-title {
  color: #fa0;
  font-weight: bold;
  font-size: 10px;
  text-shadow: 1px 1px 0 #853;
}

.areas-btn {
  padding: 4px 8px;
  border: none;
  border-radius: 3px;
  background: #2a5a8a;
  color: #fff;
  font-size: 9px;
  font-family: 'PixelFont', monospace;
  cursor: pointer;
  transition: all 0.15s;
  text-shadow: 1px 1px 0 #152d45;
}

.areas-btn:hover {
  background: #3a7aba;
}

.areas-btn.active {
  background: rgba(255, 170, 0, 0.9);
  text-shadow: 1px 1px 0 #853;
}

.areas-btn.danger {
  background: #7c2d2d;
  margin-top: 8px;
  width: 100%;
  text-shadow: 1px 1px 0 #3e1616;
}

.areas-btn.danger:hover {
  background: #9c3d3d;
}

.areas-btn.small {
  padding: 2px 6px;
  font-size: 8px;
}

.areas-btn.hidden {
  display: none;
}

.areas-list {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 3px;
  background: rgba(0,0,0,0.2);
}

.areas-list::-webkit-scrollbar { width: 6px; }
.areas-list::-webkit-scrollbar-track { background: #1a1a1a; border-radius: 3px; }
.areas-list::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.areas-list::-webkit-scrollbar-thumb:hover { background: #555; }

.area-item {
  display: flex;
  align-items: center;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 2px;
  transition: background 0.1s;
  gap: 6px;
}

.area-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.area-item.selected {
  background: rgba(255, 170, 0, 0.25);
  outline: 1px solid #fa0;
}

.area-color {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.area-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #ccc;
  font-size: 9px;
}

.area-item.selected .area-name {
  color: #fa0;
}

.area-properties {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 8px;
  margin-top: 4px;
}

.area-properties.hidden {
  display: none;
}

.area-prop-row {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  gap: 6px;
}

.area-prop-row label {
  min-width: 50px;
  font-size: 9px;
  color: #888;
}

.area-input {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 3px;
  color: #eee;
  padding: 3px 6px;
  font-size: 9px;
  font-family: 'PixelFont', monospace;
}

.area-input:focus {
  outline: none;
  border-color: #fa0;
}

.area-color-input {
  width: 32px;
  height: 20px;
  padding: 0;
  border: 1px solid #444;
  border-radius: 3px;
  cursor: pointer;
  background: transparent;
}

.area-info {
  color: #7dd;
  font-size: 9px;
  text-shadow: 1px 1px 0 #3a6a6a;
}

.area-checkbox {
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: #fa0;
}

.area-num-input {
  width: 36px;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 3px;
  color: #eee;
  padding: 3px 4px;
  font-size: 9px;
  font-family: 'PixelFont', monospace;
  text-align: center;
}

.area-num-input:focus {
  outline: none;
  border-color: #fa0;
}

/* Area property sections */
.area-prop-section {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 6px;
  margin-top: 6px;
}

.area-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 9px;
  color: #aaa;
}

/* Encounters list */
.encounters-list {
  max-height: 120px;
  overflow-y: auto;
  margin-bottom: 4px;
}

.encounter-entry {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.encounter-entry:last-child {
  border-bottom: none;
}

.encounter-name {
  flex: 1;
  min-width: 60px;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 3px;
  color: #eee;
  padding: 2px 4px;
  font-size: 8px;
  font-family: 'PixelFont', monospace;
  text-transform: uppercase;
}

.encounter-name:focus {
  outline: none;
  border-color: #fa0;
}

.encounter-level {
  width: 28px;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 3px;
  color: #7d7;
  padding: 2px 3px;
  font-size: 8px;
  font-family: 'PixelFont', monospace;
  text-align: center;
}

.encounter-level:focus {
  outline: none;
  border-color: #fa0;
}

.encounter-weight {
  width: 28px;
  background: rgba(0,0,0,0.3);
  border: 1px solid #444;
  border-radius: 3px;
  color: #dd7;
  padding: 2px 3px;
  font-size: 8px;
  font-family: 'PixelFont', monospace;
  text-align: center;
}

.encounter-weight:focus {
  outline: none;
  border-color: #fa0;
}

.encounter-delete {
  background: rgba(180,60,60,0.6);
  border: 1px solid #944;
  border-radius: 3px;
  color: #faa;
  padding: 1px 5px;
  font-size: 8px;
  cursor: pointer;
  font-family: 'PixelFont', monospace;
}

.encounter-delete:hover {
  background: rgba(220,80,80,0.8);
}

.encounters-empty {
  color: #666;
  font-size: 8px;
  font-style: italic;
  padding: 4px 0;
}

/* Areas panel scrollbar */
.areas-panel::-webkit-scrollbar { width: 6px; }
.areas-panel::-webkit-scrollbar-track { background: #1a1a1a; border-radius: 3px; }
.areas-panel::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.areas-panel::-webkit-scrollbar-thumb:hover { background: #555; }

/* Fullscreen mode - hide areas panel */
body.fullscreen-mode .areas-panel {
  display: none !important;
}
