*{margin:0;padding:0;box-sizing:border-box}
body{
  background:#0a0a18;
  color:#fff;
  font-family:'Segoe UI','Malgun Gothic',sans-serif;
  overflow-x:hidden;
  min-height:100vh;
  display:flex; flex-direction:column; align-items:center;
}

/* ── Top Menu Bar ── */
#topMenuBar {
  position: sticky; top: 0; width: 100%;
  height: 50px; z-index: 100;
  background: rgba(10, 10, 30, 0.9);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(85, 153, 255, 0.3);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 10px;
}
.menu-right { display: flex; gap: 6px; }
.menu-btn, #nicknameEdit {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(85, 153, 255, 0.4);
  border-radius: 8px; color: #fff;
  padding: 6px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  font-family: inherit; transition: all 0.2s;
}
.menu-btn:hover, #nicknameEdit:hover { background: rgba(85, 153, 255, 0.2); border-color: #5599ff; }
#nicknameEdit { background: rgba(60, 120, 255, 0.15); border-color: #5599ff; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Main Container ── */
#gameContainer {
  width: min(96vw, 440px);
  padding: 10px 0 80px; /* Bottom padding for touch controls */
  display: flex; flex-direction: column; align-items: center;
}

/* ── Character Selector ── */
#charSelector {
  width: 100%; display: flex; gap: 8px; overflow-x: auto;
  padding: 12px 6px; scrollbar-width: none;
  flex-wrap: nowrap; /* Ensure they stay on one line */
  -webkit-overflow-scrolling: touch;
}
#charSelector::-webkit-scrollbar { display: none; }

#charSelector button {
  flex: 0 0 74px; /* Fixed width for consistent look */
  height: 90px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(25, 40, 80, 0.5);
  border: 1px solid rgba(85, 153, 255, 0.3);
  border-radius: 14px;
  color: #88aacc; font-size: 11px; font-weight: bold;
  cursor: pointer; transition: all 0.2s;
  padding: 6px 4px;
}
#charSelector button.active {
  background: rgba(42, 96, 204, 0.8);
  color: #fff; border-color: #5599ff;
  box-shadow: 0 0 15px rgba(60,120,255,0.4);
  transform: translateY(-2px);
}
.char-thumb {
  width: 48px; height: 48px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 50%; margin-bottom: 6px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.char-thumb img {
  width: 110%; height: 110%; object-fit: contain;
}
#charSelector button span {
  display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Cabinet ── */
#cabinet {
  width: 100%; border-radius: 18px; overflow: hidden;
  background: #1a2a55; border: 2px solid #5599ff;
  box-shadow: 0 0 30px rgba(40,100,255,0.2);
  display: flex; flex-direction: column;
}
#titleBar { background: linear-gradient(180deg,#1e4faa,#2a60cc); padding: 8px 0; text-align: center; border-bottom: 1px solid #5599ff; }
#ledStrip { height: 4px; background: linear-gradient(90deg,#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); background-size: 200% 100%; animation: ledScroll 2s linear infinite; }
@keyframes ledScroll{0%{background-position:0 0}100%{background-position:200% 0}}
#titleBar h1 { color: #fff; font-size: 16px; text-shadow: 0 0 8px #0ff; letter-spacing: 1px; }

/* 3D Viewport */
#viewport { width: 100%; aspect-ratio: 4/3.5; background: #111; position: relative; }
#viewport canvas { display: block; width: 100%!important; height: 100%!important; }

/* Control Panel */
#controlPanel {
  background: linear-gradient(180deg,#2a60cc,#1e4faa); border-top: 3px solid #333;
  padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
}
#panelJoystick { width: 64px; height: 64px; background: radial-gradient(circle,#2a2a3a 60%,#1a1a2a); border-radius: 50%; border: 2px solid #555; position: relative; display: flex; align-items: center; justify-content: center; box-shadow: inset 0 2px 8px rgba(0,0,0,0.5); cursor: pointer; }
#joyStick { width: 22px; height: 32px; background: linear-gradient(180deg,#666,#333); border-radius: 6px 6px 10px 10px; position: relative; }
#joyBall { width: 20px; height: 20px; background: radial-gradient(circle at 35% 35%,#888,#444); border-radius: 50%; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); }
.joy-arrow { position: absolute; color: rgba(255,255,255,0.2); font-size: 8px; }
.joy-arrow.up{top:2px;left:50%;transform:translateX(-50%)} .joy-arrow.down{bottom:2px;left:50%;transform:translateX(-50%)}
.joy-arrow.left{left:2px;top:50%;transform:translateY(-50%)} .joy-arrow.right{right:2px;top:50%;transform:translateY(-50%)}

