/* Retro Arcade Stylesheet for 寶島風情畫 */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

html,
body {
  touch-action: manipulation;
}

body {
  background:
    radial-gradient(circle at 50% 0%, rgba(0, 210, 211, 0.08), transparent 38rem),
    #070910;
  color: #c5c6c7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang TC", "Microsoft JhengHei", sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
  overflow-x: hidden;
  overscroll-behavior: none;
}

#arcade-cabinet {
  position: relative;
  width: 100%;
  max-width: 900px;
  background: linear-gradient(145deg, rgba(25, 31, 48, 0.98), rgba(12, 15, 27, 0.98));
  border-radius: 12px;
  border: 2px solid #2e354f;
  box-shadow: 0 0 35px rgba(0, 210, 211, 0.18), 0 20px 40px rgba(0, 0, 0, 0.6);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Header */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid #23293d;
  padding-bottom: 10px;
}

.title-group {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.main-title {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 2px;
  color: #00f2fe;
  text-shadow: 0 0 10px rgba(0, 242, 254, 0.6);
}

.subtitle {
  font-size: 13px;
  color: #fbc531;
  letter-spacing: 1px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Arcade Buttons */
.arcade-btn {
  background: #1f2538;
  color: #ffffff;
  border: 1px solid #3d4a6e;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.arcade-btn:hover {
  background: #2b334d;
  border-color: #00d2d3;
  color: #00d2d3;
  box-shadow: 0 0 8px rgba(0, 210, 211, 0.4);
}

.arcade-btn.primary-btn {
  background: #00a8ff;
  border-color: #0097e6;
  color: #ffffff;
}

.arcade-btn.primary-btn:hover {
  background: #0097e6;
  box-shadow: 0 0 12px rgba(0, 168, 255, 0.7);
}

.arcade-btn.active {
  background: #00d2d3;
  color: #111;
  border-color: #00f2fe;
}

/* Screen Wrapper */
.screen-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 800 / 480;
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  touch-action: none;
  border: 1px solid rgba(0, 242, 254, 0.18);
  box-shadow:
    inset 0 0 30px rgba(0, 0, 0, 0.9),
    0 0 15px rgba(0, 0, 0, 0.7),
    0 0 28px rgba(0, 210, 211, 0.10);
}

#gameCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

/* CRT Scanlines Overlay */
.crt-overlay {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  background: linear-gradient(
    rgba(18, 16, 16, 0) 50%,
    rgba(0, 0, 0, 0.35) 50%
  ),
  linear-gradient(
    90deg,
    rgba(255, 0, 0, 0.04),
    rgba(0, 255, 0, 0.02),
    rgba(0, 0, 255, 0.04)
  );
  background-size: 100% 3px, 6px 100%;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.6);
}

.crt-overlay.active {
  display: block;
}

/* Virtual Touch Controls */
.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  opacity: 0.44;
  transition: opacity 0.15s ease;
}

.touch-controls.touch-enabled {
  display: flex;
}

.touch-controls:focus-within,
.touch-controls:has(button:active) {
  opacity: 0.78;
}

.dpad {
  position: absolute;
  left: calc(env(safe-area-inset-left) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
}

.dpad-mid {
  display: flex;
  align-items: center;
  gap: 4px;
}

.dpad-center {
  width: 38px;
  height: 38px;
  background: rgba(27, 32, 48, 0.28);
  border-radius: 4px;
}

.dpad-btn {
  width: 58px;
  height: 58px;
  background: rgba(37, 45, 66, 0.58);
  border: 1px solid rgba(118, 137, 185, 0.72);
  color: #fff;
  border-radius: 6px;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.dpad-btn:active {
  background: #00d2d3;
  color: #111;
}

.action-buttons {
  position: absolute;
  right: calc(env(safe-area-inset-right) + 12px);
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  gap: 14px;
  align-items: center;
  pointer-events: auto;
}

.act-btn {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  border: 2px solid;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  touch-action: manipulation;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.rotate-prompt {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  background: #0b0c10;
  color: #fff;
  text-align: center;
}

.rotate-prompt .rotate-icon {
  font-size: 48px;
  color: #00f2fe;
}

.rotate-prompt small {
  color: #a4b0be;
}

.act-btn.fire-btn {
  background: rgba(0, 168, 255, 0.58);
  border-color: #00f2fe;
  box-shadow: 0 0 10px rgba(0, 168, 255, 0.5);
}

.act-btn.fire-btn:active {
  background: #0077c2;
  transform: scale(0.95);
}

.act-btn.bomb-btn {
  background: rgba(232, 65, 24, 0.58);
  border-color: #ff6b81;
  box-shadow: 0 0 10px rgba(232, 65, 24, 0.5);
}

.act-btn.bomb-btn:active {
  background: #b33918;
  transform: scale(0.95);
}

/* Footer / Instructions */
.game-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid #23293d;
  padding-top: 10px;
  font-size: 13px;
  color: #a4b0be;
}

.controls-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.badge {
  background: #23293d;
  color: #00f2fe;
  padding: 3px 7px;
  border-radius: 4px;
  font-family: monospace;
  font-weight: 600;
  border: 1px solid #3742fa;
}

/* Responsive */
@media (max-width: 600px) {
  #arcade-cabinet {
    padding: 8px;
  }
  .main-title {
    font-size: 18px;
  }
  .subtitle {
    display: none;
  }
  .game-header {
    align-items: stretch;
  }
  .header-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .arcade-btn {
    min-height: 44px;
    white-space: nowrap;
  }
  .game-footer {
    display: none;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  body {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    padding: 0;
    overflow: hidden;
  }
  #arcade-cabinet {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-width: none;
    padding: 0;
    border: 0;
    border-radius: 0;
  }
  .game-header {
    display: none;
  }
  .screen-wrapper {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
  }
  .rotate-prompt {
    display: flex;
  }
  .touch-controls {
    display: none !important;
  }
}

#arcade-cabinet:fullscreen {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  min-height: 100dvh;
  padding: 12px;
  border: 0;
  border-radius: 0;
}

#arcade-cabinet:fullscreen .screen-wrapper {
  flex: 1;
  min-height: 0;
  aspect-ratio: auto;
}

#arcade-cabinet:fullscreen .game-footer {
  display: none;
}

@media (orientation: landscape) and (max-width: 900px) {
  body {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    padding: 0;
    overflow: hidden;
  }
  #arcade-cabinet {
    width: 100vw;
    height: 100dvh;
    max-width: none;
    min-height: 100dvh;
    border-radius: 0;
    border: 0;
    padding: 0;
    gap: 0;
  }
  .game-header {
    position: absolute;
    z-index: 10;
    top: env(safe-area-inset-top);
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    min-height: 0;
    border: 0;
    padding: 0;
    pointer-events: none;
  }
  .title-group,
  #lvl-toggle-btn,
  #sound-toggle-btn,
  #crt-toggle-btn {
    display: none;
  }
  .header-actions {
    justify-content: flex-end;
    pointer-events: auto;
  }
  .header-actions .arcade-btn {
    min-height: 36px;
    padding: 5px 9px;
    font-size: 12px;
  }
  .screen-wrapper {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    border-radius: 0;
  }
  #gameCanvas {
    object-fit: fill;
  }
  .header-actions {
    flex-wrap: nowrap;
  }
  .game-footer {
    display: none;
  }
}
