/* ═══════════════════════════════════════════════
   TETRIS — Mobile-First | Full-Screen
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:     #0a0a14;
  --panel:  #0f0f1e;
  --border: #1a1a3a;
  --cyan:   #00f5ff;
  --yellow: #ffe600;
  --purple: #bf00ff;
  --green:  #00ff41;
  --red:    #ff003c;
  --orange: #ff6d00;
  --white:  #e8e8ff;
  --dim:    #4a4a6a;
  --font:   'Press Start 2P', monospace;
  --safe-t: env(safe-area-inset-top,    0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left,   0px);
  --safe-r: env(safe-area-inset-right,  0px);
}

html, body {
  height: 100%;
  height: -webkit-fill-available;
  background: var(--bg);
  color: var(--white);
  font-family: var(--font);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

/* ─── Screens ─── */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
  overflow: hidden;
}
.screen.active { opacity: 1; pointer-events: all; }

/* ─── Stars ─── */
.stars { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.star  { position: absolute; border-radius: 50%; background: #fff; animation: twinkle var(--d) ease-in-out infinite; }
@keyframes twinkle { 0%,100%{opacity:.1;transform:scale(1)} 50%{opacity:.9;transform:scale(1.5)} }

/* ═══ REGISTER ══════════════════════════════════ */
.register-wrap {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  align-items: center; gap: 20px;
  padding: 20px 16px;
  padding-top:    calc(20px + var(--safe-t));
  padding-bottom: calc(20px + var(--safe-b));
  width: 100%; max-width: 420px;
  max-height: 100vh; overflow-y: auto;
}
.logo-block { font-size: clamp(28px, 10vw, 46px); letter-spacing: 5px; line-height: 1; }
.logo-block span { display: inline-block; animation: logoFloat 2s ease-in-out infinite; }
.logo-t  { color: var(--cyan);   text-shadow: 0 0 18px var(--cyan),   0 0 36px var(--cyan);   animation-delay:  0s; }
.logo-e  { color: var(--yellow); text-shadow: 0 0 18px var(--yellow), 0 0 36px var(--yellow); animation-delay: .1s; }
.logo-t2 { color: var(--green);  text-shadow: 0 0 18px var(--green),  0 0 36px var(--green);  animation-delay: .2s; }
.logo-r  { color: var(--red);    text-shadow: 0 0 18px var(--red),    0 0 36px var(--red);    animation-delay: .3s; }
.logo-i  { color: var(--purple); text-shadow: 0 0 18px var(--purple), 0 0 36px var(--purple); animation-delay: .4s; }
.logo-s  { color: var(--orange); text-shadow: 0 0 18px var(--orange), 0 0 36px var(--orange); animation-delay: .5s; }
@keyframes logoFloat { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-5px)} }

.register-card { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 24px 20px; width: 100%; }
.card-title    { font-size: 10px; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); margin-bottom: 22px; text-align: center; }
.form-group    { margin-bottom: 18px; }
.form-group label { display: block; font-size: 7px; color: var(--dim); margin-bottom: 7px; letter-spacing: 1px; }
.form-group input {
  width: 100%; background: #05050f; border: 1px solid var(--border); border-radius: 2px;
  color: var(--white); font-family: var(--font); font-size: 12px; padding: 13px 14px;
  outline: none; -webkit-appearance: none; transition: border-color .2s, box-shadow .2s;
}
.form-group input:focus  { border-color: var(--cyan); box-shadow: 0 0 14px rgba(0,245,255,.3); }
.form-group input::placeholder { color: var(--dim); }
.form-error { font-size: 8px; color: var(--red); text-shadow: 0 0 8px var(--red); margin-bottom: 10px; text-align: center; }

