* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0d1117;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: #e6edf3;
  user-select: none;
  touch-action: none;
}

#game { display: block; position: fixed; inset: 0; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }

/* Top-left cluster: score on top, minimap below it. */
#topLeft {
  position: absolute; left: 14px; top: 14px;
  display: flex; flex-direction: column; gap: 8px;
}
#score {
  font-size: 18px; font-weight: 700;
  text-shadow: 0 2px 6px rgba(0,0,0,0.6);
}

#leaderboard {
  position: absolute; right: 16px; top: 16px;
  background: rgba(13,17,23,0.72);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 10px 14px 12px;
  min-width: 170px;
  backdrop-filter: blur(6px);
}
#leaderboard h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  color: #7d8590; margin-bottom: 8px; text-align: center;
}
#leaderboard ol { list-style: none; }
#leaderboard li {
  font-size: 14px; padding: 2px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#leaderboard li.me { color: #4ade80; font-weight: 700; }

#minimap {
  width: 180px; height: 180px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  background: rgba(13,17,23,0.5);
}

/* Floating chat window — draggable + resizable. Default bottom-left, tall. */
#chat {
  position: fixed; left: 14px; top: calc(100vh - 494px);
  width: 320px; height: 480px;
  min-width: 220px; min-height: 140px;
  max-width: 96vw; max-height: 90vh;
  display: flex; flex-direction: column;
  background: rgba(13,17,23,0.72);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.45);
  z-index: 6;
}
#chatHeader {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 8px 7px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  cursor: move; user-select: none;
  font-size: 13px; font-weight: 700; color: #9aa4af;
}
#chatDrag { letter-spacing: 1px; }
.chatBtns { display: flex; gap: 4px; }
.chatBtns button {
  flex: none; width: 26px; height: 24px; padding: 0;
  font-size: 13px; line-height: 1; border-radius: 6px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  color: #cbd5e1;
}
.chatBtns button:hover { background: rgba(255,255,255,0.14); }
#chatBody {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column; gap: 6px;
  padding: 8px;
}
#chatLog {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 3px;
  font-size: 13px; line-height: 1.35;
}
#chatLog .msg {
  background: rgba(255,255,255,0.05);
  padding: 3px 8px; border-radius: 8px; width: fit-content;
  max-width: 100%; word-break: break-word;
}
#chatLog .msg b { color: #4ade80; margin-right: 5px; }
#chatLog .msg.sys { color: #9aa4af; font-style: italic; background: transparent; padding: 1px 4px; }
#chatInput {
  padding: 8px 10px; font-size: 13px; flex: none;
  border-radius: 8px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(13,17,23,0.85); color: #e6edf3; outline: none;
}
#chatInput:focus { border-color: #4ade80; }

/* Collapsed: only the header bar remains. */
#chat.collapsed { height: auto !important; min-height: 0; }
#chat.collapsed #chatBody,
#chat.collapsed .chatResize { display: none; }
#chat.collapsed #chatHeader { border-bottom: none; }

/* Resize handles on the right and bottom edges (+ corner). */
.chatResize { position: absolute; z-index: 2; }
#chatResizeR { top: 8px; bottom: 12px; right: -3px; width: 8px; cursor: ew-resize; }
#chatResizeB { left: 8px; right: 12px; bottom: -3px; height: 8px; cursor: ns-resize; }
#chatResizeBR { right: -3px; bottom: -3px; width: 16px; height: 16px; cursor: nwse-resize; }

/* Spectate -> join button */
#joinFromSpectate {
  position: absolute; left: 50%; top: 14px; transform: translateX(-50%);
  width: auto; padding: 9px 18px; pointer-events: auto;
  background: linear-gradient(120deg, #16a34a, #0891b2);
  border-color: transparent; color: #fff; font-weight: 700;
}

#connHint {
  position: fixed; left: 50%; top: 14px; transform: translateX(-50%);
  background: rgba(13,17,23,0.85);
  padding: 6px 14px; border-radius: 20px;
  font-size: 13px; color: #7d8590; display: none;
}

