/* ======================================= */
/* TETRIS - TOOLIFY STIJL                  */
/* ======================================= */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&family=Fredoka+One&display=swap');

:root {
  --bg:       #f0f4ff;
  --surface:  #ffffff;
  --surface2: #f8faff;
  --border:   #dde3f5;
  --text:     #2d3561;
  --text-muted: #7b84b0;

  --easy:   #22c55e;
  --medium: #f59e0b;
  --hard:   #ef4444;

  --blue:   #3b82f6;
  --purple: #8b5cf6;
  --pink:   #ec4899;
  --teal:   #14b8a6;
  --orange: #f97316;

  --shadow-sm: 0 2px 8px  rgba(59,82,246,0.08);
  --shadow-md: 0 6px 24px rgba(59,82,246,0.13);
  --shadow-lg: 0 12px 40px rgba(59,82,246,0.18);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-xl: 32px;

  /* Tetris block colours */
  --t-I: #06b6d4;
  --t-O: #eab308;
  --t-T: #a855f7;
  --t-S: #22c55e;
  --t-Z: #ef4444;
  --t-J: #3b82f6;
  --t-L: #f97316;
}

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 1.5rem 1rem 1rem;
  background-image:
    radial-gradient(circle at 10% 20%, rgba(139,92,246,0.08) 0%, transparent 50%),
    radial-gradient(circle at 90% 80%, rgba(6,182,212,0.08)  0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(236,72,153,0.04) 0%, transparent 60%);
  -webkit-tap-highlight-color: transparent;
}

/* ======================================= */
/* HEADER                                  */
/* ======================================= */
.game-header {
  text-align: center;
  margin-bottom: 1.2rem;
}

.game-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2.8rem;
  line-height: 1;
  background: linear-gradient(135deg, var(--blue), var(--purple), var(--pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 2px 8px rgba(139,92,246,0.2));
  margin-bottom: 0.3rem;
}

.game-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ======================================= */
/* DIFFICULTY PICKER                       */
/* ======================================= */
.difficulty-row {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
}

.diff-btn {
  font-family: 'Nunito', sans-serif;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0.45rem 1.2rem;
  border-radius: 999px;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: var(--shadow-sm);
}

.diff-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.diff-btn[data-diff="easy"]   { border-color: var(--easy); }
.diff-btn[data-diff="medium"] { border-color: var(--medium); }
.diff-btn[data-diff="hard"]   { border-color: var(--hard); }

