* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: radial-gradient(ellipse at top, #2b1a12 0%, #140b08 60%, #0a0504 100%);
  color: #f3e6c8;
  font-family: 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 24px 12px 40px;
}

h1 {
  font-family: Georgia, 'Times New Roman', serif;
  font-size: clamp(28px, 6vw, 44px);
  letter-spacing: 2px;
  margin: 6px 0 2px;
  color: #f6d675;
  text-shadow: 0 2px 0 #5c3a12, 0 0 24px rgba(246, 214, 117, 0.35);
  text-align: center;
}

.crown {
  font-size: 22px;
  display: block;
  margin-bottom: -4px;
}

.subtitle {
  color: #c9a97a;
  font-size: 14px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 18px;
  text-align: center;
}

#game-frame {
  position: relative;
  border-radius: 14px;
  padding: 10px;
  background: linear-gradient(180deg, #3a2313, #1c1108);
  box-shadow:
    0 0 0 2px #7a4e1e,
    0 0 0 6px #1c1108,
    0 20px 50px rgba(0,0,0,0.6);
  max-width: 100%;
}

canvas {
  display: block;
  border-radius: 6px;
  background: #111;
  width: 100%;
  max-width: 800px;
  height: auto;
  /* Maintain 4:3 aspect ratio via container or JS; CSS fallback */
  aspect-ratio: 4 / 3;
}

#overlay {
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  background: rgba(10, 6, 4, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 20px;
  gap: 14px;
}

#overlay h2 {
  font-family: Georgia, serif;
  font-size: 26px;
  color: #f6d675;
  margin: 0;
}

#overlay p {
  max-width: 420px;
  line-height: 1.5;
  color: #e6d3ac;
  margin: 0;
  font-size: 14px;
}

.key {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #3a2313;
  border: 1px solid #7a4e1e;
  font-weight: bold;
  font-size: 13px;
}

button {
  font-family: inherit;
  font-weight: bold;
  letter-spacing: 0.5px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  /* Better touch targets */
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

#start-btn {
  padding: 12px 28px;
  font-size: 16px;
  background: linear-gradient(180deg, #f6d675, #c9932a);
  color: #2b1a12;
  box-shadow: 0 3px 0 #7a4e1e;
}

#start-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #7a4e1e;
}

#controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
  width: 100%;
  max-width: 820px;
}

#mute-btn,
#restart-btn,
#go-back-btn {
  padding: 8px 14px;
  font-size: 13px;
  background: #3a2313;
  color: #f3e6c8;
  border: 1px solid #7a4e1e;
}

#mute-btn:hover,
#restart-btn:hover,
#go-back-btn:hover {
  background: #4a2c17;
}

#restart-btn {
  display: none;
}

footer {
  margin-top: 20px;
  font-size: 12px;
  color: #7a6248;
  text-align: center;
}

.legend {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  max-width: 640px;
  font-size: 12px;
  color: #c9a97a;
  padding: 0 8px;
}

.legend span.good {
  color: #7cd88c;
}

.legend span.bad {
  color: #e37a7a;
}

/* ========== Mobile optimizations ========== */
@media (max-width: 768px) {
  html, body {
    padding: 16px 8px 28px;
  }

  h1 {
    font-size: clamp(24px, 7vw, 36px);
    letter-spacing: 1px;
  }

  .crown {
    font-size: 18px;
  }

  .subtitle {
    font-size: 12px;
    margin-bottom: 14px;
  }

  #game-frame {
    padding: 6px;
    border-radius: 10px;
    box-shadow:
      0 0 0 2px #7a4e1e,
      0 0 0 4px #1c1108,
      0 12px 30px rgba(0,0,0,0.55);
  }

  #overlay {
    inset: 6px;
    padding: 14px 12px;
    gap: 10px;
  }

  #overlay h2 {
    font-size: 20px;
  }

  #overlay p {
    font-size: 13px;
    max-width: 100%;
  }

  #start-btn {
    padding: 14px 24px;
    font-size: 15px;
    width: 100%;
    max-width: 260px;
  }

  #controls-bar {
    gap: 8px;
    margin-top: 10px;
  }

  #mute-btn,
  #restart-btn,
  #go-back-btn {
    padding: 10px 12px;
    font-size: 12px;
    flex: 1 1 auto;
    min-width: 90px;
  }

  .legend {
    font-size: 11px;
    gap: 6px 10px;
    margin-top: 12px;
  }

  footer {
    font-size: 11px;
    margin-top: 16px;
  }
}

@media (max-width: 480px) {
  html, body {
    padding: 12px 6px 24px;
  }

  h1 {
    font-size: clamp(22px, 8vw, 30px);
  }

  .subtitle {
    font-size: 11px;
    letter-spacing: 0.5px;
  }

  #overlay h2 {
    font-size: 18px;
  }

  #overlay p {
    font-size: 12px;
  }

  .key {
    padding: 1px 6px;
    font-size: 12px;
  }

  #controls-bar {
    flex-direction: column;
    align-items: stretch;
  }

  #mute-btn,
  #restart-btn,
  #go-back-btn {
    width: 100%;
    max-width: none;
  }

  .legend {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
  }
}

/* Prefer reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  #start-btn:active {
    transform: none;
  }
}
