/* Shuffleborg — themed via CSS custom properties set by client.js */

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

:root {
  --bg1: #ffe4ef; --bg2: #efb7cf;
  --card: rgba(255, 255, 255, 0.5);
  --ink: #57394a;
  --dim: rgba(87, 57, 74, 0.55);
  --accent: #d4547e;
  --accent2: #b47fd6;
  --blob1: #ffb3ca; --blob2: #d8b4f0; --blob3: #ffd9b3;
  --p0: #e8638c; --p1: #6fae9e;
  --btn: rgba(255, 255, 255, 0.55);
  --btn-hi: rgba(255, 255, 255, 0.85);
  --edge: rgba(255, 255, 255, 0.6);
  --edge-soft: rgba(0, 0, 0, 0.08);
}

html, body { height: 100%; }

body {
  font-family: 'Nunito', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 120% at 50% 0%, var(--bg1), var(--bg2));
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

h1, h2, .mode, .stackbtn, .roomcode, .pscore, #banner, #frameNo, #delta, .toast, .seg button {
  font-family: 'Fredoka', 'Nunito', system-ui, sans-serif;
}

/* ---------------- living background ---------------- */

#bgfx { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.55; }
.blob.b0 { width: 46vmax; height: 46vmax; top: -14vmax; left: -12vmax; background: var(--blob1); animation: blob1 17s ease-in-out infinite alternate; }
.blob.b1 { width: 38vmax; height: 38vmax; bottom: -12vmax; right: -10vmax; background: var(--blob2); animation: blob2 21s ease-in-out infinite alternate; }
.blob.b2 { width: 28vmax; height: 28vmax; top: 38%; left: 58%; background: var(--blob3); animation: blob3 25s ease-in-out infinite alternate; }
@keyframes blob1 { to { transform: translate(7vmax, 5vmax) scale(1.12); } }
@keyframes blob2 { to { transform: translate(-6vmax, -7vmax) scale(1.15); } }
@keyframes blob3 { to { transform: translate(-8vmax, 6vmax) scale(0.9); } }

.drift {
  position: absolute; top: -8vh;
  opacity: 0.5;
  animation-name: fall;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes fall {
  to { transform: translateY(125vh) rotate(80deg); }
}
body.playing .drift { display: none; }

.hidden { display: none !important; }
.dim { color: var(--dim); }

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  overflow-x: hidden; /* the logo puck flies in from off-screen */
}

/* ---------------- lobby ---------------- */

.logo { text-align: center; margin: 4vh 0 2vh; animation: logo-in 0.7s ease-out; }
.logo h1 {
  display: flex; justify-content: center; align-items: center;
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  line-height: 1;
  font-weight: 700;
  filter: drop-shadow(0 5px 14px rgba(120, 70, 95, 0.28));
  cursor: pointer; /* tap to replay the intro animation */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
/* big bubbly letters, popping in one after another */
.bl {
  display: inline-block;
  padding: 0 0.015em;
  animation: letter-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) backwards;
  animation-delay: calc(var(--i) * 60ms);
}
.bl:nth-child(4n + 1) { color: var(--accent); }
.bl:nth-child(4n + 2) { color: var(--p0); }
.bl:nth-child(4n + 3) { color: var(--accent2); }
.bl:nth-child(4n + 4) { color: var(--p1); }
@keyframes letter-pop {
  from { transform: translateY(-55px) scale(0.3); opacity: 0; }
  65% { transform: translateY(6px) scale(1.12); opacity: 1; }
}
/* the O in BORG is a puck that slides in from the right and parks */
.puckslot { animation: none; }
#logoPuck {
  display: block;
  width: 0.82em; height: 0.82em; margin: 0 0.04em;
  border-radius: 50%;
  position: relative;
  background: radial-gradient(
    circle at 33% 28%,
    color-mix(in srgb, var(--p0) 40%, white),
    var(--p0) 62%,
    color-mix(in srgb, var(--p0) 60%, black)
  );
  box-shadow:
    inset 0 0 0 0.05em color-mix(in srgb, var(--p0) 55%, black),
    0 0.08em 0.22em rgba(60, 20, 40, 0.35);
  animation: puck-roll-in 1s cubic-bezier(0.22, 1.15, 0.36, 1) 0.8s backwards;
}
#logoPuck::before {
  content: '';
  position: absolute; inset: 22%;
  border-radius: 50%;
  border: 0.045em solid rgba(255, 255, 255, 0.45);
}
#logoPuck::after {
  content: '';
  position: absolute; left: 22%; top: 16%;
  width: 30%; height: 17%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  transform: rotate(-32deg);
}
@keyframes puck-roll-in {
  from { transform: translateX(58vw) rotate(630deg); opacity: 0; }
  20% { opacity: 1; }
  80% { transform: translateX(-0.08em) rotate(-14deg) scale(1.1, 0.92); }
  to { transform: none; }
}
@keyframes logo-in { from { transform: translateY(-10px); opacity: 0; } }
.logo .tag { color: var(--dim); letter-spacing: 0.3em; text-transform: uppercase; font-size: 0.72rem; margin-top: 0.4rem; }

