/* ============================================================
   TETRIS VOL 5.0 — retro 90s stylesheet
   ============================================================ */

:root {
  --blue: #0019b3;
  --blue-deep: #000a4d;
  --blue-bevel-light: #4d6bff;
  --blue-bevel-dark: #00062b;
  --pink: #ff2d8a;
  --cyan: #00e5ff;
  --yellow: #ffd200;
  --green: #39ff14;
  --red: #ff3030;
  --orange: #ff8c00;
  --paper: #fff8c2;
}

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

html, body {
  min-height: 100%;
}

body {
  background: var(--blue);
  color: #fff;
  font-family: 'VT323', 'Courier New', monospace;
  font-size: 22px;
  line-height: 1.2;
  position: relative;
  overflow-x: hidden;
  cursor: crosshair;
}

/* sparkly blue starfield background */
.bg-stars {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(2px 2px at 12% 20%, #fff, transparent 60%),
    radial-gradient(1px 1px at 33% 70%, #fff, transparent 60%),
    radial-gradient(2px 2px at 78% 35%, var(--cyan), transparent 60%),
    radial-gradient(1px 1px at 55% 88%, #fff, transparent 60%),
    radial-gradient(2px 2px at 90% 75%, var(--pink), transparent 60%),
    radial-gradient(1px 1px at 8% 60%, var(--yellow), transparent 60%),
    radial-gradient(2px 2px at 45% 12%, #fff, transparent 60%),
    radial-gradient(1px 1px at 67% 50%, var(--green), transparent 60%),
    linear-gradient(180deg, #001066 0%, var(--blue) 50%, #000833 100%);
  background-size: 600px 600px, 600px 600px, 600px 600px, 600px 600px, 600px 600px, 600px 600px, 600px 600px, 600px 600px, 100% 100%;
  animation: stars 80s linear infinite;
}

@keyframes stars {
  from { background-position: 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0, 0 0; }
  to   { background-position: 600px 600px, -600px 600px, 600px -600px, -600px -600px, 300px 600px, 600px 300px, -300px 300px, 300px -300px, 0 0; }
}

/* top scrolling marquee */
.top-marquee {
  display: block;
  background: #000;
  color: var(--yellow);
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: 11px;
  padding: 8px 0;
  letter-spacing: 1px;
  border-top: 4px solid var(--pink);
  border-bottom: 4px solid var(--pink);
}

/* HEADER */
.page-header {
  text-align: center;
  padding: 28px 16px 10px;
}

.logo {
  display: block;
  margin: 0 auto;
  width: min(540px, 80vw);
  height: auto;
  filter: drop-shadow(4px 4px 0 #000) drop-shadow(0 0 12px var(--cyan));
  image-rendering: pixelated;
}

.tagline {
  margin-top: 8px;
  font-family: 'Press Start 2P', 'VT323', monospace;
  font-size: 12px;
  color: var(--yellow);
  text-shadow: 2px 2px 0 var(--pink);
  letter-spacing: 2px;
}

.blink {
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink {
  to { visibility: hidden; }
}

/* GAME SHELL */
.game-shell {
  display: grid;
  grid-template-columns: 220px auto 220px;
  gap: 18px;
  justify-content: center;
  align-items: start;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 880px) {
  .game-shell {
    grid-template-columns: 1fr;
  }
}

/* PANEL — bevelled retro frame */
.panel {
  background: var(--blue-deep);
  border: 4px solid #000;
  box-shadow:
    inset 4px 4px 0 var(--blue-bevel-light),
    inset -4px -4px 0 var(--blue-bevel-dark),
    6px 6px 0 #000;
  padding: 16px 14px;
}

.panel-title {
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  color: var(--cyan);
  text-shadow: 2px 2px 0 var(--pink);
  letter-spacing: 2px;
  margin-bottom: 10px;
  text-align: center;
}

/* STATS */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
  margin-bottom: 16px;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
}

.stats dt {
  color: var(--yellow);
  align-self: center;
}

.stats dd {
  background: #000;
  color: var(--green);
  padding: 6px 8px;
  border: 2px inset #888;
  text-align: right;
  font-size: 12px;
  min-width: 60px;
}

#next {
  display: block;
  margin: 0 auto 6px;
  border: 3px solid #000;
  box-shadow: inset 2px 2px 0 var(--blue-bevel-light), inset -2px -2px 0 var(--blue-bevel-dark);
  background: var(--blue-deep);
  image-rendering: pixelated;
}

/* BOARD */
.panel--board {
  padding: 12px;
  background: #000033;
}

.board-frame {
  position: relative;
  width: 312px; /* 300px canvas + 2 × 6px border */
  margin: 0 auto;
  border: 6px solid var(--pink);
  box-shadow:
    0 0 0 4px #000,
    0 0 24px var(--pink),
    inset 0 0 0 2px var(--cyan);
}

#board {
  display: block;
  background: #000044;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: rgba(0, 0, 30, 0.78);
  font-family: 'Press Start 2P', monospace;
  letter-spacing: 2px;
  pointer-events: none;
}

.overlay--hidden {
  display: none;
}

.overlay-title {
  font-size: 24px;
  color: var(--yellow);
  text-shadow: 3px 3px 0 var(--pink), -2px -2px 0 var(--cyan);
  margin-bottom: 16px;
}

.overlay-sub {
  font-size: 12px;
  color: var(--cyan);
}

.overlay--end .overlay-title {
  color: var(--red);
  text-shadow: 3px 3px 0 #000, -2px -2px 0 var(--yellow);
}

/* CONTROLS */
.keys {
  list-style: none;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.keys li {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  color: #fff;
}

.keys--scoring li {
  display: block;
  color: var(--green);
}

kbd {
  display: inline-block;
  background: linear-gradient(180deg, #f4f4f4 0%, #c0c0c0 100%);
  color: #000;
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 4px 6px;
  border: 2px solid #000;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #555, 2px 2px 0 #000;
  margin-right: 2px;
  min-width: 20px;
  text-align: center;
}

/* FOOTER */
.page-footer {
  text-align: center;
  padding: 30px 16px 24px;
  color: #fff;
  font-size: 18px;
}

.under-construction {
  background: repeating-linear-gradient(
    45deg,
    #ffd200 0 14px,
    #000 14px 28px
  );
  color: #000;
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 10px;
  letter-spacing: 2px;
  margin: 0 auto 14px;
  max-width: 720px;
  border: 4px solid #000;
  box-shadow: 4px 4px 0 var(--pink);
  -webkit-text-stroke: 1px #ffd200;
}

.cone {
  color: #000;
  -webkit-text-stroke: 0;
  font-size: 16px;
  margin: 0 8px;
}

.webring {
  font-size: 16px;
  margin: 12px 0;
  color: var(--yellow);
}

.webring a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.webring a:hover {
  color: var(--pink);
  background: #000;
}

.counter {
  display: inline-block;
  margin: 6px auto 12px;
  background: #000;
  border: 3px solid var(--green);
  padding: 4px 10px;
  font-family: 'Press Start 2P', monospace;
  font-size: 13px;
  color: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.counter-num {
  letter-spacing: 4px;
}

.copyleft {
  font-size: 14px;
  color: #b0b0ff;
  letter-spacing: 1px;
  font-family: 'Space Mono', monospace;
}

/* TOUCH CONTROLS — chunky bevelled arcade buttons, touch screens only */
.touchpad,
.tbtn--pause {
  display: none;
}

.touchpad {
  grid-column: 1 / -1;
  justify-content: space-between;
  gap: 14px;
}

.pad-group {
  display: flex;
  gap: 8px;
}

.pad-group--move { flex: 3; }
.pad-group--act { flex: 2; }

.tbtn {
  flex: 1 1 0;
  min-width: 0;
  height: 64px;
  font-family: 'Press Start 2P', monospace;
  font-size: 20px;
  color: #000;
  background: linear-gradient(180deg, #f4f4f4 0%, #c0c0c0 100%);
  border: 3px solid #000;
  border-radius: 0;
  box-shadow: inset 3px 3px 0 #fff, inset -3px -3px 0 #555, 4px 4px 0 #000;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.tbtn.is-down {
  box-shadow: inset 3px 3px 0 #555, inset -3px -3px 0 #fff;
  transform: translate(4px, 4px);
}

.tbtn--rotate {
  background: linear-gradient(180deg, #9ff7ff 0%, var(--cyan) 100%);
  font-size: 26px;
}

.tbtn--drop {
  background: linear-gradient(180deg, #ff8cc4 0%, var(--pink) 100%);
  color: #fff;
  font-size: 11px;
  text-shadow: 2px 2px 0 #000;
}

.tbtn--pause {
  width: 100%;
  height: 40px;
  margin-top: 10px;
  font-size: 9px;
  background: linear-gradient(180deg, #fff38a 0%, var(--yellow) 100%);
}

@media (pointer: coarse) {
  body {
    cursor: auto;
    touch-action: manipulation;
    overscroll-behavior: none;
  }
  .touchpad { display: flex; }
  .tbtn--pause { display: block; }
  .game-shell {
    user-select: none;
    -webkit-user-select: none;
  }
  .board-frame {
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }
}

/* PHONES (portrait) — board + slim status column, buttons underneath,
   everything sized to fit one screen without scrolling */
@media (max-width: 880px) {
  .top-marquee {
    font-size: 9px;
    padding: 5px 0;
    border-width: 3px;
  }
  .page-header { padding: 8px 10px 2px; }
  .logo {
    width: auto;
    height: clamp(44px, 9vh, 90px);
    max-width: 80vw;
  }
  .tagline {
    font-size: 7px;
    letter-spacing: 0;
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
  }
  .game-shell {
    grid-template-columns: auto minmax(88px, 104px);
    grid-template-areas:
      "board info"
      "pad pad"
      "keys keys";
    gap: 10px;
    padding: 8px 10px;
  }
  .panel--board { grid-area: board; padding: 6px; }
  .panel--info { grid-area: info; padding: 10px 8px; align-self: stretch; }
  .panel--controls { grid-area: keys; }
  .touchpad { grid-area: pad; }
  .board-frame {
    width: min(312px, calc(100vw - 168px), calc((100vh - 215px) / 2));
    width: min(312px, calc(100vw - 168px), calc((100dvh - 215px) / 2));
    min-width: 150px;
  }
  #board { width: 100%; height: auto; }
  .panel-title {
    font-size: 8px;
    letter-spacing: 1px;
  }
  .panel-title .deco { display: none; }
  .tbtn--pause { font-size: 8px; letter-spacing: 0; padding: 0; }
  .stats {
    grid-template-columns: 1fr;
    gap: 2px;
    font-size: 8px;
    margin-bottom: 10px;
  }
  .stats dd {
    font-size: 10px;
    padding: 4px 6px;
    min-width: 0;
    margin-bottom: 4px;
  }
  #next { width: 72px; height: 72px; }
  .overlay-title { font-size: 15px; letter-spacing: 1px; }
  .overlay-sub { font-size: 7px; letter-spacing: 1px; }
  .under-construction { font-size: 8px; letter-spacing: 1px; }
  .cone { font-size: 12px; margin: 0 4px; }
}

@media (max-width: 880px) and (pointer: coarse) {
  .panel--controls { display: none; }
}

/* PHONES (landscape) — d-pad left, board centre, status + actions right */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .top-marquee,
  .tagline { display: none; }
  .page-header {
    position: absolute;
    top: 8px;
    left: 16px;
    padding: 0;
  }
  .logo { height: 40px; max-width: none; }
  .game-shell {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "move board info"
      "move board act";
    grid-template-rows: auto 1fr;
    gap: 8px 16px;
    max-width: none;
    padding: 6px 16px;
  }
  .panel--board { grid-area: board; padding: 4px; }
  .panel--info { grid-area: info; align-self: start; padding: 8px; }
  .panel--controls { display: none; }
  .board-frame {
    width: calc((100vh - 44px) / 2);
    width: calc((100dvh - 44px) / 2);
    min-width: 110px;
  }
  #board { width: 100%; height: auto; }
  .stats {
    grid-template-columns: auto 1fr;
    font-size: 8px;
    margin-bottom: 6px;
  }
  .stats dd { font-size: 10px; padding: 2px 6px; min-width: 0; }
  .panel-title { margin-bottom: 6px; }
  #next { width: 56px; height: 56px; }
  .touchpad { display: contents; }
  .pad-group--move {
    grid-area: move;
    align-self: end;
    display: grid;
    grid-template-areas: "l r" "d d";
    gap: 10px;
  }
  .tbtn--left { grid-area: l; }
  .tbtn--right { grid-area: r; }
  .tbtn--down { grid-area: d; }
  .pad-group--act {
    grid-area: act;
    align-self: end;
  }
  .tbtn { height: 60px; }
  .tbtn--pause { height: 32px; margin-top: 6px; }
}

/* selection */
::selection {
  background: var(--pink);
  color: #000;
}
