:root {
  --bg: #0b0d17;
  --panel: #151a2d;
  --line: #262d4a;
  --text: #e6e9f5;
  --muted: #8a93b8;
  --accent: #a855f7;
  font-family: ui-monospace, "SF Mono", "Cascadia Code", "DejaVu Sans Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: radial-gradient(circle at 50% 0%, #1b1f3b 0%, var(--bg) 60%);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.game {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.side { display: flex; flex-direction: column; gap: 16px; width: 150px; }

.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

canvas { display: block; }
.box canvas { margin: 0 auto; }
#hold { width: 120px; height: 60px; }
#next { width: 120px; height: 210px; }

.stats { display: grid; gap: 12px; }
.stats h2 { margin-bottom: 2px; }
.stats output { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  margin: 0 0 12px;
  font-size: 12px;
}
.keys dt { color: var(--text); font-weight: 700; }
.keys dd { margin: 0; color: var(--muted); }

.toggles { display: grid; gap: 6px; }
.toggles button {
  font: inherit;
  font-size: 12px;
  text-align: left;
  color: var(--text);
  background: #1e2440;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}
.toggles button b { float: right; color: var(--muted); }
.toggles button.off { opacity: 0.45; text-decoration: line-through; }

.board-wrap {
  position: relative;
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(168, 85, 247, 0.15);
  line-height: 0;
}

#board {
  width: min(300px, 45vh);
  height: min(600px, 90vh);
  aspect-ratio: 1 / 2;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  text-align: center;
  line-height: 1.4;
  background: rgba(8, 10, 20, 0.82);
  backdrop-filter: blur(2px);
  cursor: pointer;
}
.overlay.hidden { display: none; }
.overlay h1 {
  margin: 0;
  font-size: 36px;
  letter-spacing: 0.15em;
  background: linear-gradient(90deg, #22d3ee, #a855f7, #f97316);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay p { margin: 0; white-space: pre-line; }

.start-level { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.start-level input {
  width: 52px;
  font: inherit;
  color: var(--text);
  background: #1e2440;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
}

.popup {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #fde047;
  text-shadow: 0 0 12px rgba(253, 224, 71, 0.7);
  opacity: 0;
  pointer-events: none;
  line-height: 1.2;
}
.popup.show { animation: pop 1.2s ease-out; }
@keyframes pop {
  0% { opacity: 0; transform: scale(0.6); }
  15% { opacity: 1; transform: scale(1.15); }
  30% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-30px); }
}

.touch { display: none; }

/* telas de toque ou estreitas: painéis compactos e botões na tela */
@media (pointer: coarse), (max-width: 700px) {
  body { justify-content: flex-start; padding: 10px 16px; }
  .game { gap: 8px; }
  .side { width: 68px; gap: 8px; }
  .box { padding: 6px; }
  #hold, #next { width: 54px; height: auto; }
  .keys dl, .keys h2 { display: none; }
  h2 { font-size: 8px; letter-spacing: 0.04em; margin-bottom: 4px; }
  .stats output { font-size: 14px; }
  .toggles button { font-size: 10px; padding: 4px; }
  .toggles button b { display: none; }
  #board {
    width: min(calc(100vw - 32px - 156px), 34vh);
    height: min(calc((100vw - 32px - 156px) * 2), 68vh);
  }
  .touch {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: min(100%, 420px);
    margin-top: 12px;
  }
  .touch button {
    font-size: 22px;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 0;
  }
  .touch button:active { background: #2a3260; }
}