.card {
  width: min(430px, 92vw);
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 34px rgba(110, 60, 85, 0.18);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); }

input, select {
  font: inherit;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--edge-soft);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input::placeholder { color: var(--dim); }
input:focus, select:focus { border-color: var(--accent); }
select option { color: #222; }

.optrow { display: flex; gap: 10px; }
.optrow .field { flex: 1; }

.themes { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-chip {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 3px 10px rgba(110, 60, 85, 0.18);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  padding: 0;
  transform: rotate(-18deg);
  transition: transform 0.15s;
}
.theme-chip:hover { transform: rotate(-18deg) scale(1.12); }
.theme-chip.on { border-color: var(--accent); transform: rotate(0deg) scale(1.12); }
.theme-chip i { flex: 1; }

.seg { display: flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--edge-soft); }
.seg button {
  flex: 1; padding: 9px 0; font: inherit; font-size: 0.85rem;
  background: transparent; color: var(--dim); border: 0; cursor: pointer;
}
.seg button.on { background: var(--btn-hi); color: var(--ink); font-weight: 700; }

.modes { display: flex; flex-direction: column; gap: 9px; margin-top: 4px; }
.mode {
  font: inherit; font-weight: 700; color: var(--ink);
  background: var(--btn);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s;
}
.mode:hover {
  background: var(--btn-hi);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 25%, transparent);
}
.mode:active { transform: translateY(1px); }
.mode.big {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff; font-size: 1.05rem; border: 0;
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
}
.mode.big:hover { filter: brightness(1.06); box-shadow: 0 8px 26px color-mix(in srgb, var(--accent) 55%, transparent); }

.joinrow { display: flex; gap: 9px; }
.joinrow input { flex: 1; text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-weight: 700; }
.joinrow .mode { width: 110px; }

.roomcode {
  font-size: 3rem; font-weight: 700; letter-spacing: 0.35em;
  text-align: center; padding: 8px 0 8px 0.35em;
  background: linear-gradient(120deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#waitBox { text-align: center; }
#waitBox .dim { animation: pulse 1.6s infinite; }
.waitpane { display: flex; flex-direction: column; gap: 14px; }
.searchpulse { font-size: 2.8rem; animation: pulse 1.4s infinite; }
.modesub { font-size: 0.68rem; font-weight: 400; color: var(--dim); margin-left: 4px; }

.rules { width: min(430px, 92vw); font-size: 0.8rem; text-align: center; margin: 16px 0 4vh; line-height: 1.5; }
.rules b { color: var(--accent); }

/* ---------------- login + stats + watch ---------------- */

.logsub { font-size: 0.78rem; line-height: 1.4; margin-top: -4px; }
.difsub { font-size: 0.72rem; line-height: 1.35; margin-top: 2px; }

.mestats {
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 10px 12px;
}
.melead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.melead b { font-family: 'Fredoka', sans-serif; font-size: 1.05rem; }
.eloBadge {
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 0.78rem;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2));
  padding: 2px 9px; border-radius: 999px;
}
.mesub { font-size: 0.72rem; margin-top: 3px; }
.linkbtn {
  margin-left: auto; background: none; border: 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: 0.75rem; font-weight: 700;
  text-decoration: underline; padding: 0;
}