/* Pixel buttons (shared) */
.pixel-btn {
  font-family: var(--font); font-size: 10px; padding: 14px 20px;
  border: none; border-radius: 2px; cursor: pointer; letter-spacing: 1px;
  transition: all .12s; display: block; width: 100%; margin-top: 10px;
  -webkit-appearance: none; touch-action: manipulation;
}
.pixel-btn.primary  { background: var(--cyan); color: #000; box-shadow: 0 0 20px rgba(0,245,255,.5), 0 3px 0 #006b70; text-shadow: none; }
.pixel-btn.primary:active  { transform: scale(.97) translateY(2px); box-shadow: 0 0 20px rgba(0,245,255,.4), 0 1px 0 #006b70; }
.pixel-btn.secondary { background: transparent; color: var(--dim); border: 1px solid var(--border); }
.pixel-btn.secondary:active { color: var(--white); border-color: var(--dim); }
.pixel-btn.ghost    { background: transparent; color: var(--dim); border: none; font-size: 8px; }
.pixel-btn.small    { font-size: 8px; padding: 8px 14px; width: auto; display: inline-block; margin: 0; }

.top3-preview { font-size: 8px; color: var(--dim); text-align: center; line-height: 2.4; }
.top3-preview .t3-item { color: var(--white); }
.top3-preview .t3-item.gold { color: var(--yellow); text-shadow: 0 0 8px var(--yellow); }

/* ═══ GAME SCREEN (mobile default) ══════════════ */
#screen-game { justify-content: flex-start; }

/* ── Mobile topbar ── */
.m-topbar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: calc(var(--safe-t) + 4px) calc(var(--safe-l) + 8px) 4px;
  min-height: 48px;
}
.m-stat-score {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.m-val-score {
  font-size: 16px;
  color: var(--cyan);
  text-shadow: 0 0 10px var(--cyan);
  line-height: 1;
}
.m-stat-group {
  display: flex;
  gap: 0;
  align-items: center;
  border-left: 1px solid var(--border);
  margin-left: 6px;
  padding-left: 6px;
}
.m-stat {
  text-align: center;
  padding: 0 7px;
  border-right: 1px solid var(--border);
}
.m-stat:last-child { border-right: none; }
.m-label   { font-size: 5px; color: var(--dim); letter-spacing: 1px; margin-bottom: 3px; }
.m-val     { font-size: 11px; color: var(--white); line-height: 1; }
.m-val-best { color: var(--yellow); }
.m-topbar-btns { display: flex; gap: 5px; margin-left: 8px; flex-shrink: 0; }

.icon-btn {
  background: rgba(255,255,255,.04); border: 1px solid var(--border); border-radius: 4px;
  color: var(--dim); font-family: var(--font); font-size: 11px; cursor: pointer;
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; transition: all .12s;
}
.icon-btn:active { background: rgba(0,245,255,.12); border-color: var(--cyan); color: var(--cyan); }
.icon-btn.muted  { color: var(--red); border-color: rgba(255,0,60,.5); }

/* ── Game layout ── */
.game-layout {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
}
/* Desktop side panels: hidden on mobile */
.side-panel { display: none; }

.board-area {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
}
.board-wrap { position: relative; line-height: 0; }

#canvas-board {
  display: block;
  border: 1px solid #1e1e3e;
  box-shadow: 0 0 0 1px #0a0a20, 0 0 24px rgba(0,245,255,.14), 0 0 48px rgba(0,245,255,.06);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* Board overlay */
.board-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.board-overlay.hidden { display: none; }
.overlay-inner { text-align: center; padding: 20px; }
.ov-title {
  font-size: clamp(12px, 4vw, 20px); color: var(--red);
  text-shadow: 0 0 20px var(--red), 0 0 40px var(--red);
  margin-bottom: 14px;
  animation: pulse 1s ease-in-out infinite;
}
.ov-score {
  font-size: clamp(9px, 2.5vw, 12px); color: var(--yellow);
  text-shadow: 0 0 10px var(--yellow);
  margin-bottom: 22px; line-height: 2;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }

/* ── Desktop control buttons — hidden by default (mobile-first) ── */
.d-ctrl { display: none !important; }

/* ── Mobile controls ── */
.m-ctrl {
  width: 100%; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 4px calc(var(--safe-l) + 6px) calc(4px + var(--safe-b));
}
.mc-row { display: flex; gap: 4px; }

/* Shared mc-btn base */
.mc-btn {
  font-family: var(--font);
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  color: var(--white); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation; -webkit-user-select: none;
  transition: background .08s, border-color .08s, transform .07s, box-shadow .08s;
  -webkit-tap-highlight-color: transparent;
}
.mc-btn:active, .mc-btn.pressed { transform: scale(.91); background: #1c1c3e; }

/* Row 1: HOLD | PAUSE (center) | ROTATE */
.mc-row-top .mc-btn { flex: 1; height: 38px; font-size: 9px; letter-spacing: .3px; }
.mc-hold   { color: var(--orange) !important; border-color: rgba(255,109,0,.35) !important; }
.mc-hold.pressed,   .mc-hold:active   { border-color: var(--orange) !important; box-shadow: 0 0 10px rgba(255,109,0,.4) !important; }
.mc-rotate { color: var(--green)  !important; border-color: rgba(0,255,65,.35)  !important; }
.mc-rotate.pressed, .mc-rotate:active { border-color: var(--green)  !important; box-shadow: 0 0 10px rgba(0,255,65,.4) !important; }
.mc-pause  { color: var(--dim) !important; font-size: 16px !important; flex: 0 0 50px !important; }

/* Row 2: ◀ | ▼ | ▶ */
.mc-row-mid .mc-btn { flex: 1; height: 52px; font-size: 22px; }
.mc-down  { color: var(--yellow) !important; border-color: rgba(255,230,0,.35) !important; }
.mc-down.pressed, .mc-down:active { border-color: var(--yellow) !important; box-shadow: 0 0 10px rgba(255,230,0,.4) !important; }

/* Row 3: HARD DROP */
.mc-row-bot .mc-btn {
  flex: 1; height: 38px; font-size: 10px; letter-spacing: 1px;
  background: rgba(0,245,255,.07); border-color: rgba(0,245,255,.3); color: var(--cyan);
}
.mc-drop.pressed, .mc-drop:active { background: rgba(0,245,255,.18) !important; border-color: var(--cyan) !important; box-shadow: 0 0 14px rgba(0,245,255,.4) !important; }

/* ═══ TUTORIAL OVERLAY ══════════════════════════ */
.tut-overlay {
  position: absolute; inset: 0; z-index: 100;
  background: rgba(0,0,8,.96);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(8px); overflow-y: auto;
}
.tut-overlay.hidden { display: none; }
.tut-box {
  width: 100%; max-width: 360px;
  padding: 24px 20px;
  padding-top:    calc(24px + var(--safe-t));
  padding-bottom: calc(24px + var(--safe-b));
  text-align: center;
}
.tut-logo  { font-size: 28px; letter-spacing: 4px; margin-bottom: 4px; }
.tut-title { font-size: 11px; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); margin-bottom: 20px; letter-spacing: 2px; }
.tut-section { margin-bottom: 14px; text-align: left; }
.tut-head  { font-size: 7px; color: var(--dim); letter-spacing: 1px; margin-bottom: 9px; text-align: center; }
.tut-row   { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid #1a1a2e; font-size: 7px; }
.tut-row:last-child { border: none; }
.tut-gest  { color: var(--cyan); text-shadow: 0 0 6px var(--cyan); min-width: 110px; }
.tut-desc  { color: var(--white); text-align: right; }
.tut-divider { font-size: 7px; color: var(--dim); letter-spacing: 2px; margin: 14px 0 12px; text-align: center; }
.tut-btns-preview {
  background: var(--panel); border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 8px; display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px;
}
.tbp-row   { display: flex; gap: 4px; }
.tbp-btn   { flex: 1; font-size: 7px; background: #0a0a20; border: 1px solid var(--border); border-radius: 4px; padding: 8px 4px; text-align: center; color: var(--white); }
.tbp-big   { padding: 11px 4px; font-size: 15px; }
.tbp-full  { }
.c-orange  { color: var(--orange); border-color: rgba(255,109,0,.4); }
.c-green   { color: var(--green);  border-color: rgba(0,255,65,.4); }
.c-yellow  { color: var(--yellow); border-color: rgba(255,230,0,.4); }
.c-cyan    { color: var(--cyan);   border-color: rgba(0,245,255,.4); }
.c-dim     { color: var(--dim); }
.tut-tip   { font-size: 7px; color: var(--dim); margin-bottom: 18px; line-height: 2; }

/* ═══ SCORE SCREEN ══════════════════════════════ */
.score-wrap {
  width: 100%; max-width: 400px;
  padding: 20px 20px;
  padding-top:    calc(16px + var(--safe-t));
  padding-bottom: calc(16px + var(--safe-b));
  text-align: center; overflow-y: auto; max-height: 100vh;
}
.pb-banner {
  margin-bottom: 16px; padding: 16px;
  background: linear-gradient(135deg, rgba(255,230,0,.15), rgba(255,109,0,.1));
  border: 1px solid rgba(255,230,0,.4); border-radius: 4px;
  animation: pbPulse 1.5s ease-in-out infinite;
}
.pb-trophy { font-size: 40px; margin-bottom: 8px; }
.pb-text   { font-size: 10px; color: var(--yellow); text-shadow: 0 0 12px var(--yellow); letter-spacing: 1px; }
@keyframes pbPulse { 0%,100%{box-shadow:0 0 0 rgba(255,230,0,0)} 50%{box-shadow:0 0 20px rgba(255,230,0,.3)} }

.gameover-title { font-size: clamp(20px, 7vw, 30px); margin-bottom: 18px; animation: pulse 1.2s ease-in-out infinite; }
.final-stats { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 14px 18px; margin-bottom: 18px; }
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 10px; }
.stat-row:last-child { border: none; }
.stat-row span:first-child { color: var(--dim); }
.stat-row span:last-child  { color: var(--cyan); text-shadow: 0 0 8px var(--cyan); }
.rank-row span:last-child  { color: var(--yellow); text-shadow: 0 0 8px var(--yellow); font-size: 16px; }

.email-section { margin-bottom: 16px; }
.email-q       { font-size: 8px; color: var(--dim); margin-bottom: 10px; line-height: 2; }
.email-choice-btns { display: flex; flex-direction: column; gap: 6px; }
.success-msg   { font-size: 9px; color: var(--green); text-shadow: 0 0 8px var(--green); margin-top: 8px; line-height: 2; }
.error-msg     { font-size: 9px; color: var(--red);   text-shadow: 0 0 8px var(--red);   margin-top: 8px; }
.score-actions { display: flex; flex-direction: column; gap: 8px; }

/* ═══ LEADERBOARD ═══════════════════════════════ */
.leaderboard-wrap {
  width: 100%; max-width: 560px;
  padding: 20px 16px;
  padding-top:    calc(20px + var(--safe-t));
  padding-bottom: calc(20px + var(--safe-b));
  max-height: 100vh; overflow-y: auto;
}
.lb-title { font-size: clamp(12px, 3.5vw, 16px); color: var(--yellow); text-shadow: 0 0 16px var(--yellow); text-align: center; margin-bottom: 20px; }
.lb-table { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; margin-bottom: 16px; overflow: hidden; }
.lb-row   { display: grid; grid-template-columns: 32px 1fr 88px 44px; padding: 10px 12px; font-size: 8px; border-bottom: 1px solid var(--border); align-items: center; gap: 6px; }
.lb-row:last-child { border: none; }
.lb-row.header { background: #0c0c20; color: var(--dim); font-size: 7px; letter-spacing: 1px; }
.lb-row.gold   { color: var(--yellow); }
.lb-row.silver { color: #c0c0c0; }
.lb-row.bronze { color: #cd7f32; }
.lb-rank  { text-align: center; }
.lb-name  { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { text-align: right; color: var(--cyan); text-shadow: 0 0 6px var(--cyan); }
.lb-level { text-align: right; color: var(--dim); }
.lb-empty { padding: 32px; text-align: center; font-size: 8px; color: var(--dim); }

/* ─── Utility ─── */
.hidden { display: none !important; }
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ═══ DESKTOP (≥ 700px) ═════════════════════════ */
@media (min-width: 700px) {
  /* Hide mobile-only elements — !important to prevent any override */
  .m-topbar { display: none !important; }
  .m-ctrl   { display: none !important; }

  /* Show desktop side panels */
  .side-panel {
    display: flex; flex-direction: column;
    gap: 8px; width: 120px; flex-shrink: 0;
  }
  .info-box { background: var(--panel); border: 1px solid var(--border); border-radius: 2px; padding: 8px 10px; }
  .info-label { font-size: 7px; color: var(--dim); letter-spacing: 1px; margin-bottom: 6px; }
  .info-value { font-size: 13px; color: var(--cyan); text-shadow: 0 0 10px var(--cyan); word-break: break-all; line-height: 1.4; }
  .info-value.small { font-size: 9px; color: var(--white); text-shadow: none; }
  .hold-box canvas, .next-box canvas { display: block; margin: 0 auto; }
  .keys-list { font-size: 6px; color: var(--dim); line-height: 2.2; }
  .keys-list span { color: var(--white); }

  #screen-game { justify-content: center; }

  .game-layout {
    flex-direction: row; flex: unset;
    align-items: flex-start; gap: 12px; padding: 12px;
  }
  .board-area { height: auto; }
  #canvas-board { width: 300px !important; height: 600px !important; }

  /* Desktop control buttons row */
  .d-ctrl {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    width: 100%;
    max-width: 552px; /* 300 board + 2×120 panels + 2×12 gaps */
    padding: 0 12px;
  }
  .dc-row {
    display: flex;
    gap: 6px;
  }
  .dc-btn {
    font-family: var(--font);
    font-size: 8px;
    letter-spacing: .5px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--white);
    cursor: pointer;
    padding: 0;
    height: 36px;
    flex: 1;
    display: flex; align-items: center; justify-content: center;
    touch-action: manipulation;
    transition: background .1s, border-color .1s, box-shadow .1s, transform .07s;
  }
  .dc-btn:hover  { background: #161630; border-color: #2a2a4a; }
  .dc-btn:active { transform: scale(.95); }

  .dc-hold   { color: var(--orange); border-color: rgba(255,109,0,.35); }
  .dc-hold:hover   { border-color: var(--orange); box-shadow: 0 0 10px rgba(255,109,0,.3); }
  .dc-hold:active  { border-color: var(--orange); }

  .dc-rotate { color: var(--green);  border-color: rgba(0,255,65,.35); }
  .dc-rotate:hover  { border-color: var(--green);  box-shadow: 0 0 10px rgba(0,255,65,.3); }

  .dc-pause  { color: var(--dim); }
  .dc-pause:hover  { color: var(--white); }

  .dc-left, .dc-right { font-size: 16px; flex: 0 0 52px; }
  .dc-down  { color: var(--yellow); border-color: rgba(255,230,0,.35); flex: 1; }
  .dc-down:hover  { border-color: var(--yellow); box-shadow: 0 0 10px rgba(255,230,0,.3); }

  .dc-drop {
    flex: 2;
    background: rgba(0,245,255,.07);
    border-color: rgba(0,245,255,.3);
    color: var(--cyan);
  }
  .dc-drop:hover  { background: rgba(0,245,255,.14); border-color: var(--cyan); box-shadow: 0 0 12px rgba(0,245,255,.3); }
}
