* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #06050c;
  --purple: #a55cff;
  --yellow: #ffd719;
  --green: #7cff00;
  --blue: #4aa3ff;
  --cyan: #27f3dc;
  --red: #ff4b5c;
  --text: #ffffff;
  --muted: rgba(255,255,255,.64);
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  display: flex;
  min-width: 320px;
  min-height: 100svh;
  flex-direction: column;
  color: var(--text);
  background-color: var(--bg);
  background-position: center;
  background-size: cover;
  background-attachment: fixed;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

button,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.arcade-nav {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: 14px max(30px, 7vw);
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(4,3,11,.72);
  backdrop-filter: blur(10px);
}

.arcade-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  font-size: 20px;
  font-weight: 900;
  letter-spacing: .035em;
  white-space: nowrap;
}

.brand-code {
  color: var(--purple);
  font-size: 28px;
  letter-spacing: -.12em;
}

.arcade-nav-links {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 999px;
  background: rgba(15,12,29,.78);
}

.arcade-nav-links a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 15px;
  border-radius: 999px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.arcade-nav-links a:hover {
  color: #fff;
  background: rgba(123,92,255,.18);
}

.arcade-nav-links i {
  width: 17px;
  color: var(--purple);
  text-align: center;
}

/* MÁS ESTRECHO: misma sensación que Space Shooter */
.tetris-page {
  width: min(1320px, 92vw);
  flex: 1 0 auto;
  margin: 0 auto;
  padding-bottom: 26px;
}

.site-footer {
  flex: 0 0 auto;
  margin-top: auto;
}

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding: 0 4px;
}

.toolbar-link {
  color: var(--purple);
  background: none;
  text-decoration: none;
  font-size: 13px;
  font-weight: 850;
  letter-spacing: .06em;
}

.toolbar-button {
  border: 0;
}

.arcade-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(330px, .95fr);
  min-height: calc(100svh - 160px);
  overflow: hidden;
  border: 1px solid rgba(181,108,255,.48);
  border-radius: 28px;
  background: linear-gradient(135deg,rgba(11,8,25,.94),rgba(5,4,14,.92));
  box-shadow: 0 35px 100px rgba(0,0,0,.62);
  backdrop-filter: blur(9px);
}

.board-column {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 18px 26px 20px;
  border-right: 1px solid rgba(255,255,255,.08);
}

/* TÍTULO estilo Space Shooter */
.tetris-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 17px;
  min-height: 70px;
  margin: 0 auto 7px;
  font-family: "Courier New", monospace;
  font-size: clamp(34px,3.6vw,50px);
  font-weight: 1000;
  letter-spacing: .08em;
}

.tetris-title-text {
  color: var(--cyan);
  text-shadow:
    2px 2px #285b77,
    0 0 8px rgba(39,243,220,.8),
    0 0 22px rgba(39,243,220,.4);
}

.tetris-mark {
  font-size: clamp(15px,1.7vw,23px);
  letter-spacing: -.24em;
  transform: skewX(-8deg);
}

.tetris-mark-left {
  color: var(--yellow);
  text-shadow: 0 0 10px rgba(255,215,25,.75);
}

.tetris-mark-right {
  color: var(--green);
  text-shadow: 0 0 10px rgba(124,255,0,.7);
}

.canvas-shell {
  position: relative;
  width: 100%;
  min-height: 390px;
  flex: 1;
  overflow: hidden;
  border: 2px solid rgba(18,104,255,.9);
  border-radius: 16px;
  background: #03060c;
  box-shadow:
    0 0 28px rgba(32,70,255,.22),
    inset 0 0 28px rgba(0,0,0,.7);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 390px;
  border-radius: 14px;
  background: #03060c;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  padding: 20px;
  color: #fff;
  text-align: center;
  background: rgba(0,0,0,.38);
  backdrop-filter: blur(2px);
}

.overlay-start {
  pointer-events: none;
}

.start-copy {
  color: rgba(255,255,255,.9);
  font-size: 17px;
  font-weight: 850;
  text-shadow: 0 4px 16px rgba(0,0,0,.7);
}

.start-copy b {
  color: var(--cyan);
}

.overlay-end {
  background: rgba(0,0,0,.6);
}

.ov-title {
  margin-bottom: 10px;
  color: var(--red);
  font-size: clamp(32px,4vw,48px);
  font-weight: 900;
}

.ov-sub {
  color: rgba(255,255,255,.92);
  font-size: 16px;
}

.btn-play-again {
  min-width: 180px;
  min-height: 48px;
  margin-top: 18px;
  padding: 10px 18px;
  border: 2px solid var(--cyan);
  border-radius: 12px;
  color: var(--cyan);
  background: rgba(6,34,38,.92);
  font-weight: 900;
  box-shadow: 0 0 18px rgba(39,243,220,.18);
}

.game-help {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 11px 24px;
  padding: 14px 5px 0;
  color: var(--muted);
  font-size: 12px;
}

.game-help b {
  color: rgba(255,255,255,.92);
}