.watchhead {
  display: flex; align-items: center; justify-content: space-between;
  font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 1.05rem;
}
#btnRefreshGames {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--btn); border: 1px solid var(--edge); color: var(--ink);
  font-size: 1.05rem; cursor: pointer;
}
#gamesList { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.gameitem {
  display: flex; flex-direction: column; gap: 3px; text-align: left;
  background: var(--btn); border: 1px solid var(--edge); border-radius: 12px;
  padding: 10px 14px; cursor: pointer; font: inherit;
  transition: transform 0.08s, background 0.15s;
}
.gameitem:hover { background: var(--btn-hi); transform: translateY(-1px); }
.gi-names { font-family: 'Fredoka', sans-serif; font-weight: 600; color: var(--ink); }
.gi-meta { font-size: 0.74rem; color: var(--dim); }

/* spectators watch only — no throw controls */
body.spectating #stackRow,
body.spectating #specialRow,
body.spectating #curveWrap,
body.spectating #btnResign { display: none; }

/* practice table: no opponent, no resigning, no puck budget */
body.practice #pcard1,
body.practice #btnResign,
body.practice .dots { display: none; }
#btnClear {
  display: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--btn); color: var(--dim); border: 1px solid var(--edge);
  font-size: 0.9rem; cursor: pointer;
}
body.practice #btnClear { display: block; }

/* ---------------- game ---------------- */

#game { gap: 4px; padding: 8px 8px 10px; overflow: hidden; }

#hud {
  width: min(560px, 100%);
  display: flex; gap: 8px; align-items: stretch;
}
.pcard {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--edge);
  border-radius: 12px;
  padding: 7px 10px;
  transition: box-shadow 0.25s, border-color 0.25s;
}
.pcard.turn {
  border-color: var(--accent);
  box-shadow: 0 0 16px 0 color-mix(in srgb, var(--accent) 45%, transparent);
  transform: scale(1.03);
}
.prow { display: flex; align-items: center; gap: 6px; }
.chip { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.chip.c0 { background: var(--p0); }
.chip.c1 { background: var(--p1); }
.pname { font-size: 0.8rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pscore { font-size: 1.5rem; font-weight: 900; line-height: 1.1; }
.dots { display: flex; gap: 3px; margin-top: 2px; min-height: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); opacity: 0.9; }
.dot.used { opacity: 0.18; }
.pcard0 .dot { background: var(--p0); }

.mid { text-align: center; align-self: center; min-width: 84px; }
#frameNo { font-weight: 800; font-size: 0.9rem; }
#delta { font-weight: 900; font-size: 0.95rem; min-height: 1.2em; }
/* live projection of the frame margin onto the exact-target rule */
#delta.bust { color: #e05f5f; animation: pulse 1.2s infinite; }
#delta.win { color: var(--accent); animation: pulse 1.2s infinite; }
#targetInfo { font-size: 0.68rem; color: var(--dim); }
.pneeds { font-size: 0.62rem; color: var(--dim); min-height: 0.9em; }
.pleft { font-size: 0.62rem; color: var(--dim); margin-top: 2px; }

#banner {
  font-weight: 600; font-size: 0.95rem; letter-spacing: 0.04em;
  min-height: 1.7em; text-align: center;
  padding: 2px 18px; border-radius: 999px;
}
#banner.you {
  color: var(--accent);
  background: var(--btn-hi);
  box-shadow: 0 3px 12px color-mix(in srgb, var(--accent) 30%, transparent);
  animation: pulse 1.6s infinite;
}

