:root {
  --page-w: 90%;
  --page-max: 900px;
  --topbar-h: 3.4rem;
}

/* Base */
html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;              /* prevents page scroll / viewport resize jitter */
  overscroll-behavior: none;
  background: #1d1e22;
  color: #eee;
  font-family: sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Top bar */
#topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.8rem;
  z-index: 50;
  pointer-events: none;
}

#menu-toggle {
  pointer-events: auto;
  width: var(--page-w);
  max-width: var(--page-max);
  height: 2.6rem;
  border-radius: 999px;
  border: 1px solid #374151;
  background: #111827;
  color: #f9fafb;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55);
}

#menu-toggle:active {
  transform: scale(0.99);
}

/* Title */
h1 {
  margin: calc(var(--topbar-h) + 0.2rem) 0 0;
  font-size: 1.6rem;
  font-weight: 700;
}

/* Dice box */
/* Use 100vh (not dvh) to avoid iOS canvas stretch/jitter */
#dice-box {
	display: block;
  width: var(--page-w);
  max-width: var(--page-max);
  height: calc(100vh - (var(--topbar-h) + 5.2rem));
  background: #111;
  margin: 0.8rem auto 1rem;
  border: 2px solid #333;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
}

/* IMPORTANT: do NOT force canvas width/height, it can cause skew on mobile */
#dice-box canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Overlay (never blocks clicks when closed) */
#menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 140ms ease, visibility 140ms ease;
}

#menu-overlay.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

/* Menu panel */
#menu-panel {
  width: var(--page-w);
  max-width: var(--page-max);
  margin: calc(var(--topbar-h) + 0.5rem) auto 1rem;
  background: rgba(2, 6, 23, 0.9);
  border: 1px solid #374151;
  border-radius: 12px;
  padding: 0.9rem;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.7);

  max-height: calc(100vh - (var(--topbar-h) + 2rem));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Controls grid */
#controls {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 700px) {
  #controls {
    grid-template-columns: 1fr 1fr;
  }
  #scale-control {
    grid-column: span 2;
  }
}

/* Cards */
.die-card {
  background: #111827;
  border-radius: 10px;
  border: 1px solid #374151;
  padding: 0.65rem 0.75rem;
  display: block;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
  transition: box-shadow 0.1s, border-color 0.1s, background 0.1s;
}

.die-card:hover {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.7);
  border-color: #fbbf24;
  background: #020617;
}

.die-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* +/- buttons */
.qty-btn {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 999px;
  border: none;
  background: #1f2937;
  color: #f9fafb;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.qty-btn:active {
  transform: scale(0.95);
}

/* Roll button */
.roll-btn {
  flex: 1;
  height: 2.6rem;
  border-radius: 999px;
  border: none;
  background: #2563eb;
  color: #f9fafb;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.roll-btn:active {
  transform: scale(0.98);
}

.die-count {
  font-size: 1.1rem;
  font-weight: 700;
}

.die-label {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Scale */
#scale-control {
  background: #020617;
  border-radius: 10px;
  border: 1px solid #374151;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
}

#scale-label-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

input[type="range"] {
  width: 100%;
  background: #111;
}

