/* ===== Roll & Reach – Galaxy & Glass theme ===== */
:root {
  --glass: rgba(15, 20, 40, 0.45);
  --glass-border: rgba(100, 180, 255, 0.35);
  --accent: #00d4ff;
  --accent-glow: rgba(0, 212, 255, 0.5);
  --neon-blue: #4da6ff;
  --neon-blue-glow: rgba(77, 166, 255, 0.45);
  --teal: #00e5cc;
  --teal-glow: rgba(0, 229, 204, 0.45);
  --gold: #ffb347;
  --gold-glow: rgba(255, 179, 71, 0.4);
  --danger: #ff6b7a;
  --danger-glow: rgba(255, 107, 122, 0.35);
  --text: #f0f4ff;
  --text-muted: #a0b0d0;
  --spacing: 16px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 999px;
  --transition-fast: 0.2s;
  --transition-normal: 0.25s;
}

/* ===== Base ===== */
html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-width: 100vw;
  min-width: 100dvw;
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Full-screen background (no gap) ===== */
#bg-layer {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  background: url('../img/bg.png') center center no-repeat;
  background-size: cover;
  z-index: 0;
}

/* ===== Canvas (sits above bg, transparent so bg shows through) ===== */
#canvas-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  z-index: 1;
}

/* ===== UI layer ===== */
.hud-spacer {
  min-height: 0;
}

#ui-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: grid;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;
  padding: var(--spacing);
  padding-left: max(var(--spacing), env(safe-area-inset-left));
  padding-right: max(var(--spacing), env(safe-area-inset-right));
  padding-top: max(var(--spacing), env(safe-area-inset-top));
  padding-bottom: max(var(--spacing), env(safe-area-inset-bottom));
  box-sizing: border-box;
}

/* ===== Top HUD ===== */
.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: auto;
  gap: var(--spacing);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 44px;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ===== Level: text only, no background ===== */
.level-badge {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  height: 48px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.level-label {
  font-family: 'Nunito', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  line-height: 1;
}

.level-label #level-num {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
  font-size: 22px;
  text-shadow: 0 0 10px var(--neon-blue-glow);
}