#boardWrap { flex: 1; width: 100%; display: flex; justify-content: center; min-height: 0; }
canvas#board { touch-action: none; cursor: crosshair; max-width: 100%; }

#controls {
  width: min(560px, 100%);
  display: flex; align-items: center; gap: 14px; justify-content: center;
  flex-wrap: wrap; /* narrow phones: spill onto a second row, never off-screen */
  row-gap: 6px;
  padding: 0 6px;
  box-sizing: border-box;
  min-height: 44px;
}
@media (max-width: 480px) {
  #controls { gap: 8px; }
  #curve { width: 84px; }
  .stackbtn, .specialbtn { width: 34px; height: 34px; }
}
.ctl-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--dim); }
#stackRow { display: flex; align-items: center; gap: 8px; }
#stackBtns { display: flex; gap: 5px; }
.stackbtn {
  width: 38px; height: 38px; border-radius: 10px;
  font: inherit; font-weight: 800; color: var(--ink);
  background: var(--btn); border: 1px solid var(--edge);
  cursor: pointer;
}
.stackbtn.on { background: var(--accent); color: #fff; border-color: transparent; }
.stackbtn:disabled { opacity: 0.25; cursor: default; }
#curveWrap { display: flex; align-items: center; gap: 8px; }
#curve {
  -webkit-appearance: none; appearance: none;
  width: 110px; height: 6px; border-radius: 3px;
  background: rgba(255, 255, 255, 0.65); border: 0; padding: 0;
}
#curve::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); cursor: pointer;
}
#curve::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25); cursor: pointer;
}
#btnLeave {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--btn); color: var(--dim); border: 1px solid var(--edge);
  font-size: 0.9rem; cursor: pointer;
}
#btnResign {
  height: 34px; min-width: 34px; border-radius: 17px;
  background: var(--btn); color: var(--dim); border: 1px solid var(--edge);
  font-size: 0.9rem; cursor: pointer;
}
#btnResign.confirm {
  background: #e05f5f; color: #fff; border-color: transparent;
  font: inherit; font-size: 0.72rem; font-weight: 800;
  padding: 0 10px;
  animation: pulse 1.2s infinite;
}
#specialRow { display: flex; align-items: center; gap: 8px; }
#specialBtns { display: flex; gap: 5px; }
.specialbtn {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--btn); border: 1px solid var(--edge);
  font-size: 1.1rem; cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
}
.specialbtn:disabled { opacity: 0.25; cursor: default; }
.specialbtn.armed {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  transform: scale(1.15);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 60%, transparent);
  animation: pulse 1.2s infinite;
}
.spectag { font-size: 0.75rem; margin-left: auto; letter-spacing: 2px; }
.spectag .used { opacity: 0.25; filter: grayscale(1); }

/* toasts + overlay */

#toasts {
  position: fixed; top: 14vh; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none; z-index: 20;
}
.toast {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--edge);
  color: var(--ink);
  padding: 10px 22px; border-radius: 999px;
  font-weight: 800; font-size: 1rem;
  animation: toast-in 0.25s ease-out, fadeout 0.5s 2.4s forwards;
  box-shadow: 0 8px 26px rgba(110, 60, 85, 0.25);
}
.toast.big { font-size: 1.5rem; padding: 14px 30px; border-color: var(--accent); color: var(--accent); }

#overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(90, 60, 85, 0.35);
  display: flex; align-items: center; justify-content: center;
}
.overcard {
  background: var(--btn-hi);
  border: 1px solid var(--edge);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 34px 44px;
  text-align: center;
  animation: toast-in 0.3s ease-out;
}
.overcard h2 { font-size: 2rem; font-weight: 900; margin-bottom: 6px; }
.overcard p { color: var(--dim); margin-bottom: 20px; min-height: 1.2em; }
.overbtns { display: flex; gap: 10px; justify-content: center; }
.overbtns .mode { min-width: 130px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes toast-in { from { transform: translateY(-14px) scale(0.92); opacity: 0; } }
@keyframes fadeout { to { opacity: 0; } }
