#game { padding: 0; position: fixed; inset: 0; display: block; overflow: hidden; }
#game.hidden { display: none; }

#cv {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
#cv.shake { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-7px); }
  50% { transform: translateX(7px); }
  75% { transform: translateX(-4px); }
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  pointer-events: none;
}
.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 18, 24, 0.86);
  border: 1px solid var(--line);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  white-space: pre-line;
  text-align: center;
}
.timer {
  min-width: 64px;
  padding: 4px 12px;
  border-radius: 14px;
  background: rgba(15, 18, 24, 0.9);
  border: 2px solid var(--accent);
  font-size: 1.6rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.timer.low { border-color: var(--danger); color: var(--danger); }

.banner {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 10px;
  background: rgba(58, 42, 18, 0.95);
  color: #ffd591;
  font-size: 0.85rem;
  white-space: nowrap;
}

.bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: rgba(18, 22, 29, 0.93);
  border-top: 1px solid var(--line);
}
.row { display: flex; gap: 6px; align-items: center; }
.barInfo { margin: 0; font-size: 0.85rem; color: var(--muted); text-align: center; }

.tools { justify-content: space-between; }
.tool {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 4px 2px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #262e3b;
  color: var(--text);
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
.tool span { font-size: 0.62rem; color: var(--muted); }
.tool.on { border-color: var(--accent); background: #3a3120; }
.tool.on span { color: var(--accent); }
.tool.wide { flex: none; padding: 4px 14px; flex-direction: row; font-size: 0.9rem; }

.paletteRow { gap: 8px; }
.colorBtn {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid #fff;
  overflow: hidden;
  cursor: pointer;
  position: relative;
}
.colorBtn input { position: absolute; inset: -8px; width: 70px; height: 70px; border: 0; padding: 0; cursor: pointer; }
.palette { display: flex; gap: 6px; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.palette::-webkit-scrollbar { display: none; }
.sw {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  cursor: pointer;
  padding: 0;
}
.sw.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

.adjust { flex-wrap: wrap; gap: 8px 12px; padding: 4px 2px; }
.adjust label { flex: 1 1 130px; display: flex; flex-direction: column; font-size: 0.75rem; color: var(--muted); }
.adjust input[type="range"] { width: 100%; height: 30px; accent-color: var(--accent); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 12, 16, 0.82);
  z-index: 20;
}
.overlay.sheet {
  inset: auto 0 0 0;
  background: none;
  align-items: flex-end;
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  pointer-events: none;
}
.overlay.sheet .card { pointer-events: auto; padding: 14px; gap: 8px; background: rgba(28, 34, 44, 0.96); }
.overlay h2 { font-size: 1.25rem; }
.overlay .big { font-size: 3rem; line-height: 1; }
.scoreLine { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border-radius: 10px; background: #11151b; }
.scoreLine b { color: var(--accent); }
.scoreLine .gain { color: var(--ok); font-size: 0.85rem; }
.scoreLine.win { outline: 2px solid var(--accent); }

.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }

@media (min-width: 760px) {
  .bar { left: 50%; right: auto; bottom: 12px; transform: translateX(-50%); width: 560px; border: 1px solid var(--line); border-radius: 16px; }
  .overlay.sheet { justify-content: center; }
}