/* ===== Home button – neon blue border and glow ===== */
.btn-home {
  color: var(--neon-blue);
  border: 1px solid var(--neon-blue);
  background: rgba(8, 12, 24, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 0 14px var(--neon-blue-glow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.btn-home:hover {
  background: rgba(77, 166, 255, 0.2);
  border-color: var(--neon-blue);
  color: var(--text);
  box-shadow: 0 0 20px var(--neon-blue-glow);
}

/* ===== Control buttons – smaller, less glow ===== */
.controls-group {
  display: flex;
  gap: 8px;
  align-items: center;
  height: 44px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: rgba(8, 12, 24, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  border: 1px solid var(--neon-blue);
  transition: var(--transition-normal);
  color: var(--text);
  font-size: 1rem;
  box-shadow: 0 0 12px var(--neon-blue-glow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.btn-icon:hover {
  background: rgba(255, 107, 122, 0.25);
  border-color: var(--danger);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.btn-solve {
  color: var(--teal);
  border-color: rgba(0, 229, 204, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.btn-solve:hover {
  background: rgba(0, 229, 204, 0.2);
  border-color: var(--teal);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.btn-disabled {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.6);
}

/* ===== Dice HUD – number indicator, large numbers, reduced glow ===== */
.dice-hud {
  display: grid;
  grid-template-columns: 50px 50px 50px;
  grid-template-rows: 50px 50px 50px;
  gap: 6px;
  background: rgba(8, 12, 24, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--neon-blue);
  box-shadow: 0 0 16px var(--neon-blue-glow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.dh-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-sm);
  font-size: 20px;
  color: var(--text-muted);
  position: relative;
}

.dh-cell.center {
  background: rgba(0, 229, 204, 0.25);
  border: 1px solid var(--teal);
  color: var(--text);
  font-size: 28px;
  box-shadow: 0 0 14px var(--teal-glow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.dh-cell.prediction {
  background: rgba(20, 35, 60, 0.4);
  border: 1px solid var(--neon-blue);
  color: var(--text);
}

.dh-cell .dh-label {
  font-size: 9px;
}

.dh-label {
  position: absolute;
  font-size: 9px;
  opacity: 0.85;
  font-family: sans-serif;
  color: var(--text-muted);
}

#dh-up .dh-label { top: 2px; left: 50%; transform: translateX(-50%); }
#dh-down .dh-label { bottom: 2px; left: 50%; transform: translateX(-50%); top: auto; }
#dh-left .dh-label { left: 4px; top: 50%; transform: translateY(-50%); }
#dh-right .dh-label { right: 4px; top: 50%; transform: translateY(-50%); left: auto; }

/* ===== Bottom HUD ===== */
.hud-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  pointer-events: auto;
  padding-bottom: 24px;
}

/* ===== Mobile controls – glass ===== */
#mobile-controls {
  display: none;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(2, 68px);
  gap: 10px;
  margin-top: 14px;
}

.d-btn {
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  min-width: 44px;
  min-height: 44px;
}

.d-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.d-btn:active {
  background: rgba(0, 229, 204, 0.3);
  color: var(--text);
  transform: scale(0.95);
  border-color: var(--teal);
}

.d-btn-up { grid-column: 2; grid-row: 1; }
.d-btn-down { grid-column: 2; grid-row: 2; }
.d-btn-left { grid-column: 1; grid-row: 2; }
.d-btn-right { grid-column: 3; grid-row: 2; }

/* ===== RESPONSIVE BREAKPOINTS ===== */
/* Desktop (≥1025px): default styles above */

/* Tablet Landscape (769px - 1024px) */
@media (max-width: 1024px) {
  :root {
    --spacing: 14px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
  }
  #ui-layer { padding: var(--spacing); }
  .level-label, .level-label #level-num { font-size: 20px; }
  .hud-left { height: 42px; }
  .controls-group { height: 42px; gap: 6px; }
  .btn-icon { width: 42px; height: 42px; font-size: 0.95rem; }
  .dice-hud {
    grid-template-columns: 46px 46px 46px;
    grid-template-rows: 46px 46px 46px;
    gap: 5px;
    padding: 10px;
  }
  .dh-cell { font-size: 18px; }
  .dh-cell.center { font-size: 24px; }
  .dh-cell .dh-label { font-size: 8px; }
  .modal-card { padding: 28px 24px; max-width: 400px; }
  .modal-title { font-size: 26px; }
  #start-popup .modal-title { font-size: 42px; }
  .modal-msg { font-size: 15px; margin-bottom: 20px; }
  .btn-next { padding: 16px 40px; font-size: 17px; }
  .solving-indicator { font-size: 16px; padding: 24px 36px; }
}

/* Tablet Portrait (641px - 768px) */
@media (max-width: 768px) {
  #mobile-controls { display: grid; }
  .dice-hud {
    transform: scale(0.9);
    transform-origin: top right;
    grid-template-columns: 42px 42px 42px;
    grid-template-rows: 42px 42px 42px;
    gap: 4px;
    padding: 8px;
  }
  .dh-cell { font-size: 16px; }
  .dh-cell.center { font-size: 22px; }
  .dh-cell .dh-label { font-size: 7px; }
  .hud-top { gap: 8px; }
  .level-label, .level-label #level-num { font-size: 18px; }
  .hud-left { height: 40px; gap: 8px; }
  .controls-group { height: 40px; gap: 6px; }
  .btn-icon { width: 40px; height: 40px; font-size: 0.9rem; }
  #mobile-controls {
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(2, 60px);
    gap: 8px;
    margin-top: 12px;
  }
  .d-btn { font-size: 22px; min-width: 44px; min-height: 44px; }
  .hud-bottom { gap: 12px; padding-bottom: 16px; }
  .modal-card { padding: 24px 20px; width: 92%; max-width: 380px; }
  .modal-title { font-size: 24px; }
  #start-popup .modal-title { font-size: 38px; }
  .modal-msg { font-size: 14px; margin-bottom: 18px; }
  .btn-next { padding: 14px 36px; font-size: 16px; max-width: 240px; }
  .solving-indicator { font-size: 15px; padding: 20px 32px; }
}

/* Mobile (481px - 640px) */
@media (max-width: 640px) {
  :root { --spacing: 12px; --radius-sm: 10px; --radius-md: 12px; --radius-lg: 18px; }
  #ui-layer { padding: var(--spacing); }
  .hud-top { gap: 6px; flex-wrap: wrap; }
  .level-label, .level-label #level-num { font-size: 16px; }
  .level-badge { height: 40px; }
  .hud-left { height: 38px; gap: 6px; }
  .controls-group { height: 38px; gap: 4px; }
  .btn-icon { width: 38px; height: 38px; font-size: 0.85rem; }
  .dice-hud {
    transform: scale(0.82);
    transform-origin: top right;
    grid-template-columns: 36px 36px 36px;
    grid-template-rows: 36px 36px 36px;
    gap: 3px;
    padding: 6px;
  }
  .dh-cell { font-size: 14px; }
  .dh-cell.center { font-size: 18px; }
  .dh-cell .dh-label { font-size: 6px; }
  #mobile-controls {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 6px;
    margin-top: 10px;
  }
  .d-btn {
    font-size: 20px;
    min-width: 44px;
    min-height: 44px;
    border-radius: var(--radius-sm);
  }
  .hud-bottom { gap: 10px; padding-bottom: 12px; }
  .modal-card { padding: 22px 18px; width: 92%; max-width: 340px; }
  .modal-title { font-size: 22px; letter-spacing: 1px; }
  #start-popup .modal-title { font-size: 34px; }
  .modal-msg { font-size: 13px; margin-bottom: 16px; line-height: 1.5; }
  .modal-actions { gap: 10px; }
  .btn-next { padding: 14px 32px; font-size: 15px; max-width: 220px; }
  .solving-indicator { font-size: 14px; padding: 18px 28px; letter-spacing: 1px; }
}

/* Small Mobile (≤480px) */
@media (max-width: 480px) {
  :root { --spacing: 10px; --radius-sm: 8px; --radius-md: 10px; --radius-lg: 16px; }
  #ui-layer { padding: var(--spacing); }
  .hud-top { gap: 6px; }
  .level-label, .level-label #level-num { font-size: 14px; }
  .level-badge { height: 36px; }
  .hud-left { height: 36px; gap: 4px; }
  .controls-group { height: 36px; gap: 4px; }
  .btn-icon {
    width: 44px;
    height: 44px;
    font-size: 0.9rem;
    min-width: 44px;
    min-height: 44px;
  }
  .dice-hud {
    transform: scale(0.72);
    transform-origin: top right;
    grid-template-columns: 32px 32px 32px;
    grid-template-rows: 32px 32px 32px;
    gap: 2px;
    padding: 5px;
  }
  .dh-cell { font-size: 12px; }
  .dh-cell.center { font-size: 16px; }
  .dh-cell .dh-label { font-size: 5px; }
  #mobile-controls {
    grid-template-columns: repeat(3, 52px);
    grid-template-rows: repeat(2, 52px);
    gap: 6px;
    margin-top: 8px;
  }
  .d-btn {
    width: 52px;
    height: 52px;
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
  }
  .hud-bottom { gap: 8px; padding-bottom: 10px; }
  .modal-card { padding: 20px 16px; width: 94%; max-width: 300px; }
  .modal-title { font-size: 20px; letter-spacing: 1px; margin-bottom: 10px; }
  #start-popup .modal-title { font-size: 30px; }
  .modal-msg { font-size: 12px; margin-bottom: 14px; line-height: 1.45; }
  .modal-actions { gap: 8px; }
  .btn-next { padding: 14px 28px; font-size: 14px; max-width: 200px; }
  .solving-indicator { font-size: 13px; padding: 16px 24px; letter-spacing: 1px; }
}

/* Landscape Mobile (orientation: landscape, short viewport) */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --spacing: 8px; }
  #ui-layer {
    padding: var(--spacing);
    grid-template-rows: auto 1fr auto;
  }
  .hud-top { gap: 6px; align-items: center; }
  .level-label, .level-label #level-num { font-size: 14px; }
  .level-badge { height: 32px; }
  .hud-left { height: 32px; gap: 4px; }
  .controls-group { height: 32px; gap: 4px; }
  .btn-icon {
    width: 36px;
    height: 36px;
    min-width: 44px;
    min-height: 44px;
    font-size: 0.8rem;
  }
  .hud-right { gap: 6px; }
  .dice-hud {
    transform: scale(0.65);
    transform-origin: top right;
    grid-template-columns: 28px 28px 28px;
    grid-template-rows: 28px 28px 28px;
    gap: 2px;
    padding: 4px;
  }
  .dh-cell { font-size: 10px; }
  .dh-cell.center { font-size: 14px; }
  .dh-cell .dh-label { font-size: 5px; }
  #mobile-controls {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(2, 48px);
    gap: 4px;
    margin-top: 4px;
  }
  .d-btn {
    width: 48px;
    height: 48px;
    min-width: 44px;
    min-height: 44px;
    font-size: 16px;
  }
  .hud-bottom { gap: 4px; padding-bottom: 6px; justify-content: flex-end; }
  .modal-card {
    padding: 16px 20px;
    width: 85%;
    max-width: 360px;
    max-height: 90vh;
    overflow-y: auto;
  }
  .modal-title { font-size: 18px; margin-bottom: 6px; }
  #start-popup .modal-title { font-size: 26px; }
  .modal-msg { font-size: 12px; margin-bottom: 12px; line-height: 1.4; }
  .modal-actions { gap: 8px; }
  .btn-next { padding: 10px 24px; font-size: 14px; max-width: 180px; }
  .solving-indicator { font-size: 12px; padding: 12px 20px; }
}

/* Landscape + very narrow (e.g. iPhone SE landscape) */
@media (orientation: landscape) and (max-height: 400px) {
  .hud-bottom { padding-bottom: 4px; }
  #mobile-controls { margin-top: 2px; }
  .modal-card { padding: 12px 16px; max-height: 85vh; }
  .modal-title { font-size: 16px; }
  #start-popup .modal-title { font-size: 22px; }
  .modal-msg { font-size: 11px; margin-bottom: 8px; }
  .btn-next { padding: 8px 20px; font-size: 13px; }
}

/* ===== Modals – same game background, glass card, no glow ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: url('../img/bg.png') center center no-repeat;
  background-size: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition-normal);
  z-index: 100;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: rgba(8, 12, 24, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  padding: 32px 28px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-lg);
  transform: scale(0.9);
  transition: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  width: 90%;
  max-width: 420px;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-title {
  font-family: 'Nunito', sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 12px;
  letter-spacing: 0.5px;
  text-shadow: none;
  line-height: 1.2;
}

.modal-msg {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 16px;
  line-height: 1.55;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.btn-next {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, rgba(0, 212, 255, 0.35), rgba(0, 229, 204, 0.3));
  color: var(--text);
  font-family: 'Luckiest Guy', cursive;
  font-weight: 400;
  border: 1px solid var(--glass-border);
  padding: 18px 44px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  letter-spacing: 2px;
  transition: var(--transition-fast);
  width: 100%;
  max-width: 260px;
  border-radius: var(--radius-full);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

.btn-next:hover {
  background: linear-gradient(145deg, rgba(0, 212, 255, 0.45), rgba(0, 229, 204, 0.4));
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

/* ===== Start popup ===== */
#start-popup { z-index: 101; }

#modal-overlay { z-index: 102; }

#start-popup .modal-card {
  border: 1px solid var(--neon-blue);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

#start-popup .modal-title {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  color: var(--text);
  font-size: 48px;
  letter-spacing: 1px;
  text-shadow: none;
  line-height: 1.1;
  margin-bottom: 16px;
}

#start-popup .btn-next:hover {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* ===== Solving indicator – glass ===== */
.solving-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Luckiest Guy', cursive;
  font-size: 18px;
  color: var(--accent);
  background: var(--glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 28px 44px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  display: none;
  z-index: 50;
  letter-spacing: 2px;
  box-shadow: 0 0 48px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.solving-indicator.is-visible {
  display: block;
}
