/* ===================================================================
   TETRIS_WEB — mobile-game style design tokens
   =================================================================== */
:root {
  --panel-bg:        #fffaf1;
  --panel-bg-solid:  #fff3df;
  --field-bg:        #efe7ff;
  --field-line:      #e0d3ff;
  --ink:             #2d2250;
  --ink-dim:         #7a6f9c;

  --primary:         #ff5fa2;
  --primary-rgb:     255, 95, 162;
  --primary-dark:    #d63e80;

  --secondary:       #3fd4ff;
  --secondary-rgb:   63, 212, 255;
  --secondary-dark:  #1fa8cf;

  --gold:            #ffd23f;
  --gold-rgb:        255, 210, 63;
  --gold-dark:       #e0ac00;

  --success:         #2be38a;
  --danger:          #ff4d4d;
  --danger-dark:     #d32f2f;

  --radius-lg:       28px;
  --radius-md:       18px;
  --radius-sm:       12px;

  --font-display:    'Baloo 2', system-ui, sans-serif;
  --font-body:       'Nunito', system-ui, sans-serif;

  /* candy-gem piece colors */
  --p-i: #22e0ff;
  --p-o: #ffd400;
  --p-t: #c86bff;
  --p-s: #43e97b;
  --p-z: #ff4d6d;
  --p-j: #4d8dff;
  --p-l: #ff9d3d;

  --shadow-panel: 0 10px 0 rgba(45, 34, 80, 0.08), 0 16px 30px -10px rgba(45, 34, 80, 0.25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  overflow-x: hidden;
}

body {
  position: relative;
  background: #0d0a24;
}

body::before {
  content: '';
  position: fixed;
  inset: -60px;
  z-index: -1;
  background: url('../assets/fond.png') center / cover no-repeat;
  filter: blur(34px) saturate(1.2) brightness(0.6);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle at 50% 30%, rgba(10,8,30,0), rgba(6,10,28,0.5) 85%);
}

/* ---------- jungle corner foliage (kept as a soft depth layer under the cards) ---------- */
.jungle-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  display: none;
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.55) 3px, transparent 3px);
  background-size: 46px 46px;
  opacity: 0.12;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 16px;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.topbar   { animation: fadeUp 0.5s ease both; }
.panel-left  { animation: fadeUp 0.5s ease 0.08s both; }
.board-wrap  { animation: fadeUp 0.5s ease 0.16s both; }
.panel-right { animation: fadeUp 0.5s ease 0.24s both; }
.bottombar   { animation: fadeUp 0.5s ease 0.32s both; }

/* ===================================================================
   Header
   =================================================================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-block {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(0,0,0,0.18), inset 0 -2px 3px rgba(0,0,0,0.15), inset 0 2px 2px rgba(255,255,255,0.6);
}
.logo .b1 { background: var(--p-i); }
.logo .b2 { background: var(--p-t); }
.logo .b3 { background: var(--p-o); }
.logo .b4 { background: var(--p-z); }

.logo h1 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 27px;
  margin: 0;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #fff 0%, #fff 45%, #ffe9a8 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow:
    2px 2px 0 rgba(45,34,80,0.9),
    0 5px 0 rgba(45,34,80,0.35),
    0 10px 14px rgba(0,0,0,0.35);
}
.logo h1 span {
  background: linear-gradient(180deg, #ffe685 0%, var(--gold) 55%, var(--gold-dark) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ===================================================================
   Buttons — chunky mobile-game style
   =================================================================== */
.primary-btn, .ghost-btn {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  border-radius: 999px;
  padding: 13px 26px;
  cursor: pointer;
  border: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 6px 0 var(--primary-dark), 0 10px 18px -6px rgba(214, 62, 128, 0.55);
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--primary-dark), 0 4px 10px -4px rgba(214, 62, 128, 0.5);
}

.ghost-btn {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--field-line), 0 8px 16px -8px rgba(45,34,80,0.35);
}
.ghost-btn:hover { filter: brightness(1.03); }
.ghost-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--field-line);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 5px 0 var(--field-line), 0 8px 16px -8px rgba(45,34,80,0.35);
  transition: transform 0.1s ease, box-shadow 0.1s ease, filter 0.1s ease;
}
.icon-btn:hover { filter: brightness(1.03); }
.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 var(--field-line);
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===================================================================
   Layout
   =================================================================== */
.layout {
  display: grid;
  grid-template-columns: 190px auto 230px;
  gap: 20px;
  justify-content: center;
  align-items: start;
  flex: 1;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ===================================================================
   Stat cards / next piece
   =================================================================== */
.stat-card, .piece-card {
  position: relative;
  background: var(--panel-bg);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-panel);
  border: 3px solid #fff;
}
.stat-card {
  padding-left: 46px;
}

