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

:root {
  --bg-a: #eef2f7;
  --bg-b: #e0e8f5;
  --card: #ffffff;
  --line: #dbe2ea;
  --ink: #102033;
  --muted: #66788f;
  --label: #1d4e89;
  --blue: #0066ff;
  --blue-hover: #1a73e8;
  --board: #0b1220;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  --radius: 16px;
  --touch: 48px;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-height: 100%;
  overflow-x: hidden;
  background-color: #0f172a !important;
  color-scheme: dark;
}

body {
  min-height: 100vh;
  font-family: Manrope, "Segoe UI", sans-serif;
  color: #e5e7eb !important;
  background-color: #111827 !important;
  background-image: linear-gradient(180deg, #0f172a 0%, #111827 100%) !important;
}

.app {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 10px 20px;
}

.topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--blue);
}

.brand {
  display: flex;
  justify-content: center;
  max-width: 100%;
}

.logo {
  display: block;
  height: 64px;
  width: auto;
  max-width: min(42vw, 110px);
  object-fit: contain;
}

.head-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
}

.intro {
  margin: 14px 0 16px;
  color: #cbd5e1;
  font-size: 0.9rem;
  text-align: center;
}

.game {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.card,
.board-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--label);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

.stat {
  min-width: 0;
  padding: 12px;
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.stat .label {
  margin-bottom: 4px;
}

.stat strong {
  display: block;
  font-size: 1.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.nextbox {
  display: grid;
  place-items: center;
  min-height: 118px;
  background: var(--board);
  border: 2px solid #1e3a5f;
  border-radius: 12px;
}

#next {
  display: block;
  width: 120px;
  height: 100px;
}

.help {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-wrap: break-word;
}

.help strong {
  color: var(--ink);
}

.help-rules p {
  margin: 0;
}

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  background: linear-gradient(180deg, #10233f 0%, var(--board) 40%);
  border: 2px solid var(--blue);
  box-shadow: 0 12px 28px rgba(0, 102, 255, 0.12);
}

#board {
  display: block;
  width: min(85vw, calc(55vh / 2), 240px);
  max-width: 85vw;
  height: auto;
  max-height: 55vh;
  aspect-ratio: 1 / 2;
  background: var(--board);
  border-radius: 8px;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  border-radius: 8px;
  background: rgba(8, 14, 28, 0.88);
  color: #f4f7ff;
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay-inner {
  width: 100%;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin-bottom: 8px;
  color: #7eb6ff;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.overlay h2 {
  margin-bottom: 8px;
  font-size: 1.7rem;
}

.overlay p {
  margin-bottom: 16px;
  color: #c5d4ea;
  font-size: 0.9rem;
}

.btn,
.controls button {
  min-height: var(--touch);
  border-radius: 12px;
  font: 700 0.85rem/1 Manrope, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  border: 0;
  padding: 10px 14px;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
}

.btn-primary:hover {
  background: var(--blue-hover);
}

.btn-ghost {
  background: #fff;
  color: var(--label);
  border: 1px solid var(--line);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: auto;
}

.controls button {
  border: 1px solid var(--line);
  background: #f7f9fc;
  color: var(--label);
  font-size: 1.25rem;
}

#rotateBtn { grid-column: 2; }
#leftBtn { grid-column: 1; grid-row: 2; }
#downBtn { grid-column: 2; grid-row: 2; }
#rightBtn { grid-column: 3; grid-row: 2; }

.drop {
  grid-column: 1 / -1;
  grid-row: 3;
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.foot {
  margin-top: 14px;
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
}

.btn:focus-visible,
.controls button:focus-visible {
  outline: 3px solid #7eb6ff;
  outline-offset: 2px;
}

.board-wrap {
  order: 1;
  width: fit-content;
  max-width: 100%;
  padding: 8px;
}

.side-left { order: 2; }
.side-right { order: 3; }

.help-keys,
.help-rules {
  display: none;
}

.stats {
  gap: 6px;
}

.stat {
  padding: 8px;
}

.stat strong {
  font-size: 1.15rem;
}

.nextbox {
  min-height: 72px;
}

#next {
  width: 96px;
  height: 72px;
}

.card {
  padding: 10px;
  gap: 10px;
}

.controls {
  margin-top: 0;
}

@media (min-width: 769px) {
  body {
    background-image: linear-gradient(180deg, #0f172a 0%, #111827 55%, #0b1220 100%) !important;
  }

  .app {
    padding: 16px 14px 24px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
  }

  .brand {
    grid-column: 2;
    justify-self: center;
  }

  .head-actions {
    grid-column: 3;
    justify-self: end;
    justify-content: flex-end;
  }

  .logo {
    height: 56px;
    max-width: 120px;
  }

  .intro {
    text-align: left;
    margin: 14px 0 16px;
  }

  .game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
  }

  .board-wrap,
  .side-left,
  .side-right {
    order: unset;
    width: auto;
  }

  .board-wrap {
    padding: 12px;
  }

  #board {
    width: min(100%, 290px);
    max-width: 290px;
    max-height: 70vh;
  }

  .card {
    padding: 16px;
    gap: 14px;
  }

  .stats {
    gap: 10px;
  }

  .stat {
    padding: 12px;
  }

  .stat strong {
    font-size: 1.6rem;
  }

  .nextbox {
    min-height: 118px;
  }

  #next {
    width: 120px;
    height: 100px;
  }

  .help-keys,
  .help-rules {
    display: block;
  }

  .overlay {
    inset: 12px;
  }

  .controls {
    margin-top: auto;
  }
}

