:root {
  --pad: 12px;
  --radius: 10px;
}

/* Basic reset and typography */
html, body {
  height: 100%;
}

body {
  margin: 0;
  background: #fff;
  color: #000;
  font-family: "Noto Sans", "Space Mono", system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Canvas fullscreen */
#game {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

/* UI overlay */
#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

/* HUD */
#hud {
  pointer-events: auto;
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff;
  border: 1px solid #000;
  border-radius: var(--radius);
  padding: 10px 12px;
}

#status {
  display: flex;
  gap: 12px;
  font-weight: 800;
}

#actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#actions #musicBtn { display: none; }
#actions #collectBtn { display: none !important; }
#actions #chatBtn { pointer-events:auto; }
#actions #slapBtn { display: none !important; }

/* Buttons */
button {
  appearance: none;
  border: 1px solid #000;
  background: #000;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:active {
  transform: scale(0.98);
}

button:disabled {
  background: #fff;
  color: #000;
  opacity: 0.6;
  cursor: not-allowed;
}

/* Joystick container */
#joystick {
  pointer-events: auto;
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  left: 20px;
  width: 180px;
  height: 180px;
  opacity: 0.95;
}

/* Toast */
#toast {
  pointer-events: none;
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse; /* oldest at bottom, new above */
  align-items: center;
  gap: 8px;
}

.toast-item {
  background: transparent;
  color: #000;
  border-radius: 0;
  padding: 0;
  font-size: 18px;
  font-weight: 800;
}

/* Accessibility */
button:focus-visible {
  outline: 2px solid #000;
  outline-offset: 2px;
}

#indexModal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; z-index: 30;
  pointer-events: auto;
}

