:root {
  --bg-dark: #080d16;
  --bg-mid: #101d31;
  --panel: rgba(14, 24, 40, 0.78);
  --panel-edge: rgba(148, 197, 255, 0.22);
  --text-main: #eef4ff;
  --text-muted: #9fb2cc;
  --accent: #ffbe0b;
  --accent-soft: #ffd166;
  --button: #1f3557;
  --button-hover: #2d4b78;
  --button-edge: #4f77ab;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--text-main);
  font-family: "Exo 2", "Segoe UI", sans-serif;
  background:
    radial-gradient(55rem 25rem at 15% 0%, rgba(76, 201, 240, 0.25), transparent 60%),
    radial-gradient(40rem 20rem at 100% 20%, rgba(251, 133, 0, 0.22), transparent 62%),
    linear-gradient(145deg, var(--bg-dark), var(--bg-mid) 56%, #060b12);
}

.app {
  width: min(1000px, 100%);
}

.header {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--accent-soft);
}

h1 {
  margin: 6px 0 8px;
  font-size: clamp(2rem, 4vw, 2.8rem);
  font-family: "Rajdhani", "Exo 2", sans-serif;
  line-height: 0.95;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 280px;
  gap: 20px;
}

.panel {
  border: 1px solid var(--panel-edge);
  background: var(--panel);
  border-radius: 18px;
  box-shadow: 0 18px 45px rgba(2, 8, 18, 0.42);
  backdrop-filter: blur(8px);
}

.board-panel {
  padding: 14px;
}

.board-wrap {
  width: fit-content;
  margin: 0 auto;
  position: relative;
}

#board {
  display: block;
  width: min(74vw, 320px);
  height: auto;
  border-radius: 12px;
  background: #050a13;
  border: 1px solid rgba(166, 212, 255, 0.25);
}

.overlay {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  background: linear-gradient(160deg, rgba(6, 11, 18, 0.85), rgba(8, 17, 31, 0.94));
  display: grid;
  place-content: center;
  text-align: center;
  padding: 18px;
  gap: 6px;
}

.overlay h2 {
  margin: 0;
}

.overlay p {
  margin: 0;
  color: var(--text-muted);
}

.hidden {
  display: none;
}