#coinBtn, #startBtn { width: 50px; height: 50px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: transform 0.1s; }
#coinBtn { background: radial-gradient(circle at 35% 35%,#ffdd44,#cc9900 50%,#aa7700); border: 3px solid #ddaa22; box-shadow: 0 0 10px rgba(255,200,0,0.3); }
#startBtn { background: radial-gradient(circle at 35% 35%,#5f5,#0c0 50%,#090); border: 3px solid #4a4; box-shadow: 0 0 12px rgba(0,255,0,0.3); }
#coinBtn:active, #startBtn:active { transform: scale(0.9); }
#coinBtn span, #startBtn span { color: #fff; font-size: 9px; font-weight: bold; text-align: center; line-height: 1.1; }

#creditDisplay { background: #0a0a0a; padding: 6px 10px; border-radius: 6px; border: 1px solid #444; }
#creditDisplay div { font-family: 'Courier New', monospace; font-size: 10px; font-weight: bold; line-height: 1.4; }

/* ── Coupang Ad Footer ── */
#gameAdFooter {
  width: 100%; margin-top: 15px; display: none; flex-direction: column; align-items: center;
  background: rgba(255,255,255,0.03); border-radius: 14px; padding: 12px;
  border: 1px solid rgba(255,255,255,0.05);
}
#gameAdFooter.visible { display: flex; }
.ad-disclosure { font-size: 9px; color: #7788aa; margin-bottom: 10px; text-align: center; line-height: 1.3; }
#bannerContainer { display: flex; gap: 10px; justify-content: center; width: 100%; }
.q-banner { flex: 1; max-width: 90px; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.4); transition: transform 0.2s; }
.q-banner img { width: 100%; height: auto; display: block; }
.q-banner:hover { transform: scale(1.05); }

@keyframes sparkle {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.6); box-shadow: 0 0 20px #ffcc44; }
}
.sparkle-active .q-banner { animation: sparkle 1s ease-in-out 3; }

/* ── Overlays ── */
#nicknameOverlay { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,0.85); display: none; align-items: center; justify-content: center; }
#nicknameOverlay.open { display: flex; }
#nicknameModal { background: linear-gradient(180deg,#1a2a60,#0e1a3a); border: 2px solid #5599ff; border-radius: 20px; padding: 30px; width: min(88vw, 340px); text-align: center; box-shadow: 0 0 40px rgba(40,100,255,0.3); }
#nicknameInput { width: 100%; padding: 12px; border-radius: 10px; border: 2px solid #335; background: #0a0a22; color: #fff; font-size: 16px; text-align: center; margin-bottom: 15px; outline: none; }
#nicknameSave { padding: 12px 30px; border-radius: 12px; border: none; background: #e94560; color: #fff; font-weight: bold; cursor: pointer; }

#msgOverlay { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: 28px; font-weight: bold; color: #fff; text-shadow: 0 0 20px #e94560, 0 0 40px rgba(0,0,0,0.8); opacity: 0; transition: opacity 0.4s; z-index: 150; text-align: center; pointer-events: none; width: 90%; max-width: 400px; }

#collectionPanel { position: fixed; top: 0; right: -320px; bottom: 0; width: min(85vw, 320px); background: #0d1a3a; z-index: 150; transition: right 0.3s; border-left: 2px solid #5599ff; display: flex; flex-direction: column; }
#collectionPanel.open { right: 0; }
#collectionHeader { padding: 15px; border-bottom: 1px solid #335; display: flex; justify-content: space-between; align-items: center; }
#collectionClose { background: none; border: none; color: #888; font-size: 28px; cursor: pointer; }
#collectionList { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.coll-item { background: #1a2a55; border: 1px solid #335; border-radius: 10px; padding: 10px; width: calc(50% - 4px); position: relative; text-align: center; }
.coll-name { display: block; font-size: 12px; font-weight: bold; margin-top: 5px; }
.coll-count { font-size: 11px; color: #ff0; }
.plushie-3d-canvas { width: 70px; height: 70px; margin: 0 auto; }
.coll-del { position: absolute; top: 2px; right: 5px; background: none; border: none; color: #555; cursor: pointer; }

#collectionBackdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 140; display: none; }
#collectionBackdrop.open { display: block; }

#collBadge { background: #e94560; border-radius: 8px; padding: 1px 5px; font-size: 10px; }

/* Mobile touch controls */
#touchOverlay { display: none; position: fixed; bottom: 20px; left: 0; right: 0; padding: 0 20px; z-index: 120; justify-content: space-between; align-items: center; pointer-events: none; }
#touchJoystickArea { width: 100px; height: 100px; background: rgba(255,255,255,0.1); border-radius: 50%; border: 2px solid rgba(255,255,255,0.2); position: relative; pointer-events: auto; }
#touchKnob { width: 40px; height: 40px; background: #4488ff; border-radius: 50%; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); pointer-events: none; }
#touchGrabBtn { width: 70px; height: 70px; border-radius: 50%; background: #e94560; color: #fff; font-weight: bold; font-size: 12px; display: flex; align-items: center; justify-content: center; pointer-events: auto; cursor: pointer; border: 3px solid #ff8a9e; }

@media(hover:none)and(pointer:coarse){ #touchOverlay { display: flex; } }
