@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/press-start-2p.woff2') format('woff2');
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
}

body {
  position: fixed;
  inset: 0;
  color: #fff;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  image-rendering: pixelated;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: none;
}

#game {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  padding: 20px;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.nes-box {
  border: 4px solid #fff;
  border-radius: 6px;
  background: #000;
  padding: 12px;
  font-size: 13px;
  line-height: 1.6;
}

.box-title {
  text-align: center;
  margin-bottom: 10px;
}

#lines-box {
  text-align: center;
  letter-spacing: 2px;
}

#lines-side {
  display: none;
  text-align: center;
}

#board-frame {
  position: relative;
  border: 4px solid #fff;
  border-radius: 6px;
  background: #000;
  padding: 4px;
}

#board {
  display: block;
  background: #000;
  touch-action: none;
}

#left-col {
  margin-top: 52px;
}

#stats-box {
  min-width: 170px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 34px;
}

.stat-row canvas {
  width: 48px;
  height: 24px;
}

.stat-count {
  color: #d82800;
  font-size: 13px;
}

#right-col {
  min-width: 150px;
}

#score-box .value,
#level-box .value {
  color: #fff;
}

.label.spaced {
  margin-top: 12px;
}

#next-box {
  text-align: center;
}

#next {
  display: block;
  margin: 0 auto;
}

#level-box {
  text-align: center;
}

#level-box .value {
  margin-top: 6px;
}

#help {
  font-size: 8px;
  color: #7c7c7c;
  line-height: 2;
}

/* ------------------------------------------------------------------------ */
/* Buttons (touch controls, pause / music, pause menu)                      */
/* ------------------------------------------------------------------------ */
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 3px solid #fff;
  border-radius: 12px;
  background: #1c1c1c;
  color: #fff;
  font-family: inherit;
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.btn svg {
  display: block;
  width: 38px;
  height: 38px;
  pointer-events: none;
}

.btn span {
  pointer-events: none;
}

.btn.on {
  background: #fff;
  color: #000;
}

.btn.rot {
  background: #a80020;
}

.btn.rot.on {
  background: #f83800;
  color: #fff;
}

#sys {
  display: flex;
  gap: 8px;
}

.btn.sys {
  flex: 1 1 0;
  height: 44px;
  border-radius: 8px;
}

.btn.sys svg {
  width: 22px;
  height: 22px;
}

#music-btn .slash {
  display: none;
}

#music-btn.off {
  color: #7c7c7c;
  border-color: #7c7c7c;
}

#music-btn.off .slash {
  display: block;
}

#pause-menu {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: #000;
  border-radius: 2px;
}

body[data-mode="paused"] #pause-menu {
  display: flex;
}

.pm-title {
  font-size: 22px;
  margin-bottom: 14px;
}

.btn.menu {
  width: 72%;
  max-width: 220px;
  height: 56px;
  font-size: 12px;
}

#controls {
  display: none;
}

#rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #000;
  font-size: 12px;
  line-height: 2.2;
}

/* ------------------------------------------------------------------------ */
/* Compact layout: phones and any touch screen (class set by tetris.js)      */
/* ------------------------------------------------------------------------ */
body.compact {
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 8px;
  padding:
    calc(env(safe-area-inset-top, 0px) + 6px)
    calc(env(safe-area-inset-right, 0px) + 8px)
    calc(env(safe-area-inset-bottom, 0px) + 8px)
    calc(env(safe-area-inset-left, 0px) + 8px);
}

body.compact #game {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  gap: 8px;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
}

body.compact .col {
  gap: 8px;
}

body.compact #left-col,
body.compact #lines-box,
body.compact #help {
  display: none;
}

body.compact #lines-side {
  display: block;
}

body.compact #board-frame {
  border-width: 3px;
  padding: 2px;
}

body.compact #right-col {
  width: 92px;
  min-width: 92px;
}

body.compact .nes-box {
  border-width: 3px;
  padding: 7px 4px;
  font-size: 9px;
  line-height: 1.7;
  text-align: center;
}

body.compact .box-title {
  margin-bottom: 4px;
}

body.compact .label.spaced {
  margin-top: 6px;
}

body.compact #level-box .value {
  margin-top: 0;
}

body.compact #controls {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 12px;
  height: clamp(150px, 25vh, 220px);
  height: clamp(150px, 25dvh, 220px);
}

body.compact .pad {
  flex: 1 1 0;
  max-width: 210px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.15fr 1fr;
  gap: 8px;
}

body.compact .pad .wide {
  grid-column: 1 / span 2;
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  #rotate-notice {
    display: flex;
  }
}
