* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #7cc7ff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: #1d1f2b;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 22, 40, .35), rgba(20, 22, 40, .7));
}
#loading { background: #7cc7ff; z-index: 40; }
.spinner {
  width: 56px; height: 56px; border-radius: 50%;
  border: 8px solid #11121a; border-top-color: #7c5cff;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  width: min(420px, 100%);
  max-height: calc(100% - 16px); overflow-y: auto;
  background: #fff; border-radius: 22px;
  padding: 24px 22px 20px;
  box-shadow: 0 10px 0 rgba(0,0,0,.18), 0 20px 50px rgba(0,0,0,.25);
  text-align: center;
}
.card.small { width: min(320px, 100%); }
.card h2 { margin: 0 0 6px; font-size: 30px; }
.logo {
  margin: 0; font-size: 52px; letter-spacing: 2px; line-height: 1;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  font-weight: 900;
}
.logo-hole {
  width: 48px; height: 48px; border-radius: 50%;
  background: radial-gradient(circle at 50% 55%, #000 55%, #2a2340 70%);
  box-shadow: 0 0 0 6px var(--skin, #7c5cff);
}
.tag { margin: 8px 0 16px; color: #5b6075; font-size: 15px; }
.field { display: block; text-align: left; margin: 12px 0; }
.field > span { display: block; font-size: 12px; font-weight: 700; color: #7a7f95; margin-bottom: 6px; letter-spacing: .5px; text-transform: uppercase; }
#name {
  width: 100%; font: inherit; font-size: 18px; font-weight: 700;
  padding: 10px 14px; border-radius: 12px; border: 3px solid #e3e5ee; outline: none;
}
#name:focus { border-color: #7c5cff; }
#skins { display: flex; flex-wrap: wrap; gap: 8px; }
.skin {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 0 0 2px #e3e5ee; cursor: pointer; padding: 0;
}
.skin.selected { box-shadow: 0 0 0 3px #1d1f2b; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.mode {
  font: inherit; cursor: pointer; padding: 10px 6px; border-radius: 14px;
  background: #f2f3f8; border: 3px solid transparent; color: inherit;
}
.mode b { display: block; font-size: 18px; }
.mode small { color: #7a7f95; }
.mode.selected { border-color: #7c5cff; background: #f0ecff; }
button.primary, button.secondary {
  display: block; width: 100%; font: inherit; font-weight: 900; cursor: pointer;
  border: none; border-radius: 16px; padding: 14px; margin-top: 10px;
}
button.primary {
  font-size: 24px; color: #fff; background: #7c5cff;
  box-shadow: 0 6px 0 #5534d6; letter-spacing: 1px;
}
button.primary:active { transform: translateY(4px); box-shadow: 0 2px 0 #5534d6; }
button.secondary { font-size: 16px; color: #5b6075; background: #f2f3f8; }
.best { margin: 14px 0 2px; font-size: 14px; color: #5b6075; }
.hint { margin: 4px 0 0; font-size: 12px; color: #9aa0b5; }

#res-board { list-style: none; margin: 10px 0 6px; padding: 0; text-align: left; }
#res-board li {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px; font-weight: 700;
}
#res-board li:nth-child(odd) { background: #f5f6fa; }
#res-board li.me { background: #f0ecff; outline: 2px solid #7c5cff; }
#res-board .rank { width: 26px; color: #7a7f95; }
#res-board .dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
#res-board .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud-left { position: absolute; left: 14px; top: 12px; display: flex; flex-direction: column; gap: 8px; }
#score-box, #size-box, #timer, #board {
  background: rgba(255,255,255,.88); border-radius: 14px;
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
#score-box { padding: 6px 14px; display: flex; align-items: baseline; gap: 8px; }
#score { font-size: 28px; font-weight: 900; }
#score-box small, #size-box small { font-size: 11px; font-weight: 800; color: #7a7f95; letter-spacing: 1px; }
#size-box { padding: 8px 12px; width: 150px; }
#size-bar { height: 10px; border-radius: 6px; background: #e3e5ee; overflow: hidden; margin-bottom: 4px; }
#size-fill { height: 100%; width: 0; background: var(--skin, #7c5cff); transition: width .15s; }
#timer {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%);
  font-size: 30px; font-weight: 900; padding: 4px 18px; min-width: 100px; text-align: center;
}
#timer.low { color: #ff3b5c; animation: pulse 1s infinite; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.08); } }
#board {
  position: absolute; right: 14px; top: 12px; list-style: none; margin: 0;
  padding: 6px 8px; width: 190px; font-size: 14px; font-weight: 700;
}
#board li { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 6px; }
#board li.me { background: rgba(124,92,255,.15); }
#board .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#board .nm { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#board .rank { width: 16px; color: #7a7f95; }
#feed {
  position: absolute; left: 50%; top: 64px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
#feed div {
  background: rgba(17,18,26,.75); color: #fff; font-weight: 700; font-size: 14px;
  padding: 4px 12px; border-radius: 10px; animation: fadeout 3s forwards;
}
@keyframes fadeout { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
#hud-buttons { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 46px; height: 46px; border-radius: 14px; border: none; cursor: pointer;
  background: rgba(255,255,255,.88); font-size: 18px; font-weight: 900; color: #1d1f2b;
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
#banner {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%);
  font-size: 44px; font-weight: 900; color: #fff; text-align: center;
  text-shadow: 0 4px 0 rgba(0,0,0,.35); white-space: nowrap;
}

/* floating labels & popups */
#labels { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.hole-label {
  position: absolute; transform: translate(-50%, -100%);
  font-weight: 900; font-size: 14px; color: #fff; white-space: nowrap;
  text-shadow: 0 2px 0 rgba(0,0,0,.45), 0 0 4px rgba(0,0,0,.4);
}
.popup {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 900; color: #fff; font-size: 18px;
  text-shadow: 0 2px 0 rgba(0,0,0,.4);
  animation: rise .9s ease-out forwards;
}
@keyframes rise { to { transform: translate(-50%, -260%); opacity: 0; } }

#joystick {
  position: fixed; z-index: 6; width: 120px; height: 120px; margin: -60px 0 0 -60px;
  border-radius: 50%; background: rgba(255,255,255,.18); border: 3px solid rgba(255,255,255,.5);
  pointer-events: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; background: rgba(255,255,255,.75);
}

@media (max-width: 600px) {
  #timer { font-size: 22px; min-width: 76px; padding: 4px 10px; }
  #score { font-size: 20px; }
  #size-box { width: 110px; padding: 6px 10px; }
  #board { width: 140px; font-size: 12px; right: 8px; top: 8px; }
  #hud-left { left: 8px; top: 8px; }
  #feed { top: 50px; }
  #feed div { font-size: 12px; }
  .logo { font-size: 42px; }
  .hole-label { font-size: 12px; }
  #banner { font-size: 32px; }
}
@media (max-width: 380px) {
  #board li:nth-child(n+5):not(.me) { display: none; }
}
