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

:root {
  --bg-0: #0d1618;
  --bg-1: #132024;
  --bg-2: #1b2b30;
  --panel: rgba(20, 33, 37, 0.92);
  --panel-border: #4fb5a8;
  --panel-line: rgba(79, 181, 168, 0.3);
  --text-main: #f5ecce;
  --text-dim: #d6cda9;
  --accent: #4fb5a8;
  --accent-strong: #f5ecce;
  --danger: #cc6b5c;
  --success: #7fcd95;
  --button-top: #264045;
  --button-bottom: #1b2f33;
  --scanline: rgba(0, 0, 0, 0.16);
  --shadow: 0 0 0 1px rgba(79, 181, 168, 0.22), 0 14px 34px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "VT323", monospace;
  color: var(--text-main);
  background:
    radial-gradient(circle at 12% 10%, rgba(79, 181, 168, 0.12), transparent 34%),
    radial-gradient(circle at 90% 85%, rgba(245, 236, 206, 0.07), transparent 30%),
    linear-gradient(180deg, var(--bg-2), var(--bg-1) 40%, var(--bg-0));
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
  letter-spacing: 0.02em;
}

.page-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0px,
      transparent 2px,
      var(--scanline) 3px,
      transparent 4px
    );
  mix-blend-mode: soft-light;
  opacity: 0.6;
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 1rem;
  max-width: 1680px;
  height: calc(100vh - 1rem);
  margin: 0.5rem auto;
  padding: 0 1rem 1rem;
}

.title-bar {
  grid-column: 1 / -1;
  background: linear-gradient(180deg, rgba(31, 49, 54, 0.94), rgba(21, 35, 39, 0.94));
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.title-bar h1 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: clamp(1.2rem, 2.8vw, 1.8rem);
  color: var(--accent-strong);
  text-shadow: 0 0 10px rgba(79, 181, 168, 0.28);
}

.play-area,
.scores-panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.play-area {
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.hud {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.5rem;
}

.hud-block {
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  display: flex;
  flex-direction: column;
  background: rgba(25, 41, 46, 0.72);
}

.hud .label {
  color: var(--text-dim);
  font-size: 0.95rem;
  text-transform: uppercase;
}

.hud .value {
  font-size: 1.4rem;
  font-weight: 700;
}

.control-row {
  margin: 0.8rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

button {
  font-family: "Press Start 2P", monospace;
  font-size: 0.65rem;
  border: 1px solid #4fb5a8;
  background: linear-gradient(180deg, var(--button-top), var(--button-bottom));
  color: var(--accent-strong);
  border-radius: 7px;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  text-transform: uppercase;
  box-shadow: inset 0 0 0 1px rgba(245, 236, 206, 0.08);
}

button:hover {
  background: linear-gradient(180deg, #2f5158, #223b40);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#gameCanvas {
  width: min(100%, calc(100vh - 260px));
  aspect-ratio: 1 / 1;
  display: block;
  border: 1px solid rgba(79, 181, 168, 0.45);
  border-radius: 10px;
  background: #040403;
}

.controls-help {
  margin: 0.65rem 0 0;
  color: var(--text-dim);
  font-size: 1.1rem;
}

.mobile-pad {
  display: none;
  margin-top: 0.85rem;
  width: fit-content;
  max-width: 100%;
  margin-left: auto;
  justify-content: flex-end;
}

.pad-grid {
  width: min(188px, 56vw);
  max-width: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 0.34rem;
  user-select: none;
}

.pad-btn {
  font-family: "Press Start 2P", monospace;
  font-size: 0.82rem;
  min-height: 56px;
  width: 100%;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  touch-action: manipulation;
}

.pad-center {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.pad-empty {
  opacity: 0;
  pointer-events: none;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.scores-panel {
  padding: 0.85rem;
  max-height: calc(100vh - 1.6rem);
  overflow: auto;
}

.scores-panel h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: 0.92rem;
  color: var(--accent-strong);
}

.score-status {
  margin: 0.45rem 0 0.7rem;
  color: var(--text-dim);
  min-height: 1.2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  color: var(--text-dim);
  border-bottom: 1px solid rgba(79, 181, 168, 0.45);
  padding: 0.36rem;
  text-align: left;
  font-size: 0.95rem;
}

tbody td {
  padding: 0.35rem;
  border-bottom: 1px solid rgba(79, 181, 168, 0.2);
  font-size: 1.05rem;
}

tbody tr.me {
  background: rgba(79, 181, 168, 0.18);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 16, 0.88);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 3;
}

.overlay.visible {
  display: flex;
}

.overlay-card {
  width: min(94vw, 720px);
  max-height: 92vh;
  overflow: auto;
  background: rgba(20, 33, 37, 0.97);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.overlay-card h2 {
  margin: 0;
  font-family: "Press Start 2P", monospace;
  font-size: 1rem;
  color: var(--accent-strong);
}

.overlay-card p {
  color: var(--text-dim);
  font-size: 1.2rem;
}

.hidden {
  display: none;
}

#nameForm {
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 0.8rem;
  margin: 0.5rem 0;
  display: grid;
  gap: 0.5rem;
  background: rgba(24, 40, 44, 0.72);
}

#nameForm.hidden {
  display: none;
}

#nameForm label {
  color: var(--text-main);
  font-size: 1.1rem;
}

#nameInput {
  border: 1px solid rgba(79, 181, 168, 0.56);
  border-radius: 6px;
  background: #17282c;
  color: var(--text-main);
  font-family: "Press Start 2P", monospace;
  font-size: 0.72rem;
  padding: 0.6rem;
}

.submit-status {
  min-height: 1.2rem;
  margin: 0;
}

.submit-status.error {
  color: var(--danger);
}

.submit-status.ok {
  color: var(--success);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.overlay-snapshot {
  margin-top: 0.9rem;
}

.overlay-snapshot h3 {
  margin: 0 0 0.45rem;
  font-family: "Press Start 2P", monospace;
  font-size: 0.75rem;
  color: var(--accent-strong);
}

@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
    margin: 1rem auto;
  }

  .scores-panel {
    max-height: none;
  }

  #gameCanvas {
    width: 100%;
  }
}

@media (max-width: 900px) {
  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mobile-pad {
    display: flex;
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 680px) {
  .title-bar h1 {
    font-size: 1rem;
  }

  .hud {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.22rem;
  }

  .hud-block {
    padding: 0.16rem 0.2rem;
    border-radius: 5px;
  }

  .hud .label {
    font-size: 0.5rem;
    line-height: 1.05;
  }

  .hud .value {
    font-size: 0.72rem;
    line-height: 1.05;
  }

  button {
    font-size: 0.57rem;
    padding: 0.6rem 0.8rem;
  }

  .controls-help,
  tbody td,
  thead th {
    font-size: 0.92rem;
  }
}
