* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { font-family: Tahoma, Verdana, "MS Sans Serif", sans-serif; font-size: 12px; background: #008080; user-select: none; -webkit-user-select: none; }
input, select, textarea { user-select: text; -webkit-user-select: text; font-family: inherit; font-size: 12px; }
.off { display: none !important; }

#scene-container { position: fixed; inset: 0; z-index: 0; }
#scene-container canvas { display: block; touch-action: none; }

.win95-window { background: #c0c0c0; border: 2px solid; border-color: #fff #808080 #808080 #fff; box-shadow: 1px 1px 0 #000; }
#game-ui .win95-window, #build-ui .win95-window { position: fixed; z-index: 10; }
.win95-titlebar { background: linear-gradient(90deg, #000080, #1084d0); color: #fff; font-weight: bold; padding: 2px 4px; display: flex; justify-content: space-between; align-items: center; }
.tb-collapse { width: 16px; height: 14px; background: #c0c0c0; border: 1px solid; border-color: #fff #808080 #808080 #fff; font-size: 10px; line-height: 10px; cursor: pointer; font-weight: bold; }
.win95-btn, .navbtn { background: #c0c0c0; border: 2px solid; border-color: #fff #808080 #808080 #fff; padding: 2px 9px; font-family: inherit; font-size: 12px; cursor: pointer; color: #000; }
.win95-btn:active, .navbtn:active, .win95-btn.on { border-color: #808080 #fff #fff #808080; background: #b4b4b4; }
.win95-btn:disabled { color: #808080; text-shadow: 1px 1px #fff; cursor: default; }
.sunken { background: #fff; border: 2px solid; border-color: #808080 #fff #fff #808080; }
input[type=text], input[type=number], select, textarea { border: 2px solid; border-color: #808080 #fff #fff #808080; padding: 2px 3px; background: #fff; }

/* Loader */
#loading-screen { position: fixed; inset: 0; z-index: 1000; background: #3a6ea5; display: flex; align-items: center; justify-content: center; transition: opacity .5s; }
#loading-screen.fade-out { opacity: 0; }
.loader-window { width: 340px; max-width: 90vw; }
.loader-body { padding: 18px; text-align: center; }
.brick-logo { display: inline-grid; grid-template-columns: 22px 22px; gap: 3px; }
.brick-logo span { width: 22px; height: 22px; background: #c4281c; border: 2px solid; border-color: #f07060 #701010 #701010 #f07060; }
.brick-logo span:nth-child(2) { background: #0d69ac; border-color: #4aa0e0 #063a60 #063a60 #4aa0e0; }
.brick-logo span:nth-child(3) { background: #f5cd30; border-color: #fff09a #907010 #907010 #fff09a; }
.brick-logo span:nth-child(4) { background: #4b974b; border-color: #8ad08a #205020 #205020 #8ad08a; }
.loader-title { font-size: 22px; font-weight: bold; color: #000080; margin: 8px 0 14px; letter-spacing: 1px; }
.progress-outer { height: 22px; background: #fff; border: 2px solid; border-color: #808080 #fff #fff #808080; margin-bottom: 8px; overflow: hidden; }
.progress-inner { height: 100%; width: 0%; background: repeating-linear-gradient(90deg, #0a3fa8 0 16px, #fff 16px 19px); }
.loader-flavor { color: #333; font-size: 11px; height: 14px; }

/* Toolbar */
#toolbar { position: fixed; top: 0; left: 0; right: 0; z-index: 50; background: #c0c0c0; border-bottom: 2px solid #808080; padding: 3px 6px; display: flex; align-items: center; gap: 4px; height: 30px; white-space: nowrap; overflow-x: auto; overflow-y: hidden; }
.tb-title { font-weight: bold; color: #000080; margin-right: 6px; max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.tb-menu { cursor: pointer; padding: 1px 4px; }
.tb-menu:hover { background: #000080; color: #fff; }
.tb-right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.tix { font-weight: bold; color: #806000; background: #fff8c0; border: 1px solid #806000; padding: 1px 6px; }
.tb-stats { font-family: "Courier New", monospace; color: #333; }
#auth-status a { color: #0000ee; }

/* Pages */
#pages { position: fixed; top: 30px; left: 0; right: 0; bottom: 0; overflow-y: auto; z-index: 5;
  background: #6fa8dc; background-image: linear-gradient(rgba(255,255,255,.12) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.12) 1px, transparent 1px); background-size: 20px 20px; }
#pages.off { display: none; }
.page { display: none; padding: 12px; max-width: 1100px; margin: 0 auto 40px; }
.page.on { display: block; }
.box { margin-bottom: 12px; }
.box .bbody { padding: 8px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.col { flex: 1; min-width: 260px; }
h3.sec { color: #000080; font-size: 13px; margin: 4px 0 6px; border-bottom: 1px solid #808080; }
a, .link { color: #0000ee; text-decoration: underline; cursor: pointer; }
.muted { color: #555; font-size: 11px; }
.hscroll { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gcard, .icard { background: #fff; border: 2px solid; border-color: #fff #808080 #808080 #fff; padding: 4px; cursor: pointer; min-width: 150px; max-width: 180px; position: relative; }
.grid .gcard, .grid .icard { max-width: none; }
.gcard:hover, .icard:hover { outline: 2px dotted #000080; }
.gcard img { width: 100%; aspect-ratio: 16/10; display: block; border: 1px solid #000; image-rendering: pixelated; background: #9fd8f2; }
.icard img { width: 100%; aspect-ratio: 1; display: block; border: 1px solid #808080; background: #eef; image-rendering: pixelated; }
.gt { font-weight: bold; color: #0000ee; text-decoration: underline; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gs { font-size: 11px; color: #444; }
.price { color: #806000; font-weight: bold; }
.featured { position: absolute; top: 6px; left: 6px; background: #f5cd30; border: 1px solid #000; font-weight: bold; font-size: 10px; padding: 0 4px; transform: rotate(-6deg); }
.owned { color: #080; font-weight: bold; }
.equipped { outline: 3px solid #0a3fa8 !important; }
.tabs { display: flex; gap: 2px; margin-bottom: -2px; position: relative; z-index: 1; flex-wrap: wrap; }
.tab { background: #c0c0c0; border: 2px solid; border-color: #fff #808080 transparent #fff; padding: 3px 10px; cursor: pointer; }
.tab.on { background: #d4d0c8; font-weight: bold; padding-bottom: 5px; }
.tabbody { background: #d4d0c8; border: 2px solid; border-color: #fff #808080 #808080 #fff; padding: 8px; }
.welcome { display: flex; gap: 12px; align-items: center; }
.welcome img { width: 110px; height: 110px; border: 2px solid; border-color: #808080 #fff #fff #808080; background: #9fd8f2; }
.bigname { font-size: 20px; font-weight: bold; color: #000080; }
.flist div { padding: 3px; display: flex; gap: 6px; align-items: center; border-bottom: 1px dotted #aaa; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #999; display: inline-block; }
.dot.on { background: #0c0; }
.swatches { display: grid; grid-template-columns: repeat(8, 24px); gap: 3px; }
.sw { width: 24px; height: 24px; border: 2px solid; border-color: #fff #404040 #404040 #fff; cursor: pointer; }
.sw.sel { outline: 2px solid #000; }
.bodyrow { display: flex; align-items: center; gap: 6px; padding: 2px; cursor: pointer; }
.bodyrow.sel { background: #000080; color: #fff; }
.bodyrow .sw { width: 18px; height: 18px; }
#avatar-canvas-wrap { width: 260px; height: 320px; border: 2px solid; border-color: #808080 #fff #fff #808080; background: #9fd8f2; }
.hist { max-height: 160px; overflow-y: auto; font-family: "Courier New", monospace; font-size: 11px; padding: 4px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { width: 70px; text-align: center; font-size: 10px; }
.badge .bi { width: 48px; height: 48px; margin: 0 auto 2px; display: flex; align-items: center; justify-content: center; font-size: 26px; color: #fff; border: 2px solid #000; text-shadow: 1px 1px #000; }
.form label { display: block; margin: 4px 0 1px; font-weight: bold; }
.form input[type=text], .form select, .form textarea { width: 100%; }
#paint-canvas { width: 192px; height: 192px; image-rendering: pixelated; border: 2px solid #000; cursor: crosshair; background: repeating-conic-gradient(#ddd 0 25%, #fff 0 50%) 0 0/24px 24px; touch-action: none; }
.mini td { padding: 1px 4px; border-bottom: 1px dotted #999; }
.mini { border-collapse: collapse; width: 100%; background: #fff; }

/* Game UI */
#player-list { top: 36px; right: 6px; width: 190px; }
.pl-body { padding: 3px; max-height: 220px; overflow-y: auto; background: #fff; margin: 3px; border: 1px solid #808080; }
.pl-body.collapsed { display: none; }
.pl-row { display: flex; align-items: center; gap: 5px; padding: 2px 3px; }
.pl-row:nth-child(even) { background: #eef; }
.pl-color { width: 12px; height: 12px; border: 1px solid #000; flex-shrink: 0; }
.pl-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-tag { font-size: 9px; color: #888; }
.pl-dot { width: 8px; height: 8px; border-radius: 50%; background: #0c0; flex-shrink: 0; }
#chat-box { bottom: 80px; left: 6px; width: 300px; max-width: 70vw; }
.chat-log { height: 130px; overflow-y: auto; background: #fff; margin: 3px; padding: 3px; border: 1px solid #808080; line-height: 1.35; user-select: text; }
.chat-msg { word-wrap: break-word; }
.chat-name { font-weight: bold; }
.chat-sys { color: #0000cc; font-style: italic; }
.chat-input-row { display: flex; gap: 3px; padding: 3px; }
.chat-input-row input { flex: 1; }
#controls-hint { top: 70px; left: 6px; width: 190px; font-size: 11px; }
.ch-body { padding: 4px 6px; }
#leave-btn { position: fixed; top: 38px; left: 6px; z-index: 12; }
#hpbar { position: fixed; top: 38px; left: 50%; transform: translateX(-50%); width: 220px; height: 18px; z-index: 12; background: #400; border: 2px solid; border-color: #808080 #fff #fff #808080; }
#hp-fill { height: 100%; width: 100%; background: #2c2; }
#hp-text { position: absolute; inset: 0; text-align: center; color: #fff; font-weight: bold; text-shadow: 1px 1px #000; line-height: 14px; }
#hotbar-wrap { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; gap: 6px; z-index: 12; align-items: flex-end; }
#hotbar { display: flex; gap: 3px; }
.slot { width: 48px; height: 48px; background: rgba(192,192,192,.9); border: 2px solid; border-color: #fff #808080 #808080 #fff; position: relative; cursor: pointer; }
.slot.sel { border-color: #f5cd30; background: #fff4b0; box-shadow: 0 0 0 2px #000; }
.slot img { width: 100%; height: 100%; pointer-events: none; }
.slot .num { position: absolute; top: 0; left: 2px; font-weight: bold; font-size: 10px; text-shadow: 1px 1px #fff; pointer-events: none; }
.slot .cd { position: absolute; inset: 0; pointer-events: none; }
.slot .uses { position: absolute; bottom: 0; right: 2px; font-size: 10px; font-weight: bold; pointer-events: none; }
#backpack-btn { width: 48px; height: 48px; background: #c0c0c0; border: 2px solid; border-color: #fff #808080 #808080 #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.bp-icon { width: 26px; height: 30px; background: #7c503a; border: 2px solid #3a2010; position: relative; }
.bp-icon::before { content: ''; position: absolute; top: -8px; left: 6px; width: 10px; height: 8px; border: 2px solid #3a2010; border-bottom: none; }
.bp-icon::after { content: ''; position: absolute; bottom: 4px; left: 3px; right: 3px; height: 8px; background: #a06a4a; border: 1px solid #3a2010; }
#backpack { bottom: 80px; left: 50%; transform: translateX(-50%); width: 440px; max-width: 96vw; z-index: 15 !important; }
.bp-hint { padding: 3px 6px; font-size: 10px; color: #333; }
#bp-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; padding: 4px; }
#bp-grid .slot { width: 100%; height: auto; aspect-ratio: 1; }
#death-msg { position: fixed; top: 40%; left: 50%; transform: translate(-50%,-50%); z-index: 30; background: #000; color: #f44; font-size: 20px; font-weight: bold; padding: 10px 20px; border: 2px solid #f44; }
#mobile-controls { position: fixed; bottom: 80px; right: 8px; z-index: 30; display: none; align-items: flex-end; gap: 14px; }
.dpad { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.dpad-mid { display: flex; gap: 40px; }
.mright { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.mbtn { width: 48px; height: 48px; background: #c0c0c0; border: 3px solid; border-color: #fff #808080 #808080 #fff; font-weight: bold; color: #000080; touch-action: none; }
.jump-btn { width: 64px; height: 64px; }

/* Build */
#build-top { top: 34px; left: 6px; right: 6px; padding: 3px; display: flex; gap: 3px; flex-wrap: wrap; align-items: center; }
#build-top .sep { width: 2px; height: 20px; border-left: 1px solid #808080; border-right: 1px solid #fff; margin: 0 3px; }
#build-insert { top: 76px; left: 6px; width: 140px; max-height: calc(100vh - 110px); overflow-y: auto; }
#build-insert .win95-btn { display: block; width: calc(100% - 8px); margin: 3px 4px; text-align: left; }
#build-props { top: 76px; right: 6px; width: 240px; max-height: calc(100vh - 110px); overflow-y: auto; }
#build-props .pb { padding: 6px; }
#build-props label { display: block; font-weight: bold; margin-top: 5px; }
.xyz { display: flex; gap: 2px; align-items: center; }
.xyz input { width: 54px; }
.xyz .win95-btn { padding: 0 4px; }

/* Modal / toast */
#modal { position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.35); display: none; align-items: center; justify-content: center; }
.mwin { width: 420px; max-width: 94vw; max-height: 88vh; display: flex; flex-direction: column; }
.mbody { padding: 10px; overflow-y: auto; }
.mbtns { display: flex; gap: 6px; justify-content: flex-end; padding: 6px 10px 10px; }
#toast { position: fixed; bottom: 120px; left: 50%; transform: translateX(-50%); z-index: 950; background: #ffffe1; border: 1px solid #000; padding: 6px 12px; display: none; box-shadow: 2px 2px 0 #000; max-width: 90vw; }
#badge-pop { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); z-index: 960; background: #c0c0c0; border: 2px solid; border-color: #fff #808080 #808080 #fff; box-shadow: 2px 2px 0 #000; padding: 10px 14px; display: flex; gap: 10px; align-items: center; animation: drop .4s steps(4); }
@keyframes drop { from { top: -80px; } to { top: 80px; } }

#footer { position: fixed; bottom: 2px; right: 8px; z-index: 60; font-size: 11px; background: #c0c0c0; padding: 0 4px; border: 1px solid #808080; }
#footer a { color: #0000ee; }

@media (max-width: 768px) {
  #chat-box { width: 200px; bottom: 150px; }
  .chat-log { height: 70px; }
  #player-list { width: 130px; }
  #controls-hint, .tb-menu, .tb-stats { display: none; }
  .slot { width: 34px; height: 34px; }
  #backpack-btn { width: 34px; height: 34px; }
  #hotbar-wrap { bottom: 20px; }
  #build-insert { width: 110px; }
  #build-props { width: 180px; }
  #footer { left: 4px; right: auto; }
}