/* PHYSICS LAB - shell chrome. The play field itself is all canvas. */
:root {
  --bg: #070b12;
  --panel: #0f1725;
  --panel-2: #131e2e;
  --line: rgba(63, 224, 207, 0.16);
  --text: #dceaf5;
  --muted: rgba(220, 234, 245, 0.55);
  --accent: #3fe0cf;
  --accent-ink: #04211f;
  --danger: #ff5470;
  --success: #6ee7a8;
  --radius: 14px;
  --hud-h: 52px;
  --ctl-h: 92px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100vh;
  max-width: 680px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------------- header ---------------- */
.hud {
  flex: 0 0 auto;
  height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
}

.hud__brand {
  font: 800 15px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.14em;
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.hud__brand span {
  color: var(--accent);
  text-shadow: 0 0 14px rgba(63, 224, 207, 0.45);
}

.hud__chip {
  margin-left: auto;
  font: 600 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: rgba(63, 224, 207, 0.1);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
}

.iconbtn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, transform 0.1s;
}
.iconbtn:hover { color: var(--accent); border-color: var(--line); }
.iconbtn:active { transform: scale(0.94); }

/* ---------------- stage ---------------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none; /* pointer events only - never scroll while dragging */
}

/* ---------------- controls ---------------- */
.controls {
  flex: 0 0 auto;
  min-height: var(--ctl-h);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line);
  background: linear-gradient(0deg, var(--panel-2), var(--panel));
}

