:root{
  --ink:#171b28;
  --muted:#5e687b;
  --line:rgba(23,27,40,.14);
  --paper:#fffdf7;
  --blue:#2f89d8;
  --green:#27a66b;
  --yellow:#f4c83f;
  --coral:#ef654d;
  --plum:#7d59b3;
}

*{ box-sizing:border-box; }

html,
body{
  width:100%;
  height:100%;
  margin:0;
  overflow:hidden;
  background:#f6fbff;
  color:var(--ink);
  font-family:system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  touch-action:manipulation;
}

button{ font:inherit; }

.tetrisApp{
  min-height:100vh;
  height:100vh;
  display:grid;
  grid-template-rows:auto minmax(0, 1fr) auto;
  gap:8px;
  padding:8px;
  background:
    linear-gradient(180deg, #e9f7ff 0%, #fffdf7 58%, #fff3d8 100%);
}

.topBar{
  display:grid;
  grid-template-columns:minmax(250px, 1fr) auto auto;
  gap:10px;
  align-items:center;
  min-width:0;
  padding:10px;
  border:1px solid var(--line);
  border-radius:8px;
  background:rgba(255,255,255,.92);
  box-shadow:0 12px 28px rgba(23,27,40,.12);
}

.brand{
  min-width:0;
  display:flex;
  align-items:center;
  gap:10px;
}

.brand img{
  width:122px;
  max-width:22vw;
  height:auto;
  object-fit:contain;
}

.brand h1{
  margin:0;
  font-size:clamp(26px, 3vw, 42px);
  line-height:1;
  font-weight:1100;
}

.brand p{
  margin:4px 0 0;
  color:var(--muted);
  font-size:15px;
  font-weight:850;
}

.stats,
.topActions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  flex-wrap:wrap;
}

.stat{
  min-width:90px;
  display:grid;
  gap:2px;
  padding:8px 10px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#ffffff;
  text-align:center;
  box-shadow:0 8px 18px rgba(23,27,40,.08);
}

.stat span{
  color:var(--muted);
  font-size:12px;
  font-weight:950;
  text-transform:uppercase;
}

.stat strong{
  color:var(--ink);
  font-size:24px;
  line-height:1;
  font-weight:1100;
}

.uiBtn,
.controlBtn,
.difficultyBtn{
  border:2px solid rgba(23,27,40,.14);
  border-radius:8px;
  background:#ffffff;
  color:var(--ink);
  box-shadow:0 8px 18px rgba(23,27,40,.10);
  cursor:pointer;
  user-select:none;
  touch-action:manipulation;
  font-weight:1050;
}

.uiBtn{
  min-height:46px;
  padding:10px 13px;
  font-size:15px;
}

.uiBtn.primary{
  color:#123d68;
  border-color:rgba(47,137,216,.38);
  background:rgba(47,137,216,.14);
}

.uiBtn.big{
  min-height:58px;
  min-width:150px;
  font-size:20px;
}

button:disabled{
  opacity:.48;
  pointer-events:none;
}

.gameStage{
  position:relative;
  min-height:0;
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:8px;
  background:#dff5ff;
  box-shadow:0 18px 38px rgba(23,27,40,.16);
}

.phaserMount{
  position:absolute;
  inset:0;
}

.phaserMount canvas{
  display:block;
  width:100% !important;
  height:100% !important;
}

.messageText{
  position:absolute;
  left:50%;
  bottom:12px;
  z-index:3;
  transform:translateX(-50%);
  max-width:min(820px, calc(100% - 24px));
  padding:9px 12px;
  border:1px solid rgba(23,27,40,.14);
  border-radius:8px;
  background:rgba(255,255,255,.86);
  color:var(--ink);
  box-shadow:0 8px 22px rgba(23,27,40,.13);
  font-size:clamp(15px, 1.7vw, 22px);
  line-height:1.15;
  font-weight:1000;
  text-align:center;
  pointer-events:none;
}

.messageText.good{ color:#176f45; }
.messageText.bad{ color:#ad352b; }

.controls{
  display:grid;
  grid-template-columns:repeat(5, minmax(96px, 1fr));
  gap:8px;
}

.controlBtn{
  min-height:70px;
  padding:10px;
  font-size:clamp(18px, 2vw, 28px);
  line-height:1;
}

.controlBtn.important{
  border-color:rgba(239,101,77,.34);
  background:rgba(255,244,224,.95);
}

.overlay{
  position:fixed;
  inset:0;
  z-index:1000;
  display:none;
  align-items:center;
  justify-content:center;
  padding:18px;
  background:rgba(23,27,40,.34);
}

.overlay.show{ display:flex; }

.overlayCard{
  width:min(880px, 96vw);
  max-height:92vh;
  overflow:auto;
  padding:18px;
  border:1px solid rgba(23,27,40,.16);
  border-radius:8px;
  background:rgba(255,255,255,.98);
  box-shadow:0 22px 70px rgba(23,27,40,.24);
  text-align:center;
}

.startCard{
  min-height:min(660px, 92vh);
  display:flex;
  flex-direction:column;
  justify-content:center;
}

.overlayCard img{
  width:min(230px, 58vw);
  max-height:90px;
  object-fit:contain;
  margin:0 auto 12px;
}

.overlayCard h2{
  margin:0 0 8px;
  font-size:clamp(38px, 6vw, 76px);
  line-height:.98;
  font-weight:1100;
}

.overlayCard p{
  max-width:64ch;
  margin:0 auto 14px;
  color:rgba(23,27,40,.78);
  font-size:18px;
  line-height:1.35;
  font-weight:850;
}

.difficultyGrid{
  width:min(680px, 100%);
  margin:8px auto 2px;
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:10px;
}

.difficultyBtn{
  min-height:112px;
  display:grid;
  gap:6px;
  align-content:center;
  padding:12px;
  text-align:left;
}

.difficultyBtn strong{
  display:block;
  font-size:24px;
  line-height:1;
}

.difficultyBtn span{
  color:var(--muted);
  font-size:14px;
  line-height:1.2;
  font-weight:850;
}

.difficultyBtn.active{
  border-color:rgba(47,137,216,.56);
  box-shadow:0 0 0 4px rgba(47,137,216,.14), 0 8px 18px rgba(23,27,40,.10);
}

.overlayActions{
  display:flex;
  justify-content:center;
  gap:10px;
  flex-wrap:wrap;
  margin-top:14px;
}

.statusText{
  min-height:24px;
  margin-top:10px;
  color:#ad352b;
  font-weight:950;
}

@media (max-width:1040px){
  .topBar{
    grid-template-columns:1fr;
  }
  .stats,
  .topActions{
    justify-content:center;
  }
  .brand{
    justify-content:center;
    text-align:center;
  }
}

@media (max-width:720px){
  .tetrisApp{
    padding:6px;
    gap:6px;
  }
  .brand img{ display:none; }
  .stats{
    display:grid;
    grid-template-columns:repeat(3, 1fr);
  }
  .stat{ min-width:0; }
  .controls{
    grid-template-columns:repeat(3, minmax(0, 1fr));
  }
  .controlBtn{
    min-height:58px;
  }
  .difficultyGrid{
    grid-template-columns:1fr;
  }
}

@media (max-height:720px){
  .brand p{ display:none; }
  .topBar{ padding:7px; }
  .controlBtn{ min-height:54px; }
  .overlayCard h2{ font-size:42px; }
}