.stat-badge {
  position: absolute;
  top: -12px;
  left: -12px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(45,34,80,0.18), 0 6px 10px -3px rgba(45,34,80,0.4);
}
.stat-badge svg {
  width: 19px;
  height: 19px;
  fill: #fff;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
}
.badge-score { background: linear-gradient(160deg, #ff8fc0, var(--primary)); }
.badge-level { background: linear-gradient(160deg, #ffe685, var(--gold)); }
.badge-lines { background: linear-gradient(160deg, #7fe8ff, var(--secondary)); }

.stat-label {
  display: block;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-dim);
  margin-bottom: 4px;
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  color: var(--primary);
}

.piece-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

#next-canvas {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: var(--field-bg) url('../assets/board-texture.png') center / cover no-repeat;
  border-radius: var(--radius-sm);
  border: 2px dashed var(--field-line);
  margin-top: 6px;
}

/* ===================================================================
   Board
   =================================================================== */
.board-wrap {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 14px;
  background: var(--panel-bg);
  border: 48px solid transparent;
  border-image-source: url('../assets/fond.png');
  border-image-slice: 170 194 188 196;
  border-image-repeat: stretch;
  box-shadow: var(--shadow-panel), inset 0 0 0 4px rgba(255,255,255,0.55);
}

.board-stage {
  position: relative;
  width: 300px;
  height: 600px;
}

#game-canvas {
  display: block;
  width: 300px;
  height: 600px;
  background: var(--field-bg) url('../assets/board-texture.png') center / cover no-repeat;
  border-radius: var(--radius-md);
}

#fx-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 300px;
  height: 600px;
  pointer-events: none;
}

.fx-layer {
  position: absolute;
  inset: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
  pointer-events: none;
  z-index: 3;
}

.score-popup {
  position: absolute;
  left: 50%;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  color: var(--gold);
  text-shadow: 1px 1px 0 rgba(45,34,80,0.85), 0 4px 10px rgba(0,0,0,0.4);
  transform: translate(-50%, 0);
  animation: scorePop 0.9s ease-out forwards;
  white-space: nowrap;
}
@keyframes scorePop {
  0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.7); }
  20%  { opacity: 1; transform: translate(-50%, -6px) scale(1.08); }
  35%  { transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}

/* ===================================================================
   Overlays
   =================================================================== */
.overlay {
  position: absolute;
  inset: 10px;
  z-index: 4;
  border-radius: var(--radius-md);
  background: rgba(45, 34, 80, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease;
}
.overlay.hidden { display: none; }

.overlay-card {
  text-align: center;
  padding: 26px;
  background: var(--panel-bg);
  border-radius: var(--radius-md);
  border: 3px solid #fff;
  box-shadow: var(--shadow-panel);
}

.overlay-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 24px;
  color: var(--ink);
  margin: 0 0 14px;
  letter-spacing: 0.5px;
}

.overlay-sub {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-dim);
  line-height: 1.9;
  margin: 0 0 18px;
}

/* ===================================================================
   Right panel: leaderboard
   =================================================================== */
.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(45,34,80,0.35);
  letter-spacing: 0.5px;
  margin: 0 0 2px;
}
.title-icon {
  width: 20px;
  height: 20px;
  fill: var(--gold);
  filter: drop-shadow(0 2px 0 rgba(45,34,80,0.35));
}

.leaderboard {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--panel-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-panel);
  border: 3px solid #fff;
  max-height: 420px;
  overflow-y: auto;
  overflow-x: hidden;
}

.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 2px solid var(--field-line);
  font-size: 13px;
  font-weight: 700;
}
.leaderboard li:last-child { border-bottom: none; }

.leaderboard .rank {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--ink-dim);
  width: 20px;
  flex-shrink: 0;
  text-align: center;
}

.leaderboard .rank-medal {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 0 rgba(45,34,80,0.25), 0 3px 6px -2px rgba(45,34,80,0.4);
}
.rank-medal.rank-1 { background: linear-gradient(160deg, #ffe685, var(--gold-dark)); }
.rank-medal.rank-2 { background: linear-gradient(160deg, #eef1f8, #9a93b5); }
.rank-medal.rank-3 { background: linear-gradient(160deg, #ffc08a, var(--p-l)); }

.leaderboard .lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.leaderboard .lb-score {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--primary);
}

.leaderboard-empty {
  padding: 18px 14px;
  color: var(--ink-dim);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* ===================================================================
   Footer
   =================================================================== */
.bottombar {
  margin-top: 20px;
  text-align: center;
}

.controls-hint {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 0 rgba(45,34,80,0.3);
}

kbd {
  background: var(--panel-bg);
  color: var(--ink);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--field-line);
  padding: 3px 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
}

/* ===================================================================
   Modal (game over / name entry)
   =================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(45, 34, 80, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-card {
  width: 320px;
  background: var(--panel-bg);
  border-radius: var(--radius-lg);
  border: 4px solid #fff;
  padding: 28px 26px;
  box-shadow: var(--shadow-panel);
  text-align: center;
}

.modal-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  color: var(--danger);
  margin: 0 0 14px;
}

.modal-score {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-dim);
  margin: 0 0 6px;
}
.modal-score span {
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--primary);
}

.new-record {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--gold-dark);
  font-weight: 700;
  letter-spacing: 0.3px;
  margin: 0 0 14px;
}
.new-record.hidden { display: none; }

.modal-label {
  display: block;
  text-align: left;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-dim);
  margin: 18px 0 6px;
}

.modal-input {
  width: 100%;
  background: var(--field-bg);
  border: 2px solid var(--field-line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.12s ease;
}
.modal-input:focus { border-color: var(--secondary); }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.modal-actions .primary-btn,
.modal-actions .ghost-btn {
  flex: 1;
  padding: 13px 10px;
}

/* ===================================================================
   Responsive
   =================================================================== */
@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    justify-items: center;
  }
  .panel-left { flex-direction: row; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 300px; }
  .panel-left .stat-card { flex: 1; min-width: 84px; }
  .panel-left .piece-card { width: 100%; }
  .panel-right { width: 100%; max-width: 300px; }
}
