* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b3a22; color: #3a2a1c; font-family: 'Mitr', system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
#game { position: absolute; inset: 0; display: block; image-rendering: pixelated; cursor: default; }
[hidden] { display: none !important; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }
button { cursor: pointer; border: 2px solid #8a6a44; background: #fff3d6; color: #3a2a1c; padding: 5px 10px; border-radius: 8px; }
button:hover:not(:disabled) { background: #ffe9b0; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: #f0a030; border-color: #b87010; color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.25); }
button.primary:hover:not(:disabled) { background: #f5b24a; }
button.danger { background: #e8584a; border-color: #a83428; color: #fff; }
button.link { border: 0; background: none; color: #9a5a10; text-decoration: underline; padding: 2px; }
button.x { padding: 0 8px; }
button.on { background: #ffd070; border-color: #c88a10; }
input, select, textarea { border: 2px solid #b89a70; border-radius: 8px; padding: 6px 10px; background: #fffaf0; color: #3a2a1c; width: 100%; }
.dim { color: #8a7458; font-size: 12px; }
.err { color: #c8302a; font-size: 13px; min-height: 18px; }

#hud { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; padding: 6px 10px; background: rgba(255,243,214,.92); border: 3px solid #8a6a44; border-radius: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.25); z-index: 5; }
#hud img { width: 36px; height: 36px; image-rendering: pixelated; background: #cfe8b8; border-radius: 8px; border: 2px solid #8a6a44; }
#hud .who { display: flex; flex-direction: column; line-height: 1.25; font-size: 13px; }
#hud .sp { flex: 1; }

#chat { position: absolute; left: 10px; bottom: 10px; width: min(420px, calc(100vw - 20px)); z-index: 5; }
#chat-log { max-height: 160px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; margin-bottom: 6px; font-size: 13px; }
#chat-log .line { background: rgba(0,0,0,.45); color: #fff; padding: 2px 8px; border-radius: 6px; width: fit-content; max-width: 100%; word-break: break-word; transition: opacity 1s; }
#chat-log .line b { color: #ffd070; } #chat-log .line.sys { color: #bfe8ff; } #chat-log .line.old { opacity: .35; }
#chat .keys { margin-top: 4px; font-size: 11px; color: #e8f0d8; text-shadow: 0 1px 2px #000; }

#modal { position: absolute; inset: 0; background: rgba(20,12,6,.5); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; }
.panel { width: min(520px, 100%); max-height: calc(100vh - 24px); display: flex; flex-direction: column; background: #fff3d6; border: 4px solid #8a6a44; border-radius: 14px; box-shadow: 0 6px 0 rgba(0,0,0,.3); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; background: #f0c070; border-bottom: 3px solid #8a6a44; border-radius: 10px 10px 0 0; font-size: 17px; }
.panel-body { padding: 14px; overflow: auto; user-select: text; }
.items { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; background: #fffaf0; border: 2px solid #e0c898; border-radius: 10px; padding: 6px 10px; }
.item .icon { font-size: 26px; width: 34px; text-align: center; } .item .info { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.coins-line { margin: 10px 0 0; text-align: right; }
.game { background: #fffaf0; border: 2px solid #e0c898; border-radius: 10px; padding: 10px; margin-top: 10px; }
.game-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.lb { margin: 4px 0 0; padding-left: 22px; font-size: 13px; }
.mg-canvas { width: 100%; max-width: 480px; display: block; margin: 0 auto; border: 3px solid #8a6a44; border-radius: 8px; image-rendering: pixelated; }
.mem-hud { text-align: center; margin-bottom: 8px; }
.mem-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 360px; margin: 0 auto; }
.card { font-size: 30px; aspect-ratio: 1; padding: 0; background: #f0c070; } .card.up { background: #fff; } .card.done { background: #c8f0b0; opacity: .8; }
.preview { text-align: center; } .big-bear { width: 96px; height: 96px; image-rendering: pixelated; background: #cfe8b8; border-radius: 12px; border: 3px solid #8a6a44; }
.swatches, .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 8px; padding: 0; } .swatch.on { outline: 3px solid #f0a030; }
h3, h4 { margin: 10px 0 6px; }

#auth { position: absolute; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; background: linear-gradient(#7ec8f0, #b8e8a0); }
.auth-box { width: min(360px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 10px; background: #fff3d6; border: 4px solid #8a6a44; border-radius: 16px; padding: 22px; box-shadow: 0 6px 0 rgba(0,0,0,.3); text-align: center; }
.auth-box h1 { margin: 0; font-size: 28px; } .auth-box p { margin: 0; }
#loading { position: absolute; inset: 0; z-index: 25; display: flex; align-items: center; justify-content: center; background: #1b3a22; color: #fff; font-size: 20px; }
#toasts { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); z-index: 40; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: #3a8a3a; color: #fff; padding: 8px 16px; border-radius: 10px; box-shadow: 0 3px 0 rgba(0,0,0,.3); } .toast.bad { background: #c8403a; }

/* ตัวแก้ไขเมือง */
#editor { position: absolute; top: 70px; right: 10px; bottom: 10px; width: 330px; z-index: 6; display: flex; flex-direction: column; background: rgba(255,243,214,.97); border: 3px solid #8a6a44; border-radius: 12px; box-shadow: 0 3px 0 rgba(0,0,0,.25); }
.ed-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #f0c070; border-radius: 9px 9px 0 0; border-bottom: 3px solid #8a6a44; }
.ed-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 8px; } .ed-tools button { padding: 4px 2px; font-size: 12px; }
.ed-body { flex: 1; overflow: auto; padding: 8px 10px; user-select: text; }
.ed-foot { padding: 8px 10px; border-top: 2px solid #e0c898; display: flex; flex-direction: column; gap: 4px; }
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; } .palette.wide { grid-template-columns: repeat(2, 1fr); }
.pal { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 2px; font-size: 10px; line-height: 1.1; }
.pal img { width: 32px; height: 32px; image-rendering: pixelated; } .pal .big, .pal .eraser { font-size: 24px; height: 32px; line-height: 32px; } .pal.on { background: #ffd070; border-color: #c88a10; }
.form { display: flex; flex-direction: column; gap: 8px; } .form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #6a5238; }
.form .row { align-items: flex-end; } .form .row label { flex: 1; }
.plist { padding-left: 18px; } .items-ed { display: flex; flex-direction: column; gap: 6px; }
.item-ed { display: grid; grid-template-columns: 38px 1fr 64px; gap: 4px; align-items: center; background: #fffaf0; border: 2px solid #e0c898; border-radius: 8px; padding: 5px; }
.item-ed input.ico { text-align: center; padding: 6px 2px; } .item-ed select { grid-column: 1 / 3; } .item-ed > button { padding: 4px 6px; }
@media (max-width: 700px) { #editor { width: calc(100vw - 20px); top: auto; height: 46vh; } }
.item-ed input.wide, .item-ed input.cat { grid-column: 1 / -1; }
.item-ed label { grid-column: 1 / -1; display: flex; align-items: center; gap: 4px; }
button.shopee { background: #ee4d2d; border-color: #c33a1d; color: #fff; }
.item img.thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
/* เกมเซ็นเตอร์ยุค 70-90: จอมืด ตัวอักษรเขียวนีออนแบบจอ CRT */
.arcade.retro { background: #0d0221; color: #7dff5a; font-family: 'Courier New', monospace; padding: 10px; border: 3px solid #22d6ff; border-radius: 6px; box-shadow: 0 0 14px #22d6ff88, inset 0 0 24px #000; background-image: repeating-linear-gradient(0deg, rgba(0,0,0,.25) 0 1px, transparent 1px 3px); }
.arcade.retro .dim { color: #ff7ad8; }
.arcade.retro .game { background: #1d1030; border-color: #ff3fa4; }
.arcade.retro b { color: #ffe05a; text-shadow: 0 0 6px #ffe05a88; }
.arcade.retro button.primary { background: #ff3fa4; border-color: #ffe05a; color: #fff; }
.badge-new { display: inline-block; background: #ff3b30; color: #fff; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 8px; vertical-align: middle; animation: newpulse 1.2s infinite; }
@keyframes newpulse { 50% { transform: scale(1.12); } }
a.btn-link { display: inline-block; text-decoration: none; padding: 6px 12px; border-radius: 8px; border: 2px solid #a06a2a; background: #f0a030; color: #fff; font-weight: 600; white-space: nowrap; }
.arcade.retro a.btn-link { background: #ff3fa4; border-color: #ffe05a; color: #fff; }
.room-cv { width: 100%; max-width: 480px; display: block; margin: 6px auto; border: 3px solid #8e6538; border-radius: 8px; image-rendering: auto; cursor: pointer; background: #fff; }
.item.sel { border-color: #f0a030; box-shadow: 0 0 0 2px #f0a03055; }
/* ตู้เกมอาร์เคด (Retro Game Center) */
.cab-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px 12px; margin-top: 10px; }
.cab { --c: #ff3fa4; display: flex; flex-direction: column; align-items: stretch; background: linear-gradient(90deg, #0b0618, #1d1030 20%, #1d1030 80%, #0b0618); border: 3px solid #000; border-bottom: 0; border-radius: 14px 14px 0 0; padding: 6px 8px 0; box-shadow: inset 0 0 0 2px var(--c), 0 0 16px color-mix(in srgb, var(--c) 45%, transparent); }
.cab-0 { --c: #ff3fa4; } .cab-1 { --c: #ffe05a; } .cab-2 { --c: #22d6ff; } .cab-3 { --c: #7dff5a; }
.cab-marquee { background: var(--c); color: #14082a; font-weight: 800; text-align: center; letter-spacing: 1px; padding: 5px 4px; border-radius: 8px 8px 2px 2px; font-size: 13px; text-shadow: 0 1px 0 rgba(255,255,255,.4); animation: marq 1.6s steps(2) infinite; }
@keyframes marq { 50% { filter: brightness(1.25); } }
.cab-marquee .badge-new { margin-left: 6px; }
.cab-bezel { background: #000; margin: 6px 2px 0; padding: 6px; border-radius: 6px; border: 2px solid #3a2a5a; }
.cab-screen { position: relative; min-height: 120px; background: #06281c; border-radius: 10px / 14px; padding: 8px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; color: #7dff5a; font-family: 'Courier New', monospace; font-size: 11px; box-shadow: inset 0 0 22px #000; overflow: hidden; background-image: repeating-linear-gradient(0deg, rgba(0,0,0,.28) 0 1px, transparent 1px 3px); }
.cab-icon { font-size: 38px; filter: drop-shadow(0 0 6px #7dff5a); }
.cab-desc { line-height: 1.25; opacity: .9; }
.cab-hi { color: #ffe05a; font-weight: 700; }
.cab-start { margin-top: auto; color: #fff; animation: blink 1s steps(2) infinite; letter-spacing: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.cab-panel { display: flex; justify-content: space-around; align-items: center; background: #2a1a48; margin: 6px 2px 0; padding: 8px 6px; border-radius: 4px; border-top: 3px solid var(--c); transform: perspective(200px) rotateX(18deg); }
.cab-stick { width: 14px; height: 30px; position: relative; } .cab-stick::before { content: ''; position: absolute; left: 6px; bottom: 0; width: 3px; height: 18px; background: #aaa; }
.cab-stick i { position: absolute; left: 0; top: 0; width: 15px; height: 15px; border-radius: 50%; background: #e02a2a; box-shadow: inset -2px -2px 0 rgba(0,0,0,.3), 0 0 6px #e02a2a; }
.cab-btns { display: flex; gap: 6px; } .cab-btns i { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: inset -2px -2px 0 rgba(0,0,0,.3); } .cab-btns i:nth-child(2) { background: #22d6ff; } .cab-btns i:nth-child(3) { background: #ffe05a; }
.cab-coin { display: flex; flex-direction: column; align-items: center; gap: 6px; background: #120a22; margin: 6px 2px 0; padding: 8px 6px; border-radius: 2px; }
.cab-slot { width: 22px; height: 6px; background: #000; border: 2px solid #777; border-radius: 3px; box-shadow: 0 0 6px #ffe05a; }
.cab-coin button, .cab-coin a.btn-link { width: 100%; text-align: center; font-size: 12px; padding: 5px 4px; box-sizing: border-box; }
.cab-base { height: 14px; background: #000; margin: 0 -8px; border-top: 2px solid var(--c); }
.arcade.retro .cab-coin button.primary, .arcade.retro .cab-coin a.btn-link { background: var(--c); border-color: #000; color: #14082a; font-weight: 800; text-shadow: none; }
.brand-hero { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 18px; border-radius: 10px; font-size: 22px; margin-bottom: 8px; }
.brand-icon { font-size: 40px; }
.brand-ed { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; } .brand-ed input[type=color] { width: 36px; padding: 0; } .brand-ed .row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.aff-note { background: #fff3e8; border: 1px solid #ee4d2d55; color: #a8361b; border-radius: 8px; padding: 6px 8px; font-size: 12px; margin: 6px 0; }