.control-column {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 24px 28px 22px;
}

.desktop-stats,
.mobile-stats {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 12px;
}

.mobile-stats {
  display: none;
}

.stat-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-width: 0;
  padding: 12px 9px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 16px;
  background: rgba(255,255,255,.035);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
}

.stat-card > span:last-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-card b {
  color: var(--yellow);
  font-size: 19px;
}

.stat-icon {
  color: var(--yellow);
  font-size: 22px;
}

.stat-icon.cyan {
  color: var(--cyan);
}

.stat-icon.purple {
  color: var(--purple);
}

/* CONTROLES ORDENADOS */
.controls-block {
  margin: 30px 0 26px;
}

.keyboard-help h2,
.score-preview h2 {
  margin-bottom: 17px;
  color: var(--purple);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: .045em;
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2,minmax(0,1fr));
  gap: 9px;
}

.control-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 7px 9px;
  border: 1px solid rgba(255,255,255,.075);
  border-radius: 10px;
  color: rgba(255,255,255,.68);
  background: rgba(255,255,255,.025);
  font-size: 11px;
  font-weight: 700;
}

.control-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  height: 26px;
  padding: 0 7px;
  border: 1px solid rgba(39,243,220,.33);
  border-radius: 7px;
  color: var(--cyan);
  background: rgba(39,243,220,.055);
  font-family: "Courier New", monospace;
  font-weight: 900;
  box-shadow: inset 0 0 10px rgba(39,243,220,.025);
}

.control-key-wide {
  min-width: 68px;
  font-size: 10px;
}

.action-row {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 12px;
}

.arcade-action {
  min-height: 48px;
  border: 1px solid rgba(181,108,255,.45);
  border-radius: 13px;
  color: var(--purple);
  background: rgba(123,92,255,.08);
  font-size: 12px;
  font-weight: 900;
  transition: .18s ease;
}

.arcade-action:hover {
  transform: translateY(-1px);
  background: rgba(123,92,255,.14);
  box-shadow: 0 0 16px rgba(165,92,255,.12);
}

.score-preview {
  margin-top: 25px;
}

.ranking-preview {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 13px;
  background: rgba(255,255,255,.025);
  list-style: none;
}

.ranking-preview li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 8px;
  padding: 11px 14px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-size: 13px;
}

.ranking-preview li:last-child {
  border-bottom: 0;
}

.rank-position {
  color: var(--purple);
  font-weight: 900;
}

.ranking-preview li:first-child .rank-position,
.rank-score {
  color: var(--yellow);
  font-weight: 900;
}

.rank-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-loading,
.ranking-empty {
  display: block !important;
  color: var(--muted);
  text-align: center;
}

/* START dinámico estilo Space */
.btn-start-tetris {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  width: 100%;
  min-height: 58px;
  margin-top: auto;
  overflow: hidden;
  border: 2px solid var(--cyan);
  border-radius: 12px;
  color: var(--cyan);
  background:
    linear-gradient(135deg,rgba(5,31,35,.96),rgba(6,21,38,.96));
  font-family: "Courier New", monospace;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .08em;
  box-shadow:
    0 0 15px rgba(39,243,220,.18),
    inset 0 0 20px rgba(39,243,220,.035);
  transition: transform .18s ease,border-color .18s ease,box-shadow .18s ease,color .18s ease;
}

.btn-start-tetris::before {
  content: "";
  position: absolute;
  top: -45%;
  left: -30%;
  width: 22%;
  height: 190%;
  background: linear-gradient(90deg,transparent,rgba(255,255,255,.26),transparent);
  transform: skewX(-20deg);
  animation: startSweep 2.7s ease-in-out infinite;
}

.btn-start-tetris > span {
  position: relative;
  z-index: 1;
}

.start-piece {
  animation: piecePulse 1s ease-in-out infinite alternate;
}

.start-arrow {
  font-size: 13px;
  opacity: .7;
  animation: arrowNudge .8s ease-in-out infinite alternate;
}

.btn-start-tetris:hover {
  transform: translateY(-2px);
  color: #fff;
  border-color: var(--green);
  box-shadow:
    0 0 24px rgba(39,243,220,.24),
    0 0 18px rgba(124,255,0,.13);
}

@keyframes startSweep {
  0% { left: -30%; }
  45%,100% { left: 125%; }
}

@keyframes piecePulse {
  from { opacity: .55; transform: scale(.94); }
  to { opacity: 1; transform: scale(1.07); text-shadow: 0 0 10px rgba(39,243,220,.8); }
}

@keyframes arrowNudge {
  from { transform: translateX(0); }
  to { transform: translateX(4px); }
}

/* Mount vacío en desktop */
#tetrisMobileMount {
  display: none;
}

