/* ============================================================
   MONO PONG - 1-BIT ARCADE STYLESHEET  v1.1.0
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --fg: #ffffff;
  --bg: #000000;
  --font: 'Press Start 2P', 'Courier New', monospace;
}

/* ---- THEMES ---- */
body.theme-gameboy  { --fg: #0f380f; --bg: #9bbc0f; }
body.theme-terminal { --fg: #00ff41; --bg: #0a0a0a; }
body.theme-crt      { --fg: #e8e8cc; --bg: #050505; }

html, body {
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  overflow: hidden;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

/* ---- Z-INDEX STACK ----
   0   bg-canvas  (static noise)
   20  game-canvas
   25  touch-controls
   50  menu-layer
   100 scanline overlay (#app::after)
   ---- */

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  image-rendering: pixelated;
  pointer-events: none;
}

#game-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: none;
  image-rendering: pixelated;
  background: var(--bg);
  border: 2px solid var(--fg);
  pointer-events: none;
  touch-action: none;
}

#game-canvas.visible {
  display: block;
}

/* ---- TOUCH CONTROLS ---- */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  pointer-events: none;
}

#touch-controls.active {
  display: block;
  pointer-events: auto;
}

.touch-zone {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  touch-action: none;
}

.touch-zone-left  { left: 0; }
.touch-zone-right { right: 0; }

.touch-btns {
  position: absolute;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}

.touch-btns-left  { left: 12px; }

.touch-btn {
  width: 52px;
  height: 52px;
  background: var(--bg);
  border: 2px solid var(--fg);
  color: var(--fg);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  opacity: 0.55;
}

.touch-btn:active { opacity: 1; background: var(--fg); color: var(--bg); }

.touch-pause-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  pointer-events: auto;
}

/* ---- MENU LAYER ---- */
#menu-layer {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- SCREENS ---- */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  position: absolute;
  inset: 0;
}

.screen.active { display: flex; }

/* ---- MENU CONTAINER ---- */
.menu-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 36px 28px;
  border: 2px solid var(--fg);
  background: var(--bg);
  min-width: 280px;
  max-width: 460px;
  width: 92vw;
  position: relative;
}

.menu-container::before,
.menu-container::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--fg);
}

.menu-container::before { top: -2px;    left: -2px;  }
.menu-container::after  { bottom: -2px; right: -2px; }

/* ---- TITLE BLOCK ---- */
.title-block {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.title-glitch {
  font-size: clamp(14px, 4vw, 26px);
  color: var(--fg);
  text-shadow: 2px 0 var(--fg), -2px 0 var(--fg);
  letter-spacing: 4px;
  animation: titleFlicker 4s infinite;
  position: relative;
}

.title-glitch::before {
  content: attr(data-text);
  position: absolute;
  left: 2px; top: 0;
  color: var(--fg);
  opacity: 0.3;
  clip-path: polygon(0 30%, 100% 30%, 100% 50%, 0 50%);
  animation: glitchSlice 5s infinite;
}

.title-sub {
  font-size: clamp(7px, 1.4vw, 10px);
  color: var(--fg);
  opacity: 0.7;
  letter-spacing: 5px;
}

/* ---- MENU NAV ---- */
.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: center;
}

/* ---- MENU BUTTONS ---- */
.menu-btn {
  font-family: var(--font);
  font-size: clamp(9px, 2vw, 13px);
  color: var(--fg);
  background: var(--bg);
  border: 2px solid var(--fg);
  padding: 12px 24px;
  cursor: pointer;
  letter-spacing: 3px;
  text-transform: uppercase;
  width: 100%;
  max-width: 280px;
  position: relative;
  transition: none;
  outline: none;
  clip-path: polygon(
    0 4px, 4px 0,
    calc(100% - 4px) 0, 100% 4px,
    100% calc(100% - 4px), calc(100% - 4px) 100%,
    4px 100%, 0 calc(100% - 4px)
  );
  -webkit-tap-highlight-color: transparent;
}

.menu-btn:hover,
.menu-btn.selected {
  background: var(--fg);
  color: var(--bg);
}

.menu-btn:hover::after,
.menu-btn.selected::after {
  content: '>';
  position: absolute;
  left: 8px;
  color: var(--bg);
}

.menu-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.menu-btn.full-btn { max-width: 100%; }

/* ---- BUTTON ROW ---- */
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  width: 100%;
}

.btn-row .menu-btn { max-width: 180px; }

/* ---- MENU FOOTER ---- */
.menu-footer {
  font-size: 7px;
  color: var(--fg);
  opacity: 0.5;
  letter-spacing: 1px;
  text-align: center;
}

/* ---- SETTINGS CONTAINER ---- */
.settings-container {
  display: flex;
  flex-direction: column;
  width: 94vw;
  max-width: 680px;
  max-height: 94vh;
  border: 2px solid var(--fg);
  background: var(--bg);
  overflow: hidden;
}

.settings-container .title-block {
  padding: 18px 20px 0;
  flex-shrink: 0;
}

.settings-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--fg) var(--bg);
  -webkit-overflow-scrolling: touch;
}