.diff-btn[data-diff="easy"].active   { background: var(--easy);   color: #fff; }
.diff-btn[data-diff="medium"].active { background: var(--medium); color: #fff; }
.diff-btn[data-diff="hard"].active   { background: var(--hard);   color: #fff; }

/* ======================================= */
/* GAME LAYOUT                             */
/* ======================================= */
.game-layout {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: flex-start;
}

/* ======================================= */
/* SIDE PANELS                             */
/* ======================================= */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  width: 110px;
  flex-shrink: 0;
}

.info-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.info-label {
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.info-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  color: var(--text);
  line-height: 1;
}

.score-val { color: var(--purple); font-size: 1.3rem; }
.level-val { color: var(--orange); }

/* Next / Hold canvases */
.next-card canvas,
.hold-card canvas {
  display: block;
  margin: 0.3rem auto 0;
  border-radius: var(--radius-sm);
  max-width: 90px;
}

.hold-hint {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 0.25rem;
}

/* Mini highscores */
.hs-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  box-shadow: var(--shadow-sm);
}

.hs-mini {
  list-style: none;
  margin-top: 0.4rem;
}

.hs-mini li {
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
  border-bottom: 1px solid var(--border);
}

.hs-mini li:last-child { border-bottom: none; }
.hs-mini li span:first-child { color: var(--text-muted); }
.hs-mini li span:last-child  { color: var(--purple); font-family: 'Fredoka One', cursive; }

.hs-mini-empty {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.3rem 0;
}

/* Action buttons */
.action-btns {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.action-btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.82rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: all 0.18s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.action-btn:hover    { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.action-btn.new-btn  { border-color: #86efac; color: var(--easy); }
.action-btn.pause-btn { border-color: #93c5fd; color: var(--blue); }

/* ======================================= */
/* CANVAS WRAP                             */
/* ======================================= */
.canvas-wrap {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: var(--shadow-lg);
  border: 3px solid var(--border);
  display: inline-flex;
  flex-shrink: 0;
}

#tetris-canvas {
  display: block;
  border-radius: var(--radius-sm);
  background: #1a1e3a;
  touch-action: none;
}

/* Invisible touch overlay sits on top of canvas for gesture capture */
.touch-overlay {
  position: absolute;
  inset: 12px;
  border-radius: var(--radius-sm);
  z-index: 10;
  touch-action: none;
}

/* ======================================= */
/* MOBILE CONTROLS                         */
/* ======================================= */
.mobile-controls {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
  padding-bottom: 1.5rem;
}

.ctrl-row {
  display: flex;
  gap: 0.6rem;
}

.ctrl-btn {
  width: 62px;
  height: 62px;
  border-radius: var(--radius-md);
  border: 2.5px solid var(--border);
  background: var(--surface);
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.ctrl-btn:active {
  transform: scale(0.92);
  background: var(--surface2);
  box-shadow: var(--shadow-sm);
}

#btn-up    { border-color: var(--purple); }
#btn-hard  { border-color: var(--hard);   }
#btn-hold  { border-color: var(--teal);   }
#btn-left  { border-color: var(--blue);   }
#btn-right { border-color: var(--blue);   }
#btn-down  { border-color: var(--orange); }

/* ======================================= */
/* PAUSE OVERLAY                           */
/* ======================================= */
.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 30, 80, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.pause-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.pause-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 280px;
  width: 90%;
  animation: popIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

.pause-emoji { font-size: 3rem; display: block; margin-bottom: 0.5rem; }

.pause-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: var(--text);
  margin-bottom: 1.2rem;
}

/* ======================================= */
/* WIN / GAME OVER OVERLAY                 */
/* ======================================= */
.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 30, 80, 0.55);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.win-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.win-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  width: 90%;
  animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
}

.win-emoji { font-size: 3.5rem; display: block; margin-bottom: 0.5rem; }

.win-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  background: linear-gradient(135deg, var(--hard), var(--purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.3rem;
}

.win-sub {
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 1.2rem;
  margin: 1rem 0 1.5rem;
}

.win-stat { text-align: center; }

.win-stat-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.7rem;
  display: block;
  color: var(--purple);
}

.win-stat-lbl {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.win-play-btn {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  padding: 0.75rem 2rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99,102,241,0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

.win-play-btn:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 8px 24px rgba(99,102,241,0.45);
}

/* ======================================= */
/* LINE CLEAR FLASH                        */
/* ======================================= */
.line-flash {
  position: absolute;
  left: 12px; right: 12px;
  border-radius: 4px;
  background: rgba(255,255,255,0.85);
  pointer-events: none;
  animation: lineFlash 0.35s ease forwards;
}

@keyframes lineFlash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* ======================================= */
/* ANIMATIONS                              */
/* ======================================= */
@keyframes popIn {
  0%   { transform: scale(0.7) translateY(30px); opacity: 0; }
  100% { transform: scale(1)   translateY(0);    opacity: 1; }
}

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.game-header, .difficulty-row, .game-layout {
  animation: fadeSlideIn 0.4s ease both;
}
.difficulty-row { animation-delay: 0.05s; }
.game-layout    { animation-delay: 0.10s; }

/* ======================================= */
/* RESPONSIVE — TABLET                     */
/* ======================================= */
@media (max-width: 700px) {
  .side-panel { width: 88px; }
  .info-val { font-size: 1.25rem; }
  .score-val { font-size: 1.1rem; }
}

/* ======================================= */
/* RESPONSIVE — MOBILE                     */
/* Show on-screen controls, hide side info */
/* ======================================= */
@media (max-width: 520px) {
  body { padding: 1rem 0.5rem 0.5rem; }

  .game-title { font-size: 2rem; }

  .game-layout {
    gap: 0.5rem;
  }

  /* Compress side panels to icon columns */
  .side-panel {
    width: 70px;
    gap: 0.5rem;
  }

  .info-label { font-size: 0.6rem; }
  .info-val   { font-size: 1.1rem; }
  .score-val  { font-size: 0.95rem; }

  /* Hide hold card and hs on tiny screens — show only essentials */
  .hold-card, .hs-card { display: none; }

  /* Show mobile controls */
  .mobile-controls { display: flex; }

  /* Smaller action buttons */
  .action-btn { font-size: 0.75rem; padding: 0.4rem 0.4rem; }
}

@media (max-width: 380px) {
  .side-panel { width: 58px; }
  .info-card  { padding: 0.4rem 0.4rem; }
  .info-label { display: none; }
}
