body {
  margin: 0;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: #ffffff;
  background: #000000;
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.game-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding:
    calc(env(safe-area-inset-top, 0px) + 4px)
    8px
    calc(env(safe-area-inset-bottom, 0px) + 12px)
    8px;
}

.hud {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 6px 16px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.hud span {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.exit-button {
  cursor: pointer;
  color: rgba(255, 255, 255, 0.65);
  transition: color 0.2s ease;
}

.exit-button:hover {
  color: #ffffff;
}

.game-area {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#gameCanvas {
  width: auto;
  max-width: 100%;
  height: min(812px, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 64px));
  max-height: 100%;
  background: #2a2a2a;
  border: 2px solid #808080;
  border-radius: 12px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  border-radius: 12px;
}

.overlay.hidden {
  display: none;
}

.is-hidden {
  display: none !important;
}

.overlay.overlay-level-prep {
  transition: none;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
}

.overlay.overlay-level-fade {
  transition: background 1.5s ease-in, backdrop-filter 1.5s ease-in;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
}

.start-screen {
  text-align: center;
  color: #ffffff;
  max-width: 360px;
}

.start-screen.start-screen-fade-prep {
  opacity: 0;
}

.start-screen.start-screen-fade-in {
  transition: opacity 1s ease-in;
  opacity: 1;
}

.start-screen .copyright {
  margin: 12px 0 0;
  font-size: 15px;
  color: #44cc44;
  font-weight: 500;
  letter-spacing: 0.05em;
}

.title-letter {
  position: relative;
  display: inline-block;
}

.title-letter .letter-ball {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #000000;
  border-radius: 50%;
  pointer-events: none;
  z-index: 1;
}

.title-space {
  display: inline-block;
  width: 0.3em;
}

.start-screen h1 {
  margin: 0 0 8px;
  font-size: 52px;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: #ffffff;
  text-shadow:
    0 1px 0 #cccccc,
    0 2px 0 #bbbbbb,
    0 3px 0 #aaaaaa,
    0 4px 0 #999999,
    0 5px 0 #888888,
    0 6px 1px rgba(0,0,0,0.1),
    0 0 5px rgba(0,0,0,0.1),
    0 1px 3px rgba(0,0,0,0.3),
    0 3px 5px rgba(0,0,0,0.2),
    0 5px 10px rgba(0,0,0,0.25),
    0 10px 10px rgba(0,0,0,0.2),
    0 20px 20px rgba(0,0,0,0.15);
}

.start-screen .subtitle {
  margin: 0 0 24px;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.7);
  font-weight: 300;
}

.start-screen .instructions {
  margin: 0 0 32px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.5);
}

.start-screen .instructions.instruction-pop-prep {
  transition: none;
  transform: scale(0.5);
  opacity: 0;
}

.start-screen .instructions.instruction-pop-active {
  transition: transform 0.6s ease-out, opacity 0.4s ease-out;
  transform: scale(1.3);
  opacity: 1;
}

.start-screen .instructions.instruction-pop-settle {
  transition: transform 0.3s ease-in;
  transform: scale(1);
}

.start-screen button {
  appearance: none;
  border: none;
  cursor: pointer;
  background: #808080;
  color: #000000;
  padding: 16px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  width: 100%;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.start-screen button:hover {
  background: #a0a0a0;
  transform: translateY(-1px);
}

.start-screen button:active {
  transform: translateY(0);
}

.difficulty-buttons {
  display: grid;
  gap: 6px;
}

.settings-link {
  margin-top: 10px;
  margin-left: auto;
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  color: rgba(255, 255, 255, 0.65) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
  padding: 2px 5px !important;
  font-size: 8px !important;
  font-weight: 400 !important;
  width: auto !important;
  min-width: 44px !important;
  line-height: 1.1 !important;
  border-radius: 999px !important;
}

.settings-link:hover {
  color: rgba(255, 255, 255, 0.9) !important;
  border-color: rgba(255, 255, 255, 0.4) !important;
  transform: none !important;
}

.settings-screen {
  display: none;
  text-align: left;
  color: #ffffff;
  max-width: 720px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  padding: 16px;
}

.settings-screen:not(.is-hidden) {
  display: block;
}

.settings-screen h2 {
  margin: 0 0 12px;
  text-align: center;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.settings-grid {
  display: grid;
  gap: 10px;
}

.settings-row {
  display: grid;
  gap: 6px;
  font-size: 11px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.85);
}

.settings-row input {
  width: 50%;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.45);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 400;
}

.settings-row input:focus {
  outline: none;
  border-color: rgba(111, 212, 111, 0.8);
  box-shadow: 0 0 0 2px rgba(111, 212, 111, 0.2);
}

.start-screen .settings-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 14px;
}

.start-screen .settings-actions button {
  width: auto !important;
  max-width: 72px !important;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px !important;
  padding: 2px 5px !important;
  font-size: 8px !important;
  font-weight: 400 !important;
  line-height: 1.1 !important;
  border-radius: 999px !important;
  transform: none !important;
}

.settings-actions .settings-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
}

.difficulty-buttons .btn-ball {
  position: absolute;
  width: 6px;
  height: 6px;
  background: #000000;
  border-radius: 50%;
  pointer-events: none;
}

#btnEasy {
  background: #6fd46f;
}

#btnStart {
  background: #808080;
}

#btnHard {
  background: #e07070;
}

/* High Score List */
.highscore-screen {
  text-align: center;
  color: #ffffff;
  max-width: 360px;
  width: 100%;
}

.highscore-screen h2 {
  margin: 0 0 16px;
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: #ffd700;
}

.highscore-screen .hs-category {
  margin: 10px 0 6px;
  color: #cccccc;
  font-size: 14px;
  letter-spacing: 0.08em;
}

.highscore-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  font-size: 14px;
}

.highscore-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.highscore-list li.current-player {
  background: rgba(255, 215, 0, 0.15);
  border: 1px solid rgba(255, 215, 0, 0.3);
  border-radius: 4px;
}

.highscore-list .hs-rank {
  width: 24px;
  text-align: left;
  color: rgba(255,255,255,0.5);
  font-weight: 600;
}

.highscore-list .hs-name {
  flex: 1;
  text-align: left;
  padding: 0 8px;
}

.highscore-list .hs-score {
  width: 60px;
  text-align: right;
  font-weight: 600;
  color: #ffd700;
}

.highscore-list input[type="text"] {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,215,0,0.5);
  border-radius: 4px;
  color: #ffffff;
  font-size: 14px;
  padding: 4px 8px;
  width: 120px;
  outline: none;
  font-family: inherit;
}

.highscore-list input[type="text"]:focus {
  border-color: #ffd700;
  background: rgba(255,255,255,0.15);
}

.highscore-screen button {
  appearance: none;
  border: none;
  cursor: pointer;
  background: #808080;
  color: #000000;
  padding: 14px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 16px;
  width: 100%;
  transition: all 0.2s ease;
}

.highscore-screen button:hover {
  background: #a0a0a0;
  transform: translateY(-1px);
}

/* iPhone 13 Pro Max optimizations */
@media (min-width: 375px) {
  .game-container {
    max-width: 375px;
    margin: 0 auto;
  }
  
  #gameCanvas {
    width: auto;
    height: min(812px, calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 64px));
  }
}