@media (max-width: 768px) {
  html,
  body {
    height: 100dvh;
    overflow: hidden !important;
    background-color: #0f172a !important;
    color: #e5e7eb !important;
  }

  .app {
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px 8px 10px;
  }

  .intro,
  .foot,
  .help-keys,
  .help-rules {
    display: none !important;
  }

  .topbar {
    flex-shrink: 0;
    padding-bottom: 4px;
    gap: 2px;
    border-bottom-width: 2px;
  }

  .logo {
    height: 36px;
  }

  .head-actions .btn {
    min-height: 36px;
    padding: 6px 10px;
  }

  .game {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    gap: 6px;
    overflow: hidden;
    justify-content: flex-start;
  }

  .board-wrap {
    order: 1;
    flex: 0 0 auto;
    width: fit-content;
    max-width: 100%;
    margin: 0 auto;
    padding: 6px;
    background-color: #0b1220 !important;
    border-color: #3b82f6 !important;
  }

  #board {
    display: block;
    width: auto;
    height: auto;
    max-width: 85vw;
    max-height: 52vh;
  }

  .overlay {
    inset: 6px;
    padding: 10px;
  }

  .overlay h2 {
    font-size: 1.25rem;
  }

  .side-left,
  .side-right,
  .card,
  .stat,
  .btn-ghost,
  .controls button {
    background-color: rgba(30, 41, 59, 0.8) !important;
    color: #e5e7eb !important;
    border-color: rgba(59, 130, 246, 0.55) !important;
  }

  .label,
  .stat strong,
  .stat .label {
    color: #e2e8f0 !important;
  }

  .side-left {
    order: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 88px;
    align-items: center;
    gap: 4px;
    padding: 6px;
    margin: 0;
    flex: 0 0 auto;
  }

  .stats {
    gap: 4px;
  }

  .stat {
    padding: 4px 6px;
  }

  .stat strong {
    font-size: 0.95rem;
  }

  .label {
    margin-bottom: 2px;
    font-size: 0.58rem;
    letter-spacing: 0.05em;
  }

  .nextbox {
    min-height: 64px;
    background-color: #0b1220 !important;
    border-color: #3b82f6 !important;
  }

  #next {
    width: 72px;
    height: 56px;
  }

  .side-right {
    order: 3;
    align-self: stretch;
    width: 100%;
    max-width: 100%;
    gap: 0;
    margin: 0;
    padding: 8px 10px 4px;
    flex: 0 0 auto;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none;
  }

  .controls,
  .touch-controls,
  .d-pad {
    display: none !important;
  }

  #restartBtn,
  #startBtn {
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 12px 16px;
    font-size: 1rem;
  }

  #restartBtn {
    background: #0066ff !important;
    color: #fff !important;
    border-color: #0066ff !important;
  }
}