.index-content {
  background: #fff; color: #000; width: 92vw; max-width: 640px; max-height: 70vh; overflow: auto; border: 1px solid #000; border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}

.index-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; font-weight:800; border-bottom:1px solid #000; }

#indexList { padding: 12px; display: grid; gap: 16px; }

.index-section { display: grid; gap: 10px; }

.index-title { font-weight:800; font-size:16px; }

.index-items { display:grid; grid-template-columns: 1fr 1fr; gap:12px; }

.index-item { display:flex; gap:8px; align-items:center; }

.index-item img { width:40px; height:40px; object-fit: cover; border:1px solid #000; border-radius:6px; }

.index-item .meta { font-size:12px; }

.menu-container { position: relative; }

#menuDropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #fff;
  border: 1px solid #000;
  border-radius: 8px;
  padding: 6px;
  display: none;
  pointer-events: auto;
}

#menuDropdown button { width: 100%; margin: 4px 0; }

#creditModal { position:fixed; inset:0; background:rgba(0,0,0,0.5); display:none; align-items:center; justify-content:center; z-index:20; pointer-events:auto; }

.credit-card { background:#000; color:#fff; border:1px solid #000; border-radius:12px; width:90vw; max-width:400px; padding:16px; }

.cc-id { font-size: 11px; color: #666; margin-top: 12px; display: block; }

.cc-title { font-weight:800; font-size:18px; margin-bottom:8px; }

.cc-amount { font-size:16px; margin-bottom:12px; }

.cc-actions { display:flex; gap:8px; justify-content:flex-end; }

#ccPay { background:#fff; color:#000; }

#chatBox {
  position: fixed;
  top: 92px;
  left: 12px;
  display: none;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid #000;
  border-radius: 10px;
  padding: 8px;
  pointer-events: auto;
  width: 92vw; max-width: 360px;
}

#chatMessages {
  max-height: 220px;
  height: 220px;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
  display: block;
}

.chat-msg { 
  font-size: 13px; 
  font-weight: 700; 
  color: #000;
  margin: 0;
}

.chat-msg + .chat-msg {
  margin-top: 2px;
}

.chat-input-row { display: flex; gap: 8px; margin-top: 8px; }

#chatBox input {
  flex: 1;
  border: 1px solid #000;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

#chatBox button { padding: 8px 12px; }

#actionCorner { position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; align-items: flex-end; gap: 10px; pointer-events: none; }

#actionCircle { pointer-events: auto; width: 76px; height: 76px; border-radius: 50%; background:#000; color:#fff; border:1px solid #000; font-weight:800; display:flex; align-items:center; justify-content:center; padding:0; }

#actionHint { pointer-events: none; background:#fff; border:1px solid #000; border-radius:8px; padding:6px 10px; font-weight:700; }

#adminModal { position:fixed; inset:0; background:rgba(0,0,0,0.3); display:none; align-items:center; justify-content:center; z-index:15; pointer-events:auto; }

.admin-content { background:#fff; color:#000; width:92vw; max-width:640px; max-height:70vh; overflow:auto; border:1px solid #000; border-radius:10px; }

.admin-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; font-weight:800; border-bottom:1px solid #000; }

.admin-grid { padding:12px; display:grid; grid-template-columns: 1fr 1fr; gap:10px; }

.admin-grid button { width:100%; }

.admin-list { padding:12px; display:grid; gap:8px; }

.admin-list .field-row { display:flex; gap:8px; align-items:center; }

.admin-list select,
.admin-list input[type="number"] {
  appearance:none; border:1px solid #000; border-radius:8px; padding:8px 10px; font-size:14px; background:#fff; color:#000;
}

.admin-list select { width:64px; text-align:center; }

.admin-list input[type="number"] { flex:1; min-width:0; }

#serverModal { position:fixed; inset:0; background:rgba(0,0,0,0.3); display:none; align-items:center; justify-content:center; z-index:15; pointer-events:auto; }

.server-content { background:#fff; color:#000; width:92vw; max-width:640px; max-height:70vh; overflow:auto; border:1px solid #000; border-radius:10px; }

.server-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; font-weight:800; border-bottom:1px solid #000; }

#serverBody { padding:12px; display:grid; gap:8px; }

#friendModal { position:fixed; inset:0; background:rgba(0,0,0,0.3); display:none; align-items:center; justify-content:center; z-index:16; pointer-events:auto; }

#shopModal { position:fixed; inset:0; background:rgba(0,0,0,0.3); display:none; align-items:center; justify-content:center; z-index:15; pointer-events:auto; }

.shop-content { background:#fff; color:#000; width:92vw; max-width:640px; max-height:70vh; overflow:auto; border:1px solid #000; border-radius:10px; }

.shop-header { display:flex; align-items:center; justify-content:space-between; padding:10px 12px; font-weight:800; border-bottom:1px solid #000; }

#shopBody { padding:12px; display:grid; gap:12px; }

.shop-item { border:1px solid #000; border-radius:8px; padding:10px; display:grid; gap:8px; background:#fff; }

.shop-item.square { display: grid; gap: 8px; text-align: center; }

.shop-item.square .thumb { width: 100%; aspect-ratio: 1 / 1; border: 1px solid #000; border-radius: 6px; background-size: cover; background-position: center; }

#shopBody .lucky-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.menu-uptime { font-size: 11px; color: #888; padding: 6px; border-top: 1px solid #eee; }

#clientUptime { color: #ffcc00; }

#serverUptime { color: #ff3b30; }

#leftBar {
  position: fixed;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  z-index: 12;
}

#leftBar .left-btn {
  width: fit-content;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 12px;
}

#leftBar .left-btn.main { width: fit-content; }
#leftBar .left-btn.small { width: fit-content; padding: 6px 8px; }

#leftBar .left-btn.small .material-icons { font-size: 18px; }
#leftBar .left-btn.small .left-label { font-size: 12px; }

#leftBar .material-icons { font-size: 22px; }

#leftBar .left-label {
  margin-left: 6px;
  font-size: 13px;
  font-weight: 700;
}

#serverPanel {
  position: fixed;
  top: 92px;
  right: 12px;
  max-width: 200px;
  background: #fff;
  border: 1px solid #000;
  border-radius: 10px;
  padding: 6px;
  pointer-events: auto;
}
#serverList { display: grid; gap: 3px; }
.server-item { display:flex; align-items:center; justify-content:space-between; gap:8px; padding:3px 4px; border:1px solid #000; border-radius:3px; background:#fff; font-size:10px; }
.more-btn { width:13px; height:13px; display:flex; align-items:center; justify-content:center; font-weight:800; }
.more-menu { position: absolute; right: 4px; top: 17px; background:#fff; border:1px solid #000; border-radius:3px; padding:2px; display:none; z-index: 10; }
.more-menu button { width:100%; }