.settings-scroll::-webkit-scrollbar       { width: 5px; }
.settings-scroll::-webkit-scrollbar-track { background: var(--bg); }
.settings-scroll::-webkit-scrollbar-thumb { background: var(--fg); }

.settings-section { margin-bottom: 20px; }

.settings-section-title {
  font-size: 8px;
  color: var(--fg);
  opacity: 0.55;
  letter-spacing: 3px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--fg);
  padding-bottom: 4px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  flex-wrap: wrap;
}

.setting-label {
  font-size: 8px;
  letter-spacing: 2px;
  min-width: 90px;
  flex-shrink: 0;
  line-height: 1.6;
}

.setting-options {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex: 1;
}

.opt-btn {
  font-family: var(--font);
  font-size: 7px;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 6px 9px;
  cursor: pointer;
  letter-spacing: 1px;
  outline: none;
  transition: none;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.opt-btn:hover,
.opt-btn.selected {
  background: var(--fg);
  color: var(--bg);
}

.settings-footer {
  padding: 10px 20px;
  border-top: 1px solid var(--fg);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}

/* ---- PIXEL INPUT ---- */
.pixel-input {
  font-family: var(--font);
  font-size: 11px;
  color: var(--fg);
  background: var(--bg);
  border: 2px solid var(--fg);
  padding: 9px 12px;
  outline: none;
  letter-spacing: 2px;
  min-width: 0;
  width: 100%;
  max-width: 180px;
  -webkit-appearance: none;
}

.pixel-input::placeholder {
  color: var(--fg);
  opacity: 0.35;
}

.pixel-input:focus { background: rgba(255,255,255,0.07); }

/* ---- NAME ERROR ---- */
.name-error {
  font-size: 8px;
  letter-spacing: 1px;
  color: var(--fg);
  height: 16px;
  padding-left: 2px;
  opacity: 0;
  transition: opacity 0.1s;
}

.name-error.visible {
  opacity: 1;
  animation: statusBlink 0.8s step-start infinite;
}

/* ---- JOIN FORM ---- */
.join-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.code-label {
  font-size: 8px;
  letter-spacing: 4px;
  opacity: 0.7;
  text-align: center;
}

.code-input {
  max-width: 210px;
  text-align: center;
  font-size: 16px;
  letter-spacing: 4px;
}

.join-status {
  font-size: 8px;
  letter-spacing: 2px;
  height: 18px;
  text-align: center;
}

.join-status.error { animation: statusBlink 0.5s step-start infinite; }

/* ---- HOST CODE DISPLAY (inline in settings-section) ---- */
.code-display-inline {
  text-align: center;
  padding: 12px 0 4px;
}

.code-value {
  font-size: clamp(18px, 5vw, 30px);
  letter-spacing: 8px;
  color: var(--fg);
  animation: codePulse 1.5s ease-in-out infinite;
  display: block;
  margin-bottom: 8px;
}

.code-status {
  font-size: 8px;
  letter-spacing: 2px;
  opacity: 0.6;
  animation: statusBlink 1s step-start infinite;
  display: block;
}

/* ---- SCANLINES OVERLAY ---- */
#app::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 2px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 4px
  );
  pointer-events: none;
  z-index: 100;
}

/* ---- SCREEN SHAKE ---- */
@keyframes screenShake {
  0%   { transform: translate(0,0); }
  20%  { transform: translate(-3px, 1px); }
  40%  { transform: translate(3px, -1px); }
  60%  { transform: translate(-1px, 3px); }
  80%  { transform: translate(2px, -2px); }
  100% { transform: translate(0,0); }
}

#app.shake { animation: screenShake 0.15s linear; }

/* ---- KEYFRAME ANIMATIONS ---- */
@keyframes titleFlicker {
  0%, 94%, 96%, 100% { opacity: 1; }
  95%                 { opacity: 0.3; }
}

@keyframes glitchSlice {
  0%, 90%, 100% { transform: translateX(0); }
  91%           { transform: translateX(-4px); }
  93%           { transform: translateX(4px); }
  95%           { transform: translateX(-2px); }
}

@keyframes codePulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

@keyframes statusBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* ---- RESPONSIVE / MOBILE ---- */
@media (max-width: 520px) {
  .menu-container {
    padding: 22px 14px;
    gap: 18px;
    border-left: none;
    border-right: none;
    width: 100vw;
    max-width: 100vw;
  }
  .menu-btn {
    padding: 14px 16px;
    font-size: 10px;
    max-width: 100%;
  }
  .opt-btn {
    padding: 8px 10px;
    font-size: 7px;
  }
  .settings-container {
    max-height: 100svh;
    border-left: none;
    border-right: none;
    width: 100vw;
    max-width: 100vw;
  }
  .setting-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .setting-options {
    justify-content: flex-start;
  }
  .title-glitch {
    font-size: clamp(14px, 6vw, 22px);
  }
  .pixel-input {
    max-width: 100%;
    font-size: 12px;
  }
  .btn-row .menu-btn {
    max-width: calc(50% - 4px);
    font-size: 9px;
    padding: 12px 8px;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .settings-container { max-height: 100svh; }
  .menu-container { gap: 12px; padding: 14px 20px; }
}