.primary-btn {
  margin-top: 10px;
  border: 1px solid transparent;
  background: linear-gradient(180deg, #ffd56f, var(--accent));
  color: #2a1c00;
  padding: 10px 14px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary-btn:hover {
  filter: brightness(1.02);
}

.hud-panel {
  padding: 14px;
  display: grid;
  gap: 14px;
  align-content: start;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stats > div {
  padding: 10px;
  border-radius: 12px;
  background: rgba(14, 28, 47, 0.7);
  border: 1px solid rgba(159, 191, 235, 0.2);
}

.label {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.value {
  margin: 3px 0 0;
  font-size: 1.32rem;
  font-weight: 700;
  font-family: "Rajdhani", "Exo 2", sans-serif;
}

.next-box h2,
.controls-info h2,
.touch-controls h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

#nextPiece {
  width: 140px;
  height: 140px;
  display: block;
  border-radius: 10px;
  background: rgba(6, 11, 20, 0.9);
  border: 1px solid rgba(166, 212, 255, 0.2);
}

.controls-info p {
  margin: 0 0 6px;
  color: var(--text-muted);
  font-size: 0.91rem;
}

.touch-controls {
  display: grid;
  gap: 8px;
}

.control-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.touch-controls button {
  border: 1px solid var(--button-edge);
  background: var(--button);
  color: var(--text-main);
  padding: 10px 8px;
  border-radius: 10px;
  font-size: 1.1rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

.touch-controls button:hover {
  background: var(--button-hover);
}

.touch-controls button:active {
  transform: translateY(1px);
}

.touch-controls .wide {
  grid-column: span 3;
  font-size: 0.95rem;
}

.touch-controls .span-2 {
  grid-column: span 2;
  font-size: 0.95rem;
}

@media (max-width: 880px) {
  body {
    padding: 12px;
    align-items: flex-start;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    min-height: calc(100dvh - 24px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .header {
    margin-bottom: 10px;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  .game-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 0;
  }

  .board-panel {
    padding: 10px;
  }

  #board {
    width: min(58vw, calc((100dvh - 320px) / 2), 320px);
  }

  .hud-panel {
    max-width: none;
    margin: 0;
    padding: 10px;
    gap: 10px;
  }

  .stats {
    gap: 6px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stats > div {
    padding: 7px 5px;
    text-align: center;
  }

  .label {
    font-size: 0.7rem;
  }

  .value {
    font-size: 1.02rem;
  }

  .next-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .next-box h2 {
    margin: 0;
    font-size: 0.92rem;
  }

  #nextPiece {
    width: 84px;
    height: 84px;
  }

  .controls-info {
    display: none;
  }

  .touch-controls h2 {
    display: none;
  }

  .touch-controls {
    gap: 6px;
  }

  .control-row {
    gap: 6px;
  }

  .touch-controls button {
    min-height: 44px;
    padding: 10px 6px;
    font-size: 1rem;
  }

  body.is-fullscreen {
    padding: 6px;
  }

  body.is-fullscreen .app {
    min-height: calc(100dvh - 12px);
    grid-template-rows: minmax(0, 1fr);
  }

  body.is-fullscreen .header {
    display: none;
  }

  body.is-fullscreen .game-shell {
    gap: 8px;
  }

  body.is-fullscreen .board-panel {
    padding: 8px;
  }

  body.is-fullscreen #board {
    width: min(56vw, calc((100dvh - 250px) / 2), 300px);
  }

  body.is-fullscreen .hud-panel {
    padding: 8px;
    gap: 8px;
  }

  body.is-fullscreen .stats > div {
    padding: 6px 4px;
  }

  body.is-fullscreen .next-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  body.is-fullscreen .next-box h2 {
    margin: 0;
    font-size: 0.8rem;
  }

  body.is-fullscreen #nextPiece {
    width: 68px;
    height: 68px;
  }

  body.is-fullscreen .controls-info {
    display: none;
  }

  body.is-fullscreen .touch-controls {
    gap: 5px;
  }

  body.is-fullscreen .control-row {
    gap: 5px;
  }

  body.is-fullscreen .touch-controls button {
    min-height: 38px;
    padding: 8px 6px;
    font-size: 0.94rem;
  }
}

@media (max-width: 880px) and (max-height: 700px) {
  .header {
    margin-bottom: 6px;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  h1 {
    margin: 4px 0 5px;
    font-size: clamp(1.6rem, 7vw, 2rem);
  }

  .subtitle {
    display: none;
  }

  #board {
    width: min(54vw, calc((100dvh - 300px) / 2), 260px);
  }

  .next-box {
    display: none;
  }

  .touch-controls button {
    min-height: 40px;
    padding: 8px 6px;
  }

  body.is-fullscreen .next-box {
    display: flex;
    gap: 6px;
  }

  body.is-fullscreen #nextPiece {
    width: 56px;
    height: 56px;
  }

  body.is-fullscreen #board {
    width: min(54vw, calc((100dvh - 220px) / 2), 280px);
  }
}

@media (max-width: 920px) and (max-height: 520px) and (orientation: landscape) {
  body {
    padding: 8px;
  }

  .app {
    min-height: calc(100dvh - 16px);
    width: min(980px, 100%);
  }

  .header {
    display: none;
  }

  .game-shell {
    grid-template-columns: minmax(0, 1fr) 250px;
    grid-template-rows: 1fr;
  }

  .board-panel {
    padding: 8px;
  }

  #board {
    width: min(calc((100dvh - 32px) / 2), 42vw, 280px);
  }

  .hud-panel {
    padding: 8px;
    gap: 8px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .next-box,
  .controls-info {
    display: none;
  }

  body.is-fullscreen .next-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }

  body.is-fullscreen .next-box h2 {
    display: none;
  }

  body.is-fullscreen #nextPiece {
    width: 48px;
    height: 48px;
  }

  .touch-controls button {
    min-height: 36px;
    padding: 7px 5px;
    font-size: 0.92rem;
  }

  body.is-fullscreen #board {
    width: min(calc((100dvh - 20px) / 2), 44vw, 290px);
  }
}