.controls__status {
  margin: 0;
  text-align: center;
  font: 500 12px/1.3 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-height: 16px;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 15px 20px;
  font: 800 15px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.16em;
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.995); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn--primary {
  color: var(--accent-ink);
  background: linear-gradient(180deg, #62f0e0, var(--accent));
  box-shadow: 0 6px 22px rgba(63, 224, 207, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn--danger {
  color: #2a0710;
  background: linear-gradient(180deg, #ff7f96, var(--danger));
  box-shadow: 0 6px 22px rgba(255, 84, 112, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.btn--success {
  color: #042715;
  background: linear-gradient(180deg, #9af3c4, var(--success));
  box-shadow: 0 6px 22px rgba(110, 231, 168, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}
.btn--ghost {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
}

/* ---------------- result overlay ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 14, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s ease;
  z-index: 5;
}
.overlay.is-open { opacity: 1; }
/* The author `display: grid` above beats the UA rule for [hidden], so it has to
   be turned off explicitly - otherwise the invisible panel eats every tap. */
.overlay[hidden] { display: none; }

.overlay__card {
  width: min(320px, 100%);
}

.result {
  text-align: center;
  background: linear-gradient(180deg, rgba(23, 34, 50, 0.96), rgba(14, 22, 34, 0.96));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: pop 0.26s cubic-bezier(0.2, 1.3, 0.5, 1) both;
}
@keyframes pop {
  from { transform: translateY(14px) scale(0.94); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.result__badge {
  display: inline-block;
  font: 800 11px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.22em;
  padding: 7px 14px;
  border-radius: 999px;
  margin-bottom: 14px;
}
.result--ok .result__badge {
  color: var(--accent-ink);
  background: var(--accent);
  box-shadow: 0 0 26px rgba(63, 224, 207, 0.4);
}
.result--fail .result__badge {
  color: #2a0710;
  background: var(--danger);
  box-shadow: 0 0 26px rgba(255, 84, 112, 0.35);
}

.result h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.result__meta,
.result__note {
  margin: 0 0 4px;
  font: 500 12px/1.5 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
}
.result__note { color: rgba(63, 224, 207, 0.75); margin-top: 8px; }

.result__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}
.result__actions .btn { padding: 13px 10px; font-size: 13px; letter-spacing: 0.12em; }

/* ---------------- toast ---------------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(10, 18, 29, 0.92);
  border: 1px solid var(--line);
  color: var(--text);
  font: 600 12px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.04em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 6;
  max-width: min(88%, 380px);
  text-align: center;
  line-height: 1.45;
}
.toast.is-open { opacity: 1; transform: translate(-50%, 0); }

/* short screens: give the play field every pixel we can */
@media (max-height: 640px) {
  :root { --hud-h: 44px; --ctl-h: 78px; }
  .btn { padding: 12px 18px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------- level select ---------------- */
.hud__chip {
  appearance: none;
  cursor: pointer;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  transition: border-color 0.15s, background 0.15s;
}
.hud__chip:hover { background: rgba(63, 224, 207, 0.18); }
.hud__chip.has-best::after {
  content: "";
  display: inline-block;
  width: 5px;
  height: 5px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--success);
  vertical-align: middle;
}

.iconbtn.is-off { color: rgba(220, 234, 245, 0.28); }

.result--levels { padding: 20px 16px 16px; }
.result__badge--plain {
  color: var(--accent);
  background: rgba(63, 224, 207, 0.12);
  border: 1px solid var(--line);
}

.lvlgrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 4px;
  max-height: min(52vh, 420px);
  overflow-y: auto;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
}

.lvl {
  appearance: none;
  display: grid;
  gap: 2px;
  padding: 10px 10px 9px;
  text-align: left;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.lvl:hover:not(:disabled) { border-color: var(--line); background: rgba(63, 224, 207, 0.08); }
.lvl:active:not(:disabled) { transform: scale(0.985); }
.lvl--current { border-color: var(--accent); background: rgba(63, 224, 207, 0.12); }
.lvl--locked { opacity: 0.38; cursor: not-allowed; }
.lvl__no {
  font: 800 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.14em;
  color: var(--accent);
}
.lvl--locked .lvl__no { color: var(--muted); }
.lvl__name { font-size: 12.5px; font-weight: 600; }
.lvl__meta {
  font: 500 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
}
.result__actions--single { grid-template-columns: 1fr; }

/* ---------------- player levels ---------------- */
.hud__chip--custom {
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: 0.04em;
}
.result__title { word-break: break-word; }
.result__by {
  margin: 0 0 10px;
  font: 500 12px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  color: var(--muted);
  word-break: break-word;
}
.result__tags { margin: 0 0 10px; }
.tag {
  display: inline-block;
  font: 800 10px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.16em;
  padding: 6px 10px;
  border-radius: 999px;
}
.tag--ok { color: #042715; background: var(--success); }
.tag--warn { color: #2b1c02; background: #ffc15a; }
.result__hint {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}
.result__note--small { font-size: 11px; color: var(--muted); }
.result__links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 16px;
  margin-top: 14px;
}
.linkbtn {
  appearance: none;
  background: none;
  border: 0;
  padding: 6px 2px;
  color: var(--accent);
  font: 600 12px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-color: rgba(63, 224, 207, 0.4);
}
.linkbtn:hover { text-decoration-color: var(--accent); }

/* ---------------- online: rank, leaderboard, report ---------------- */
.online { margin: 12px 0 2px; padding: 10px 12px; border-radius: 14px; background: rgba(63, 224, 207, 0.06); border: 1px solid rgba(63, 224, 207, 0.18); }
.online .result__meta { margin: 0; }
.online__rank { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 2px 8px; }
.online__pos { font: 800 26px/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--accent); }
.online__of { font: 500 12px/1.3 ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); }
.online__wr { margin: 6px 0 0; font-size: 12px; color: var(--text); word-break: break-word; }
.online__links { margin: 6px 0 0; font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 10px; word-break: break-word; }
.online__err { margin: 0; font-size: 12px; color: var(--muted); }

.lb { list-style: none; margin: 10px 0 6px; padding: 0; display: grid; gap: 4px; max-height: min(46vh, 420px); overflow-y: auto; text-align: left; }
.lb__row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); }
.lb__row--me { background: rgba(63, 224, 207, 0.12); outline: 1px solid rgba(63, 224, 207, 0.35); }
.lb__row--pinned { margin-top: 6px; }
.lb__rank { font: 800 13px/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--muted); text-align: center; }
.lb__name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb__time { font: 700 13px/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--accent); }
.lb--mini { margin-top: 8px; }
.lb--mini .lb__row { padding: 6px 10px; }

.gstats { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 10px; font: 600 12px/1 ui-monospace, "SF Mono", Menlo, monospace; color: rgba(220, 234, 245, 0.75); }
.gstats__like { appearance: none; border: 1px solid rgba(255, 255, 255, 0.14); background: rgba(255, 255, 255, 0.04); color: var(--text); border-radius: 999px; padding: 7px 12px; font: inherit; cursor: pointer; }
.gstats__like.is-on { color: #ff7a93; border-color: rgba(255, 122, 147, 0.45); background: rgba(255, 122, 147, 0.1); }
.linkbtn--muted { color: var(--muted); text-decoration-color: rgba(220, 234, 245, 0.25); }

.field__input {
  width: 100%;
  margin-top: 10px;
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 11px;
  outline: none;
  resize: none;
  -webkit-user-select: text;
  user-select: text;
}
.field__input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63, 224, 207, 0.15); }
.report { display: grid; gap: 6px; text-align: left; margin-top: 4px; }
.report__opt { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.03); font-size: 13px; cursor: pointer; }
.report__opt input { accent-color: var(--danger); width: 16px; height: 16px; }

/* full-width secondary action (level select -> arcade) */
.btn--block { display: flex; width: 100%; justify-content: center; margin-top: 10px; }
