/* Roller Boss — мобильный интерфейс. Всё на фиксированном слое, канвас на весь экран. */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #06070f;
  --ink: #eaf0ff;
  --dim: #8f9bc4;
  --hot: #ff3b6b;
  --ok: #39d98a;
  --warn: #ffd43b;
  --panel: rgba(12, 16, 34, 0.86);
  --line: rgba(122, 146, 255, 0.22);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

body { position: fixed; inset: 0; }

canvas#c {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
}
#hud[hidden] { display: none; }

.top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.badge {
  display: flex;
  flex-direction: column;
  line-height: 1;
  padding: 7px 11px 8px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  min-width: 82px;
}
.badge .k { font-size: 9px; letter-spacing: 0.16em; color: var(--dim); }
.badge .v { font-size: 24px; font-weight: 800; margin-top: 3px; }
.badge .w { font-size: 10px; letter-spacing: 0.08em; color: var(--hot); margin-top: 3px; font-weight: 700; }
.badge.score { margin-left: auto; align-items: flex-end; text-align: right; }
.badge.score .p { font-size: 10px; color: var(--dim); margin-top: 3px; }

.timer {
  flex: 1;
  height: 5px;
  margin-top: 12px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  max-width: 40vw;
}
.timer i {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--hot), #ff9d5c);
  border-radius: 3px;
  transform-origin: left;
}

.lives {
  position: absolute;
  left: calc(14px + var(--safe-l));
  top: calc(76px + var(--safe-t));
  display: flex;
  gap: 5px;
}
.lives i {
  width: 14px; height: 14px;
  border-radius: 4px;
  background: var(--hot);
  box-shadow: 0 0 10px rgba(255, 59, 107, 0.7);
  transform: rotate(45deg);
}
.lives i.off { background: rgba(255, 255, 255, 0.16); box-shadow: none; }

.board {
  position: absolute;
  left: calc(14px + var(--safe-l));
  bottom: calc(14px + var(--safe-b));
  font-size: 12px;
  color: var(--dim);
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 46vw;
}
.board .r { display: flex; align-items: center; gap: 6px; }
.board .r b { color: var(--ink); font-weight: 600; max-width: 22vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .r s { text-decoration: none; margin-left: auto; color: #cdd7ff; }
.board .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.board .r.me b { color: #fff; }

.banner {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -50%);
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease;
  width: 92vw;
}
.banner.on { opacity: 1; }
.banner h2 {
  margin: 0;
  font-size: clamp(28px, 9vw, 62px);
  letter-spacing: 0.04em;
  font-weight: 900;
  text-shadow: 0 0 26px currentColor;
}
.banner p { margin: 6px 0 0; color: var(--dim); font-size: clamp(12px, 3.4vw, 16px); }
.banner .lv { font-size: clamp(11px, 3vw, 14px); letter-spacing: 0.3em; color: var(--warn); }

.toasts {
  position: absolute;
  left: 50%;
  bottom: calc(78px + var(--safe-b));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  width: 92vw;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  animation: pop 0.25s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.toast.bad { color: #ffb3c6; border-color: rgba(255, 59, 107, 0.4); }
.toast.good { color: #a8f0c8; border-color: rgba(57, 217, 138, 0.4); }
@keyframes pop { from { transform: translateY(8px) scale(0.94); opacity: 0; } }

.hint {
  position: absolute;
  left: 50%;
  bottom: calc(34px + var(--safe-b));
  transform: translateX(-50%);
  font-size: 13px;
  color: var(--dim);
  background: rgba(8, 10, 22, 0.6);
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  animation: breathe 1.8s ease-in-out infinite;
}
.hint[hidden] { display: none; }
@keyframes breathe { 50% { opacity: 0.45; } }

/* ---------- кнопки ---------- */
#tools {
  position: fixed;
  right: calc(10px + var(--safe-r));
  bottom: calc(12px + var(--safe-b));
  display: flex;
  gap: 8px;
  z-index: 5;
}
#tools button {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  backdrop-filter: blur(6px);
  touch-action: manipulation;
}
#tools button:active { transform: scale(0.94); background: rgba(30, 38, 72, 0.9); }
#tools button.off { color: #6b7396; text-decoration: line-through; }

/* ---------- оверлей входа ---------- */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  padding: calc(18px + var(--safe-t)) calc(16px + var(--safe-r)) calc(18px + var(--safe-b)) calc(16px + var(--safe-l));
  background: radial-gradient(120% 90% at 50% 15%, rgba(24, 12, 44, 0.75), rgba(4, 5, 12, 0.94) 60%);
  overflow: auto;
  touch-action: pan-y;
}
#overlay[hidden] { display: none; }
.panel {
  width: min(460px, 100%);
  background: linear-gradient(180deg, rgba(18, 22, 46, 0.92), rgba(9, 11, 24, 0.92));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px 20px 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.panel h1 {
  margin: 0;
  font-size: clamp(30px, 11vw, 46px);
  line-height: 0.94;
  font-weight: 900;
  letter-spacing: 0.02em;
}
.panel h1 span { display: block; color: var(--hot); text-shadow: 0 0 24px rgba(255, 59, 107, 0.6); }
.sub { color: var(--dim); font-size: 13px; line-height: 1.45; margin: 12px 0 16px; }
.name { display: block; margin-bottom: 12px; }
.name span { display: block; font-size: 10px; letter-spacing: 0.16em; color: var(--dim); margin-bottom: 5px; }
.name input {
  width: 100%;
  padding: 13px 14px;
  font-size: 17px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
}
.name input:focus { border-color: var(--hot); background: rgba(255, 59, 107, 0.07); }
.play {
  width: 100%;
  padding: 16px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #14060d;
  background: linear-gradient(180deg, #ff6b8f, var(--hot));
  border: 0;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(255, 59, 107, 0.35);
  touch-action: manipulation;
}
.play:active { transform: scale(0.985); }
.play[disabled] { filter: grayscale(0.7) brightness(0.7); box-shadow: none; }
.row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--dim); margin-top: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #566; display: inline-block; }
.dot.ok { background: var(--ok); box-shadow: 0 0 10px rgba(57, 217, 138, 0.8); }
.dot.wait { background: var(--warn); animation: breathe 1.2s infinite; }
.dot.bad { background: var(--hot); }

.legend {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 11px;
  color: var(--dim);
}
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.top-board { position: static; margin-top: 14px; max-width: 100%; font-size: 12px; }
.top-board .r { border-bottom: 1px dashed rgba(122, 146, 255, 0.12); padding-bottom: 3px; }

/* ---------- переподключение ---------- */
#reconnect {
  position: fixed;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  z-index: 7;
}
#reconnect .rc {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--panel);
  border: 1px solid rgba(255, 59, 107, 0.45);
  padding: 12px 20px;
  border-radius: 14px;
  font-size: 12px;
  color: var(--dim);
  backdrop-filter: blur(8px);
}
#reconnect b { color: var(--ink); font-size: 14px; }
#reconnect[hidden] { display: none; }

/* ландшафт на телефоне — компактнее */
@media (orientation: landscape) and (max-height: 500px) {
  .banner { top: 50%; }
  .lives { top: calc(62px + var(--safe-t)); }
  .badge .v { font-size: 20px; }
  .panel h1 { font-size: clamp(24px, 7vh, 36px); }
  .sub { margin: 8px 0 12px; }
}
@media (max-height: 640px) {
  .legend { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
