:root {
  --digivice-color: #3f51b5;
  --screen-bg: #8ba88b;
  --glass-bg: rgba(255, 255, 255, 0.1);
}

body {
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: #1a1a1a;
  font-family: 'Inter', sans-serif;
}

.digivice {
  position: relative;
  width: 480px;
  height: 320px;
  background: #3f51b5;
  overflow: hidden;
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.9);
  border: 4px solid #303f9f;
}

.screen-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 40px;
  overflow: hidden;
  /* Prevent game screen from leaking into shell */
}

#gameCanvas {
  position: absolute;
  top: 16px;
  left: 36px;
  width: 288px;
  height: 288px;
  background: var(--screen-bg);
  /* Absolute pixel perfection */
  image-rendering: optimizeSpeed;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: optimize-contrast;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  -ms-interpolation-mode: nearest-neighbor;
  z-index: 1;
}

#overlayCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  /* Shell stays on TOP */
}

/* Frameless Adjustments */
body.frameless .digivice {
  border: none;
  box-shadow: none;
  background: transparent;
  width: auto;
  height: auto;
  position: relative;
  display: flex;
  /* Move buttons to the side */
  align-items: center;
  gap: 40px;
}

body.frameless .screen-container {
  position: relative;
  width: auto;
  height: auto;
}

body.frameless #gameCanvas {
  position: relative;
  top: 0;
  left: 0;
  width: 576px;
  /* 6x scale of 96x96 */
  height: 576px;
  display: block;
}

body.frameless #overlayCanvas {
  display: none;
}

body.frameless .physical-buttons {
  position: static;
  transform: none;
  display: flex;
  flex-direction: column;
  gap: 30px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 20px;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

body.frameless .round-button {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: 'Inter', sans-serif;
  font-weight: bold;
  font-size: 18px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  transition: all 0.2s;
}

body.frameless .round-button:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.05);
}

body.frameless .round-button:active {
  transform: scale(0.95);
}

.utility-bar {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.utility-bar button {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  width: 35px;
  height: 35px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
  transition: all 0.2s;
}

.utility-bar button:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

#hud-container {
  position: fixed;
  top: 20px;
  left: 20px;
  display: flex;
  align-items: stretch;
  /* Match heights */
  z-index: 100;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.5);
  border-radius: 12px;
  overflow: hidden;
  /* Round outer corners */
  border: 1px solid #333;
  backdrop-filter: blur(8px);
}

#game-clock {
  background: #121212;
  padding: 10px 20px;
  color: #e0e0e0;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 1px solid #333;
}

#btn-pause {
  background: #121212;
  border: none;
  padding: 0 15px;
  color: #e0e0e0;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#btn-pause:hover {
  background: #222;
  color: white;
}

#btn-pause:active {
  background: #333;
}

.physical-buttons {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 10;
}

.round-button {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0);
  color: transparent;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.round-button:active {
  background: rgba(255, 255, 255, 0.1);
}

.round-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.controls {
  position: absolute;
  bottom: 20px;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 20px;
  z-index: 10;
}

button:hover {
  background: rgba(255, 255, 255, 0.4);
}

/* Material Dark Settings Modal */
.modern-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 380px;
  background: #121212;
  border: 1px solid #333;
  border-radius: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
  padding: 32px;
  z-index: 1000;
  color: #e0e0e0;
  font-family: 'Inter', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 28px;
  font-weight: 700;
  color: white;
}

.close-x {
  background: none;
  border: none;
  color: #888;
  font-size: 36px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.close-x:hover {
  color: white;
  background: none;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.setting-item label {
  font-size: 18px;
  font-weight: 600;
  color: #bbb;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

#volume-value {
  font-family: 'Inter', sans-serif;
  font-size: 18px;
  font-weight: bold;
  color: white;
  min-width: 50px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

/* Material Toggle Switch - Large */
.switch {
  position: relative;
  display: inline-block;
  width: 80px;
  height: 44px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #333;
  transition: .4s;
  border-radius: 44px;
  border: 2px solid #444;
}

.slider:before {
  position: absolute;
  content: "";
  height: 32px;
  width: 32px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

input:checked+.slider {
  background-color: #4f69ff;
  border-color: #4f69ff;
}

input:checked+.slider:before {
  transform: translateX(36px);
}

.modal-footer {
  margin-top: 10px;
}

.primary-btn {
  width: 100%;
  background: #4f69ff;
  /* Vibrant blue */
  color: white;
  border: none;
  padding: 20px;
  border-radius: 16px;
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.primary-btn:hover {
  background: #6c81ff;
  transform: translateY(-2px);
}

/* Range slider styling - Material Large */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: transparent;
  height: 40px;
}

input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  height: 12px;
  background: #333;
  border-radius: 6px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  height: 32px;
  width: 32px;
  background: #4f69ff;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  margin-top: -10px;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.1);
}
/* Mobile Responsiveness */
@media (max-width: 768px) {
  body {
    align-items: flex-start;
    padding: 20px 0;
  }

  body.frameless .digivice {
    flex-direction: column;
    gap: 30px;
    padding-top: 100px; /* Space for HUD/Utility */
  }

  body.frameless #gameCanvas {
    width: 320px;
    height: 320px;
    max-width: 95vw;
    margin: 0 auto;
  }

  body.frameless .physical-buttons {
    flex-direction: row;
    gap: 20px;
    padding: 20px;
    width: 100%;
    justify-content: center;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
  }

  body.frameless .round-button {
    width: 60px;
    height: 60px;
    font-size: 16px;
  }

  .utility-bar {
    top: auto;
    bottom: 20px;
    right: 50%;
    transform: translateX(50%);
    flex-direction: row;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
  }

  #hud-container {
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
  }
}