@media (max-width: 1050px) {
  .tetris-page {
    width: min(1180px,94vw);
  }

  .arcade-shell {
    grid-template-columns: minmax(0,1.4fr) minmax(310px,.85fr);
  }

  .control-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .arcade-nav {
    min-height: 68px;
    padding: 10px 16px;
  }

  .arcade-nav-links a {
    padding: 9px 10px;
  }

  .arcade-nav-links a span {
    display: none;
  }

  .tetris-page {
    width: calc(100% - 24px);
    padding-bottom: 20px;
  }

  .game-toolbar {
    min-height: 50px;
  }

  .arcade-shell {
    display: block;
    min-height: 0;
    border-radius: 22px;
  }

  .board-column {
    padding: 18px 16px 16px;
    border-right: 0;
  }

  .control-column {
    display: none;
  }

  .tetris-logo {
    min-height: 48px;
    margin-bottom: 12px;
    font-size: clamp(27px,8vw,40px);
  }

  .mobile-stats {
    display: grid;
    margin-bottom: 12px;
  }

  /* En móvil el tablero tiene más altura útil */
  .canvas-shell {
    min-height: 0;
    aspect-ratio: 10 / 13.5;
    flex: none;
  }

  #gameCanvas {
    width: 100%;
    height: 100%;
    min-height: 0;
  }

  #tetrisMobileMount {
    display: block;
  }

  /* Cruceta arcade compacta */
  .tetris-mobile-controls {
    display: grid;
    grid-template-columns: auto 94px;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 16px 0 5px;
  }

  .tetris-mobile-dpad {
    display: grid;
    grid-template-columns: repeat(3,48px);
    grid-template-rows: repeat(2,48px);
    gap: 7px;
  }

  .tetris-mobile-key {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border: 1px solid rgba(165,92,255,.55);
    border-radius: 13px;
    color: var(--purple);
    background: linear-gradient(180deg,#211539,#140d25);
    font-size: 19px;
    box-shadow:
      inset 0 1px 0 rgba(255,255,255,.055),
      0 5px 13px rgba(0,0,0,.22);
    touch-action: none;
    user-select: none;
  }

  .tetris-mobile-key:active {
    transform: scale(.93);
    color: #fff;
    background: rgba(165,92,255,.3);
  }

  .tetris-mobile-rotate {
    grid-column: 2;
    grid-row: 1;
    color: var(--green);
    border-color: rgba(124,255,0,.46);
  }

  .tetris-mobile-left {
    grid-column: 1;
    grid-row: 2;
  }

  .tetris-mobile-down {
    grid-column: 2;
    grid-row: 2;
  }

  .tetris-mobile-right {
    grid-column: 3;
    grid-row: 2;
  }

  .tetris-mobile-drop {
    min-width: 94px;
    min-height: 58px;
    padding: 10px 12px;
    border: 2px solid var(--cyan);
    border-radius: 13px;
    color: var(--cyan);
    background: linear-gradient(135deg,rgba(5,31,35,.96),rgba(6,21,38,.96));
    font-family: "Courier New", monospace;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .06em;
    box-shadow: 0 0 17px rgba(39,243,220,.18);
    touch-action: none;
  }

  .tetris-mobile-drop::before {
    content: "▼▼";
    display: block;
    margin-bottom: 3px;
    color: var(--green);
    font-size: 15px;
  }

  .tetris-mobile-drop:active {
    transform: scale(.95);
    border-color: var(--green);
  }

  .game-help {
    justify-content: center;
    gap: 7px 14px;
    font-size: 10px;
    line-height: 1.35;
  }
}

@media (max-width: 480px) {
  .arcade-brand {
    font-size: 14px;
  }

  .arcade-nav-links {
    padding: 4px;
  }

  .arcade-nav-links a {
    padding: 8px;
  }

  .tetris-page {
    width: calc(100% - 16px);
  }

  .toolbar-link {
    font-size: 12px;
  }

  .board-column {
    padding: 14px 10px 12px;
  }

  .tetris-logo {
    gap: 10px;
    font-size: 28px;
  }

  .mobile-stats {
    gap: 7px;
  }

  .stat-card {
    gap: 6px;
    padding: 9px 6px;
    font-size: 9px;
  }

  .stat-card b {
    font-size: 17px;
  }

  .canvas-shell {
    aspect-ratio: 10 / 14.5;
  }

  .tetris-mobile-controls {
    grid-template-columns: auto 82px;
    gap: 15px;
    padding-top: 13px;
  }

  .tetris-mobile-dpad {
    grid-template-columns: repeat(3,43px);
    grid-template-rows: repeat(2,43px);
    gap: 6px;
  }

  .tetris-mobile-key {
    width: 43px;
    height: 43px;
    font-size: 17px;
  }

  .tetris-mobile-drop {
    min-width: 82px;
    min-height: 54px;
    font-size: 10px;
  }

  .ov-title {
    font-size: clamp(26px,9vw,38px);
  }

  .ov-sub {
    font-size: 13px;
  }
}

@media (max-width: 360px) {
  .arcade-brand span:last-child {
    display: none;
  }

  .tetris-logo {
    font-size: 24px;
  }

  .tetris-mark {
    display: none;
  }
}