:root {
  --accent: #3e8ee0;
  --accent-deep: #2f7fd0;
  --line: #c7d6e6;
  --ink: #2b3646;
  --card: #ffffff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, #e9f2fb 0%, #d8e7f6 55%, #cfe0f2 100%);
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.overlay {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(120% 120% at 50% 20%, rgba(255,255,255,.3), rgba(118,164,214,.38));
  z-index: 10; padding: 16px;
}
.card {
  background: var(--card); border-radius: 22px; padding: 26px 28px 22px;
  max-width: 480px; width: 100%; box-shadow: 0 18px 50px rgba(46, 84, 130, .3);
  max-height: 92vh; overflow: auto;
}
.card h1 {
  margin: 0 0 4px; font-size: 30px; letter-spacing: .5px;
  background: linear-gradient(90deg, #2f7fd0, #36a08c);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.card .sub { margin: 0 0 18px; font-size: 14px; opacity: .75; }
.row { margin-bottom: 14px; }
.row > label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; opacity: .8; }
input {
  width: 100%; padding: 11px 14px; font-size: 15px; border-radius: 14px;
  border: 2px solid var(--line); outline: none; background: #f6f9fc; color: var(--ink);
}
input:focus { border-color: var(--accent); }
.hint-inline { display: block; font-size: 11.5px; opacity: .6; margin-top: 4px; }

.picker {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px;
}
.picker .ball {
  border: 2.5px solid transparent; border-radius: 16px; padding: 6px 4px 3px;
  background: #f4f8fc; cursor: pointer; text-align: center; transition: transform .12s;
}
.picker .ball:hover { transform: scale(1.06); }
.picker .ball.sel { border-color: var(--accent); background: #eaf2fb; }
.picker img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.picker .ball span { font-size: 10px; font-weight: 700; opacity: .75; }

button.primary {
  width: 100%; padding: 14px; font-size: 17px; font-weight: 800; letter-spacing: .4px;
  color: #fff; border: none; border-radius: 16px; cursor: pointer;
  background: linear-gradient(90deg, #3e8ee0, #2f7fd0); box-shadow: 0 8px 20px rgba(47, 127, 208, .42);
}
button.primary:disabled { opacity: .55; cursor: wait; }
button.primary:not(:disabled):active { transform: scale(.98); }
.note { font-size: 11.5px; opacity: .65; margin: 14px 0 0; line-height: 1.5; }
.note code { background: #eef4fa; padding: 1px 5px; border-radius: 6px; }

/* ---- menu extras: country + studio button ---- */
.row2col { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; align-items: end; }
.row2col > div > label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; opacity: .8; }
select {
  width: 100%; padding: 10px 12px; font-size: 14px; border-radius: 14px;
  border: 2px solid var(--line); outline: none; background: #f6f9fc; color: var(--ink);
  font-family: inherit;
}
select:focus { border-color: var(--accent); }
button.soft {
  width: 100%; padding: 10px 14px; font-size: 14px; font-weight: 800; cursor: pointer;
  border: 2px solid var(--line); border-radius: 14px; background: #f4f8fc; color: var(--ink);
  transition: transform .1s;
}
button.soft:hover { border-color: var(--accent); }
button.soft:active { transform: scale(.97); }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud .chip {
  position: absolute; top: 12px; display: flex; gap: 8px; align-items: center;
  pointer-events: auto;
}
#hud .chip.left { left: 12px; }
#hud .chip.right { right: 12px; }
.chip span {
  background: rgba(255,255,255,.92); border-radius: 999px; padding: 7px 14px;
  font-size: 12.5px; font-weight: 700; box-shadow: 0 4px 14px rgba(46,84,130,.22);
}
.dot { width: 12px; height: 12px; border-radius: 50%; padding: 0 !important; }
.dot.connecting { background: #ffcf5c; }
.dot.online { background: #6fdc8c; box-shadow: 0 0 0 4px rgba(111,220,140,.25); }
.dot.reconnecting { background: #ff9d5c; }
.dot.offline { background: #ff6b6b; }
#playersChip { cursor: pointer; }
#playersChip:hover { background: #eaf2fb; }

/* ---- players panel ---- */
#plist {
  position: absolute; left: 12px; top: 52px; width: 302px; max-height: min(58vh, 430px);
  display: flex; flex-direction: column; pointer-events: auto;
  background: rgba(255,255,255,.96); border-radius: 18px; overflow: hidden;
  box-shadow: 0 10px 30px rgba(46,84,130,.3);
}
.plhead {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: #eaf2fb; border-bottom: 1px solid var(--line); font-size: 13px; font-weight: 800;
}
.plhead b { margin-left: auto; font-size: 12px; color: var(--accent-deep); }
#plClose {
  border: none; background: transparent; font-size: 14px; cursor: pointer; color: var(--ink);
  padding: 2px 6px; border-radius: 8px;
}
#plClose:hover { background: #dbe7f5; }
#plRows { overflow-y: auto; padding: 6px; }
.plrow {
  display: flex; align-items: center; gap: 7px; padding: 6px 8px; border-radius: 12px;
  font-size: 12.5px; font-weight: 700; line-height: 1.15;
}
.plrow:hover { background: #f0f6fc; }
.plrow.you { background: #eef7ee; }
.plrow .plball { width: 22px; height: 22px; object-fit: contain; flex: 0 0 22px; }
.plrow .plflag { flex: 0 0 auto; font-size: 14px; }
.plrow .plname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plrow .plname i { font-style: normal; font-size: 10.5px; opacity: .6; }
.plrow .plctry {
  flex: 0 0 auto; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 10.5px; opacity: .62; font-weight: 600;
}
.plrow .pldist { flex: 0 0 auto; font-size: 10.5px; opacity: .62; min-width: 30px; text-align: right; }
.plrow .plvisit {
  flex: 0 0 auto; border: 1.5px solid var(--accent); background: #fff; color: var(--accent-deep);
  font-size: 10.5px; font-weight: 800; padding: 3px 9px; border-radius: 999px; cursor: pointer;
}
.plrow .plvisit:hover { background: var(--accent); color: #fff; }

/* ---- ball studio ---- */
.custcard { max-width: 760px; padding: 20px 22px 18px; }
.custhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.custhead h2 { margin: 0; font-size: 22px; background: linear-gradient(90deg, #2f7fd0, #36a08c); -webkit-background-clip: text; background-clip: text; color: transparent; }
.custhead .ghost { margin-left: auto; }
.custbody { display: grid; grid-template-columns: 250px 1fr; gap: 16px; }
.custleft { display: flex; flex-direction: column; gap: 8px; }
#custCv {
  width: 100%; aspect-ratio: 1; border-radius: 18px; display: block;
  background: radial-gradient(120% 120% at 50% 25%, #f2f8ff, #d9e7f6);
  border: 1.5px solid var(--line);
}
.custminibtns { display: flex; gap: 8px; }
.custright { min-width: 0; max-height: calc(92vh - 90px); overflow-y: auto; padding-right: 6px; }
.custright::-webkit-scrollbar { width: 8px; }
.custright::-webkit-scrollbar-thumb { background: #c7d6e6; border-radius: 8px; }
.custright > label {
  display: block; font-size: 12px; font-weight: 800; letter-spacing: .3px;
  margin: 10px 0 6px; opacity: .75; text-transform: uppercase;
}
.custright > label:first-child { margin-top: 0; }
.patgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.pat {
  aspect-ratio: 2.1; border-radius: 9px; border: 2.5px solid #dfe8f2; cursor: pointer;
  background-size: cover; background-position: center; padding: 0;
}
.pat.sel { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(62,142,224,.25); }
.cust2col { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.cust2col > div > label { display: block; font-size: 12px; font-weight: 800; margin-bottom: 5px; opacity: .75; }
.cust2col input[type="color"] {
  width: 44px; height: 38px; padding: 2px; border: 2px solid var(--line); border-radius: 10px;
  background: #f6f9fc; cursor: pointer;
}
.finrow { display: flex; gap: 6px; flex-wrap: wrap; }
.fin {
  padding: 7px 13px; font-size: 12px; font-weight: 800; cursor: pointer;
  border: 2px solid var(--line); border-radius: 999px; background: #f6f9fc; color: var(--ink);
}
.fin.sel { border-color: var(--accent); background: #eaf2fb; color: var(--accent-deep); }
.gearcat { font-size: 11px; font-weight: 800; opacity: .55; margin: 8px 0 5px; text-transform: uppercase; letter-spacing: .5px; }
.geargrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.gearitem {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 3px 5px; border-radius: 12px; border: 2px solid #dfe8f2;
  background: #f6f9fc; cursor: pointer; font-size: 9.5px; font-weight: 700; color: var(--ink);
}
.gearitem .gi { font-size: 16px; line-height: 1; }
.gearitem:hover { border-color: #b8d0ea; }
.gearitem.sel { border-color: var(--accent); background: #eaf2fb; box-shadow: 0 0 0 2.5px rgba(62,142,224,.22); }

button.ghost {
  pointer-events: auto; border: none; background: rgba(255,255,255,.92); color: var(--ink);
  border-radius: 999px; padding: 7px 16px; font-size: 12.5px; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 14px rgba(46,84,130,.22);
}
.hint {
  max-width: 96vw; overflow: hidden; text-overflow: ellipsis;
  position: absolute; bottom: 44px; left: 50%; transform: translateX(-50%);
  font-size: 12.5px; font-weight: 700; opacity: .7; background: rgba(255,255,255,.78);
  padding: 7px 16px; border-radius: 999px; white-space: nowrap;
}

/* ---- chat ---- */
#chatBox { position: absolute; left: 14px; bottom: 14px; width: 360px; }
#chatLog { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.chatline {
  background: rgba(255,255,255,.94); border-radius: 14px; padding: 6px 12px;
  font-size: 12.5px; line-height: 1.35; box-shadow: 0 3px 10px rgba(46,84,130,.18);
  width: fit-content; max-width: 100%; overflow-wrap: anywhere;
  transition: opacity 1.2s;
}
.chatline b { margin-right: 2px; }
.chatline.sys { font-style: italic; opacity: .78; }
.chatline.old { opacity: 0; }
#chatBar { display: flex; gap: 6px; align-items: stretch; pointer-events: auto; }
#chatBtn {
  width: 44px; height: 44px; border-radius: 50%; border: 2.5px solid #9fc3e8;
  background: rgba(255,255,255,.92); cursor: pointer; display: flex;
  align-items: center; justify-content: center; flex: 0 0 44px;
  box-shadow: 0 4px 14px rgba(46,84,130,.22); transition: transform .1s;
}
#chatBtn:active { transform: scale(.9); }
#chatIn {
  flex: 1; padding: 10px 14px; font-size: 13.5px; border-radius: 999px;
  border: 2px solid var(--line); outline: none; background: #f6f9fc; color: var(--ink);
  min-width: 0;
}
#chatIn:focus { border-color: var(--accent); }
#chatSend { border-radius: 999px; padding: 8px 16px; font-size: 13px; flex: 0 0 auto; }

/* ---- boost ---- */
#boostMeter {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  width: 180px; height: 20px; border-radius: 999px; overflow: hidden;
  background: rgba(255,255,255,.88); border: 2px solid var(--line);
  box-shadow: 0 4px 14px rgba(46,84,130,.22);
}
#boostFill {
  height: 100%; width: 100%; border-radius: 999px;
  background: linear-gradient(90deg, #f5a623, #ef7d1a);
  transition: width .12s linear;
}
#boostMeter.active { border-color: #ef9c1a; box-shadow: 0 0 14px rgba(239,156,26,.55); }
.bmlabel {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 900; letter-spacing: 1.5px; color: #a86a20;
}
#boostBtn {
  position: absolute; right: 210px; bottom: 34px; width: 66px; height: 66px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 3px solid #59c3d8; color: #2c9ab3;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px;
  pointer-events: auto; touch-action: none; user-select: none;
}
#joy {
  position: absolute; left: 26px; bottom: 26px; width: 108px; height: 108px;
  border-radius: 50%; background: rgba(255,255,255,.35); border: 3px solid rgba(255,255,255,.7);
  pointer-events: auto; touch-action: none;
}
#joyKnob {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; border-radius: 50%;
  background: rgba(255,255,255,.9); transform: translate(-50%, -50%);
  box-shadow: 0 4px 12px rgba(46,84,130,.3);
}
#emoteBtn {
  position: absolute; right: 34px; bottom: 148px; width: 56px; height: 56px; border-radius: 50%;
  background: rgba(255,255,255,.88); border: 3px solid var(--line); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 13px; letter-spacing: .5px;
  pointer-events: auto; touch-action: manipulation; user-select: none; cursor: pointer;
  box-shadow: 0 4px 14px rgba(46,84,130,.22); transition: transform .1s;
}
#emoteBtn:active { transform: scale(.9); }
#jumpBtn {
  position: absolute; right: 30px; bottom: 40px; width: 86px; height: 86px; border-radius: 50%;
  background: rgba(255,255,255,.88); border: 3px solid var(--accent); color: var(--accent-deep);
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 15px;
  letter-spacing: 1px; pointer-events: auto; touch-action: none; user-select: none;
}
#slamBtn {
  position: absolute; right: 130px; bottom: 34px; width: 66px; height: 66px; border-radius: 50%;
  background: rgba(255,255,255,.85); border: 3px solid #ffa14e; color: #e5822c;
  display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px;
  pointer-events: auto; touch-action: none; user-select: none;
}
.marker {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto; cursor: pointer;
  border: 2px solid var(--accent); background: rgba(255,255,255,.94); color: var(--ink);
  border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 800; white-space: nowrap;
}
#toasts { position: absolute; top: 58px; left: 50%; transform: translateX(-50%); }
.toast {
  background: rgba(255,255,255,.94); border-radius: 999px; padding: 7px 16px; font-size: 12.5px;
  font-weight: 700; margin-top: 6px; box-shadow: 0 4px 14px rgba(46,84,130,.22);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
.hidden { display: none !important; }
@media (max-width: 560px) {
  .card { padding: 20px 16px 16px; }
  .picker { grid-template-columns: repeat(4, 1fr); }
  .hint { display: none; }
  #hud .chip.left { flex-direction: column; align-items: flex-start; gap: 5px; }
  #chatBox { left: 150px; bottom: 16px; width: min(300px, calc(100vw - 168px)); }
  #chatBtn { width: 40px; height: 40px; flex-basis: 40px; }
  #boostMeter { bottom: 104px; width: 140px; }
  #plist { left: 8px; right: 8px; width: auto; top: 96px; }
  .custcard { max-height: 94vh; }
  .custbody { grid-template-columns: 1fr; }
  #custCv { width: min(240px, 70vw); margin: 0 auto; }
  .patgrid { grid-template-columns: repeat(6, 1fr); }
  .geargrid { grid-template-columns: repeat(4, 1fr); }
}
