:root {
  --bg: #0b0b14;
  --panel: #161628;
  --line: #2c2c4a;
  --text: #e6e6f0;
  --muted: #9a9ab8;
  --accent: #e8d24a;
  --accent2: #e8873a;
  --good: #5cc64c;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "VT323", ui-monospace, Consolas, monospace;
  font-size: 22px;
  line-height: 1.2;
  min-height: 100vh;
}

.top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 2px solid var(--line);
}

.logo {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: 20px;
  color: var(--accent);
  text-shadow: 3px 3px 0 #a33;
}
.logo span { color: var(--accent2); }

.player b { color: var(--good); }

.btn {
  font: inherit;
  font-size: 20px;
  color: var(--text);
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 2px 12px;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible { border-color: var(--accent); outline: none; }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); }

main, #play { max-width: 1040px; margin: 0 auto; padding: 16px; }

.intro { color: var(--muted); margin: 4px 0 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 2px solid var(--line);
  padding: 10px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card:hover, .card:focus-visible { border-color: var(--accent); outline: none; transform: translateY(-2px); }
.card canvas {
  width: 100%;
  aspect-ratio: 4 / 3;
  image-rendering: pixelated;
  background: #000;
  display: block;
}
.card h3 {
  margin: 4px 0 0;
  font-family: "Press Start 2P", monospace;
  font-size: 12px;
  color: var(--accent);
  line-height: 1.5;
}
.card p { margin: 0; color: var(--muted); font-size: 19px; }
.card .best { color: var(--good); }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}
#gtitle { font-family: "Press Start 2P", monospace; font-size: 13px; color: var(--accent); }
#gbest { margin-left: auto; color: var(--good); }

.screen {
  position: relative;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  border: 4px solid #222;
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(232, 210, 74, .12);
}
.screen canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  image-rendering: pixelated;
  background: #000;
  cursor: crosshair;
}
/* CRT tarama çizgileri */
.screen::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0 2px, rgba(0,0,0,.18) 2px 3px);
}

.keys { text-align: center; color: var(--muted); }

/* --- Dokunmatik gamepad --- */
.pad, .tbtn { display: none; }
.screen canvas, .pad, .tbtn {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.touch .keys { display: none; }
body.touch.playing .top { display: none; }
body.touch .tbtn { display: inline-block; min-width: 44px; }
body.touch #gbest { margin-left: auto; }

body.touch .stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "screen screen" "dpad acts";
  gap: 16px 8px;
  align-items: center;
}
body.touch .screen { grid-area: screen; }
body.touch .pad { display: flex; }

.dpad {
  grid-area: dpad;
  justify-self: start;
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, #24243e 0 30%, var(--panel) 31%);
  border: 3px solid var(--line);
}
.dpad span {
  position: absolute;
  color: var(--muted);
  font-size: 26px;
  line-height: 1;
  pointer-events: none;
}
.dpad .up { top: 10px; left: 50%; transform: translateX(-50%); }
.dpad .down { bottom: 10px; left: 50%; transform: translateX(-50%); }
.dpad .left { left: 12px; top: 50%; transform: translateY(-50%); }
.dpad .right { right: 12px; top: 50%; transform: translateY(-50%); }
.dpad[data-dir~="up"] .up, .dpad[data-dir~="down"] .down,
.dpad[data-dir~="left"] .left, .dpad[data-dir~="right"] .right { color: var(--accent); }

.acts {
  grid-area: acts;
  justify-self: end;
  align-items: center;
  gap: 14px;
}
.abtn {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  font-family: "Press Start 2P", monospace;
  font-size: 18px;
  color: #fff;
  background: #b8332a;
  border: 3px solid #e8584a;
  box-shadow: 0 4px 0 #6a1a14;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.abtn.bbtn { width: 62px; height: 62px; font-size: 14px; background: #2a5ab8; border-color: #4a7ae8; box-shadow: 0 4px 0 #14306a; }
.abtn.on, .tbtn.on { transform: translateY(3px); box-shadow: none; filter: brightness(1.25); }

/* Telefon yatay: gamepad ekranın iki yanında */
@media (orientation: landscape) and (max-height: 540px) {
  body.touch #play { padding: 6px 10px; max-width: none; }
  body.touch .bar { margin-bottom: 4px; gap: 8px; }
  body.touch .stage {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "dpad screen acts";
    gap: 10px;
  }
  body.touch .screen {
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    width: auto;
    max-width: 100%;
    aspect-ratio: 4 / 3;
    justify-self: center;
  }
  body.touch .screen canvas { width: 100%; height: 100%; }
  .dpad { width: 132px; height: 132px; }
  .acts { flex-direction: column-reverse; }
}

@media (max-width: 380px) {
  .dpad { width: 130px; height: 130px; }
  .abtn { width: 68px; height: 68px; }
}

dialog {
  background: var(--panel);
  color: var(--text);
  border: 2px solid var(--accent);
  padding: 20px;
  max-width: 360px;
  width: calc(100% - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .7); }
dialog h2 { margin: 0 0 8px; font-family: "Press Start 2P", monospace; font-size: 14px; color: var(--accent); }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog input {
  width: 100%;
  font: inherit;
  font-size: 24px;
  padding: 4px 8px;
  background: #000;
  color: var(--good);
  border: 2px solid var(--line);
}
dialog input:focus { outline: none; border-color: var(--accent); }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

@media (max-width: 600px) {
  .top { padding: 12px 16px; }
  .logo { font-size: 15px; }
}