/* Overlays */
.overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(30,40,55,0.6), rgba(5,8,12,0.92));
  z-index: 10;
}
.panel {
  background: rgba(22,27,34,0.95);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 16px;
  padding: 32px 34px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.panel h1 {
  font-size: 44px; font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(120deg, #4ade80, #22d3ee);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  margin-bottom: 6px;
}
.tag { color: #9aa4af; font-size: 14px; margin-bottom: 18px; }

#name, #authName, #authPass {
  width: 100%; padding: 12px 14px; font-size: 16px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.14);
  background: #0d1117; color: #e6edf3; outline: none; margin-bottom: 14px;
}
#name:focus, #authName:focus, #authPass:focus { border-color: #4ade80; }
#name:disabled { opacity: 0.7; }

.nameRow { display: flex; gap: 8px; }
.nameRow #name { margin-bottom: 0; }
.nameRow .iconbtn { flex: none; width: 44px; padding: 0; font-size: 17px; }
.iconbtn.confirm { background: linear-gradient(120deg, #16a34a, #0891b2); border-color: transparent; color: #fff; }
.iconbtn.cancel { background: #21262d; }
#nameMsg { min-height: 0; }
#nameMsg:not(:empty) { margin: 6px 0 4px; }

/* Account section + avatar */
#account { font-size: 13px; color: #9aa4af; margin-bottom: 10px; min-height: 20px; }
#account .who { color: #e6edf3; font-weight: 700; }
#account .check { color: #4ade80; }
#account a { color: #4ade80; cursor: pointer; text-decoration: underline; margin: 0 4px; }
.avatarRow { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
#avatarPreview {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: #0d1117 center/cover no-repeat;
  flex: none;
}
#pickImage { flex: 1; padding: 10px; font-size: 13px; }
.err { color: #f87171; font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.linkbtn { background: none; border: none; color: #9aa4af; text-decoration: underline; margin-top: 12px; }
.linkbtn:hover { background: none; color: #e6edf3; }

/* Leaderboard registered check */
#leaderboard li .check { color: #4ade80; margin-left: 4px; }

.btnrow { display: flex; gap: 10px; }
button {
  flex: 1; padding: 12px 10px; font-size: 15px; font-weight: 700;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.14);
  background: #21262d; color: #e6edf3; cursor: pointer;
  transition: transform .06s ease, background .15s ease;
}
button:hover { background: #2d333b; }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(120deg, #16a34a, #0891b2);
  border-color: transparent; color: #fff;
}
button.primary:hover { filter: brightness(1.08); }

.controls {
  list-style: none; margin-top: 18px; font-size: 13px; color: #9aa4af;
  display: flex; flex-direction: column; gap: 4px;
}
.controls b { color: #e6edf3; }

#buildTag {
  margin-top: 14px; font-size: 11px; color: #4ade80;
  opacity: 0.75; letter-spacing: 0.3px;
}

/* Settings / controls panel */
#bindRows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.bindRow {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; color: #cbd5e1;
}
.bindRow .keybtn {
  flex: none; min-width: 96px; padding: 7px 12px; font-size: 13px; font-weight: 700;
  background: #0d1117; border: 1px solid rgba(255,255,255,0.14);
  border-radius: 8px; color: #e6edf3;
}
.bindRow .keybtn.listening { border-color: #4ade80; color: #4ade80; }
.qcTitle { margin: 16px 0 4px; font-size: 15px; }
.qcRow { gap: 8px; margin-bottom: 8px; }
.qcRow .keybtn { min-width: 72px; }
.qcRow input { flex: 1; margin: 0; padding: 7px 10px; font-size: 13px; background: #0d1117; border: 1px solid rgba(255,255,255,0.14); border-radius: 8px; color: #e6edf3; }
.splitSel { margin-bottom: 16px; }
.splitSel > span { display: block; font-size: 13px; color: #9aa4af; margin-bottom: 6px; }
.splitSel button.active {
  background: linear-gradient(120deg, #16a34a, #0891b2); border-color: transparent; color: #fff;
}

/* Zoom controls (bottom-right) */
#zoomCtl {
  position: fixed; right: 16px; bottom: 16px;
  display: flex; flex-direction: column; gap: 6px; z-index: 5;
}
#zoomCtl button {
  width: 42px; height: 42px; padding: 0; font-size: 22px; font-weight: 700;
  border-radius: 10px; background: rgba(13,17,23,0.72);
  border: 1px solid rgba(255,255,255,0.12); color: #e6edf3;
  backdrop-filter: blur(6px);
}
#zoomCtl button:hover { background: rgba(45,51,59,0.85); }

/* Global-server reset countdown: bottom-right, just above the zoom controls.
   Desktop only (hidden on touch, where zoom controls are also hidden). */
#resetTimer {
  position: fixed; right: 16px; bottom: 116px; z-index: 5;
  padding: 5px 10px; border-radius: 8px;
  background: rgba(13,17,23,0.72); border: 1px solid rgba(255,255,255,0.12);
  color: #cbd5e1; font-size: 12px; font-weight: 600; letter-spacing: .3px;
  backdrop-filter: blur(6px); white-space: nowrap; pointer-events: none;
}
@media (pointer: coarse) { #resetTimer { display: none !important; } }

/* Split action buttons (one per split type), bottom-centre */
#splitCtl {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 5;
}
#splitCtl button {
  padding: 9px 14px; font-size: 14px; font-weight: 700;
  border-radius: 10px; background: rgba(13,17,23,0.72);
  border: 1px solid rgba(255,255,255,0.12); color: #e6edf3;
  backdrop-filter: blur(6px);
}
#splitCtl button:hover { background: rgba(45,51,59,0.85); }
#splitCtl button:active { transform: translateY(1px); }

/* Off-screen holder so animated GIF avatars keep advancing frames
   (display:none would pause them; off-screen positioning does not). */
#imgHolder { position: fixed; left: -99999px; top: 0; width: 1px; height: 1px; overflow: hidden; }

/* Menu layout: play panel + wall panel side by side */
.menuWrap {
  display: flex; gap: 16px; flex-wrap: wrap;
  align-items: flex-start; justify-content: center;
  max-width: 96vw; max-height: 94vh;
}
.wallPanel { width: min(92vw, 360px); text-align: left; display: flex; flex-direction: column; }
.roomsPanel { width: min(92vw, 360px); text-align: left; display: flex; flex-direction: column; }

/* Menu tabs — shown only on mobile to switch between Igra / Razgovor / Sobe. */
#menuTabs { display: none; width: 100%; gap: 8px; }
#menuTabs button.active { background: linear-gradient(120deg, #16a34a, #0891b2); border-color: transparent; color: #fff; }

@media (max-width: 768px), (pointer: coarse) {
  #menuTabs { display: flex; }
  .menuWrap { flex-direction: column; align-items: stretch; gap: 12px; width: min(94vw, 380px); max-height: 94vh; }
  .menuWrap > .panel { width: auto; max-height: 80vh; overflow-y: auto; }
  .menuWrap[data-tab="play"] .wallPanel, .menuWrap[data-tab="play"] .roomsPanel { display: none; }
  .menuWrap[data-tab="wall"] > .panel:not(.wallPanel) { display: none; }
  .menuWrap[data-tab="rooms"] > .panel:not(.roomsPanel) { display: none; }
  /* Tab already labels the panel, so drop the panel title on mobile. */
  .wallTitle, .roomsTitle { display: none; }
}
/* Discord link on the main menu panel. */
#discordLink {
  display: inline-flex; align-items: center; gap: 8px;
  margin: 4px 0 12px; padding: 8px 14px; border-radius: 10px;
  background: #5865F2; color: #fff; text-decoration: none;
  font-weight: 700; font-size: 14px;
}
#discordLink:hover { background: #4752c4; }

/* Push toggle on the main panel (shown to registered users). Button on top,
   status/help text beneath so longer unblock instructions read cleanly. */
.pushRow { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; margin: 4px 0 12px; text-align: left; }
.pushRow button { flex: none; }
.pushHint { font-size: 12px; color: #7d8590; line-height: 1.35; }

.roomsPanel h1 { font-size: 30px; }
.roomsPanel h3 { margin: 0 0 8px; font-size: 14px; color: #9aa4ad; text-transform: uppercase; letter-spacing: .04em; }
.roomsBlock { margin-bottom: 16px; }
.roomToggle { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; cursor: pointer; }
.roomToggle input { width: auto; margin: 0; }
.roomSettings { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.roomSettings label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: #9aa4ad; }
.roomSettings input { width: 84px; margin: 0; padding: 5px 8px; font-size: 13px; text-align: right; }
.roomsBtnrow { margin-top: 4px; }
.roomsNote { font-size: 12px; color: #7d8590; margin-top: 6px; min-height: 14px; }
#roomUserSearch { margin-bottom: 8px; }
.roomsList { max-height: 26vh; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.roomsList:empty::after { content: "—"; color: #545d68; font-size: 13px; }
.roomRow { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.05); padding: 5px 9px; border-radius: 8px; }
.roomRow .rn { flex: 1; word-break: break-word; font-size: 13px; }
.roomRow button { flex: none; padding: 5px 12px; font-size: 12px; }
.roomRow button:disabled { opacity: .55; }
.liveDot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #4ade80; margin-right: 6px; vertical-align: middle; box-shadow: 0 0 5px #4ade80; }
.wallPanel h1 { font-size: 30px; }
#wallLog {
  flex: 1; min-height: 150px; max-height: 44vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px;
  font-size: 13px; line-height: 1.35;
}
#wallLog .wmsg { background: rgba(255,255,255,0.05); padding: 5px 9px; border-radius: 8px; word-break: break-word; }
#wallLog .wmsg b { color: #4ade80; margin-right: 6px; }
#wallLog .wmsg .time { color: #7d8590; font-size: 11px; margin-left: 6px; }
#wallCompose { display: flex; gap: 8px; }
#wallInput { flex: 1; margin-bottom: 0; }
#wallSend { flex: none; width: 48px; padding: 0; display: flex; align-items: center; justify-content: center; }
#wallNote { font-size: 12px; color: #7d8590; margin-top: 8px; }
.wallHint { margin-top: 10px; margin-bottom: 0; }

/* Mobile chat: hidden by default, shown on small screens */
#mobileChat { display: none; }
#mobileChatLog { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 6px 10px; font-size: 13px; }
#mobileChatLog .msg { background: rgba(255,255,255,0.06); padding: 2px 8px; border-radius: 8px; width: fit-content; max-width: 100%; word-break: break-word; }
#mobileChatLog .msg b { color: #4ade80; margin-right: 5px; }
#mobileChatBar { display: flex; gap: 6px; padding: 6px; }
#mobileChatInput { flex: 1; display: none; padding: 10px; font-size: 15px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.14); background: #0d1117; color: #e6edf3; outline: none; }
#mobileChat.typing #mobileChatInput { display: block; }
#mobileChatBtn { flex: none; width: 48px; height: 40px; font-size: 18px; padding: 0; border-radius: 8px; }

@media (max-width: 768px), (pointer: coarse) {
  /* Bottom 20% chat strip on mobile; hide the desktop floating chat window. */
  #chat { display: none !important; }
  body.playing #mobileChat {
    display: flex; flex-direction: column;
    position: fixed; left: 0; right: 0; bottom: 0; height: 20vh;
    background: rgba(13,17,23,0.85); border-top: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(6px); z-index: 6;
  }
  /* Minimap at half size */
  #minimap { width: 90px; height: 90px; }
  /* Leaderboard text at half size */
  #leaderboard { min-width: 92px; padding: 6px 8px 8px; }
  #leaderboard h3 { font-size: 8px; margin-bottom: 4px; }
  #leaderboard li { font-size: 8px; padding: 1px 0; }
  /* Keep split/zoom controls clear of the chat strip */
  #splitCtl { bottom: calc(20vh + 10px); }
  #zoomCtl { bottom: calc(20vh + 10px); }
}

@media (max-width: 480px) {
  #minimap { width: 90px; height: 90px; }
}

/* In-game HUD/controls are hidden on the homepage; shown only while playing. */
#hud, #zoomCtl, #splitCtl { display: none; }
body.playing #hud { display: block; }
body.playing #zoomCtl { display: flex; }
/* Mobile/touch: no on-screen split or zoom buttons (double-tap splits; zoom is
   automatic). Split keys are used on desktop, so the buttons stay hidden there too. */
@media (pointer: coarse) {
  body.playing #zoomCtl { display: none; }
}
