/* Playnesta shell stylesheet for Ball Sort (Playnesta-original, MIT).
   Tubes and balls are CSS shapes — no sprites, fonts or network assets.
   Sizing is viewport-relative so one page fits the two production stages
   (894x670 desktop and 348x261 phone) with no overflow in either axis: the tube
   height clamps with the viewport, the ball diameter is derived from it, and the
   shelf wraps if seven tubes ever cannot fit on one line. */

* { box-sizing: border-box; }

:root {
  --bg: #101a24;
  --panel: #182734;
  --panel2: #21323f;
  --ink: #eef5fa;
  --muted: #93a8b8;
  --accent: #ffcf5c;
  --tube: rgba(255, 255, 255, 0.05);
  --tube-edge: rgba(255, 255, 255, 0.30);
  --tube-h: clamp(78px, 44vh, 220px);
  --ball-d: calc(var(--tube-h) / 4 - 3px);
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  min-height: 0;
  position: relative;
}

/* ---- top bar ---- */
.topbar { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.title { font-weight: 700; font-size: 14px; white-space: nowrap; }
.title small { font-weight: 500; color: var(--muted); font-size: 10px; }
.spacer { flex: 1 1 auto; min-width: 0; }
.hud {
  display: flex; align-items: baseline; gap: 4px; font-size: 11px;
  background: var(--panel); padding: 3px 8px; border-radius: 8px;
  white-space: nowrap; overflow: hidden;
}
.hud b { font-size: 13px; color: var(--accent); }
.hud .opt { color: var(--muted); }

/* ---- board ---- */
#board {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
}
#shelf {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(3px, 1.2vw, 14px);
  width: 100%;
  max-height: 100%;
}

.tube {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s ease;
}
.tube:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.tube .holder {
  position: relative;
  width: calc(var(--ball-d) + 9px);
  height: var(--tube-h);
  border: 2px solid var(--tube-edge);
  border-top: 0;
  border-radius: 3px 3px 14px 14px;
  background: var(--tube);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  padding-bottom: 3px;
  overflow: hidden;
  transition: box-shadow 0.12s ease, border-color 0.12s ease;
}
.tube.selected .holder {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 207, 92, 0.35) inset;
}
.tube.done .holder { border-color: rgba(120, 220, 160, 0.75); }
.tube.invalid .holder { animation: shake 0.24s ease; border-color: #e8563f; }
.tube.hinted .holder { animation: pulse 0.5s ease 2; }

/* The picked-up ball lifts out of its tube and sits on the rim. */
.tube.selected .ball.top {
  transform: translateY(calc(-1 * var(--ball-d) * 0.62));
}

.ball {
  width: var(--ball-d);
  height: var(--ball-d);
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.35), inset 3px 3px 5px rgba(255, 255, 255, 0.35);
  transition: transform 0.12s ease;
}
.ball.empty { background: transparent; box-shadow: none; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 207, 92, 0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 207, 92, 0.55); }
}

/* ---- win card ---- */
#win {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 14, 20, 0.72);
  z-index: 5;
}
#win.hidden { display: none; }
.win-card {
  background: var(--panel2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 14px 18px;
  text-align: center;
  max-width: min(92%, 360px);
}
.win-label { font-weight: 700; font-size: 15px; }
.win-stars { font-size: 22px; letter-spacing: 3px; color: var(--accent); margin: 4px 0; min-height: 26px; }
.win-body { color: var(--muted); font-size: 12px; margin-bottom: 10px; }

/* ---- status bar ---- */
#statusbar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
#status {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#status[data-mode="sel"] { color: var(--accent); }
#status[data-mode="win"] { color: #78dca0; }
#status[data-mode="bad"] { color: #ff8570; }

.actions { display: flex; gap: 4px; flex-wrap: nowrap; }
.btn {
  flex: 1 1 auto;
  min-width: 34px;
  min-height: 34px;
  padding: 4px 6px;
  font: inherit;
  font-size: 11px;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { background: var(--panel2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: #c99b2f; border-color: #e2b64a; color: #16110a; font-weight: 700; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 11, 16, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  z-index: 10;
}
.modal {
  background: var(--panel2);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 14px 16px;
  max-width: min(94vw, 460px);
  max-height: 86vh;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
}
.modal h2 { margin: 0 0 8px; font-size: 15px; }
.modal h3 { margin: 10px 0 3px; font-size: 12px; color: var(--accent); }
.modal p { margin: 0 0 6px; color: #cfe0ec; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  background: rgba(20, 32, 43, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--ink);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 20;
}
#toast.show { opacity: 1; }

/* Short viewports (the 348x261 phone stage): keep everything on screen. */
@media (max-height: 340px) {
  :root { --tube-h: clamp(70px, 42vh, 150px); }
  .title small, .hud .opt { display: none; }
  #status { display: none; }
  .btn { font-size: 10px; }
  .hud { font-size: 10px; }
}
