/* ============================================================
   TETRIS Nº 01 — édition web
   Direction : éditorial / brutalisme suisse
   Palette : papier crème, encre noire, vermillon
   ============================================================ */

:root {
  --paper: #EBE5D6;
  --paper-dim: #DCD4BF;
  --paper-edge: #C9C0A8;
  --ink: #0A0A0A;
  --ink-soft: #5C5C5C;
  --accent: #DE3517;
  --board-bg: #0A0A0A;
  --grid-line: #1A1A1A;
  --rule: 2px solid var(--ink);
  --radius: 0px;
  --space: 16px;
}

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

/* Force hidden attribute to actually hide, beats component display rules. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* Grain papier subtil via SVG inline */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.04 0 0 0 0 0.04 0 0 0 0 0.04 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

button { font-family: inherit; cursor: pointer; }

/* ============== LAYOUT FRAME ============== */

.frame {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(12px, 3vw, 24px);
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space);
  min-height: 100%;
}

/* ============== MASTHEAD ============== */

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--ink);
}

.wordmark {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: clamp(40px, 11vw, 72px);
  line-height: 0.85;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.dateline {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}
.dateline__num { color: var(--accent); font-weight: 700; }
.dateline__sep { opacity: 0.5; }

.icon-btn {
  background: var(--ink);
  color: var(--paper);
  border: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-family: 'Unbounded', sans-serif;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
}
.icon-btn:active { transform: scale(0.94); }

.icon-btn--small {
  width: 36px;
  height: 36px;
  font-size: 16px;
  background: var(--paper-dim);
  color: var(--ink);
  border: 2px solid var(--ink);
}
.icon-btn--small[data-on="false"] {
  opacity: 0.35;
  text-decoration: line-through;
}
.icon-btn--small[data-on="true"]:hover { background: var(--accent); color: var(--paper); }

.masthead__right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ============== STATS ============== */

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border: var(--rule);
  background: var(--paper-dim);
}

.stat {
  padding: 14px 14px;
  border-right: var(--rule);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat:last-child { border-right: none; }

.stat__label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
}
.stat__value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: clamp(18px, 5vw, 24px);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ============== PLAY AREA ============== */

.play {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space);
  align-items: start;
}

.board-wrap {
  position: relative;
  border: var(--rule);
  background: var(--board-bg);
  /* Petit décalage style "tirage" */
  box-shadow: 6px 6px 0 var(--ink);
}

#board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 10 / 20;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: clamp(110px, 22vw, 150px);
}

.card {
  border: var(--rule);
  padding: 10px;
  background: var(--paper-dim);
}
.card__label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.card__value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
#next {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: var(--board-bg);
}

.card--keys { display: none; } /* mobile-first : caché */

.keys {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 10px;
}
.keys li {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.keys kbd {
  display: inline-block;
  padding: 2px 5px;
  background: var(--paper);
  border: 1px solid var(--ink);
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  text-align: center;
}
.keys span {
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ============== TOUCH CONTROLS ============== */

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

.touch-btn {
  background: var(--paper-dim);
  border: var(--rule);
  height: clamp(56px, 14vw, 70px);
  font-family: 'Unbounded', sans-serif;
  font-weight: 800;
  font-size: 24px;
  color: var(--ink);
  transition: transform 0.06s ease, background 0.1s ease;
}

.touch-btn:active {
  transform: scale(0.94);
  background: var(--ink);
  color: var(--paper);
}

.touch-btn--accent {
  background: var(--accent);
  color: var(--paper);
  border-color: var(--ink);
}
.touch-btn--accent:active {
  background: var(--ink);
}

/* ============== OVERLAY (pause / game over) ============== */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 10, 0.92);
  display: grid;
  place-items: center;
  padding: 20px;
}

.overlay__inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.overlay__title {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 7vw, 42px);
  color: var(--paper);
  letter-spacing: 0.04em;
}

.overlay__sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: rgba(235, 229, 214, 0.6);
}

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

.btn-primary, .btn-ghost {
  font-family: 'Unbounded', sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 14px 22px;
  border: 2px solid var(--paper);
  background: var(--paper);
  color: var(--ink);
}
.btn-primary { background: var(--accent); color: var(--paper); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--paper); }
.btn-primary:active, .btn-ghost:active { transform: scale(0.96); }

.name-input {
  margin-top: 12px;
  background: transparent;
  border: 2px solid var(--paper);
  padding: 10px 14px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--paper);
  font-size: 14px;
  text-align: center;
  width: min(220px, 90%);
}
.name-input::placeholder { color: rgba(235, 229, 214, 0.4); }

/* ============== LEADERBOARD ============== */

.leaderboard {
  border-top: 4px solid var(--ink);
  padding-top: 16px;
}

.leaderboard__title {
  font-family: 'Unbounded', sans-serif;
  font-weight: 800;
  font-size: 18px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}

.leaderboard__list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.leaderboard__list li {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: baseline;
  gap: 12px;
  padding: 10px 4px;
  border-bottom: 1px dashed rgba(10, 10, 10, 0.2);
  font-variant-numeric: tabular-nums;
}

.lb__rank {
  font-family: 'Unbounded', sans-serif;
  font-weight: 800;
  font-size: 16px;
  color: var(--ink-soft);
}
.lb__rank--top { color: var(--accent); }
.lb__name { font-weight: 500; }
.lb__meta { font-size: 11px; color: var(--ink-soft); }
.lb__score {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  font-size: 16px;
}
.leaderboard__empty {
  display: block !important;
  color: var(--ink-soft);
  font-style: italic;
  padding: 12px 4px;
  border: none;
  text-align: center;
}

/* ============== COLOPHON ============== */

.colophon {
  text-align: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  padding-top: 8px;
  border-top: 1px solid rgba(10, 10, 10, 0.2);
}

/* ============== RESPONSIVE > 720px ============== */

@media (min-width: 720px) {
  .card--keys { display: block; }
  .touch-controls { display: none; }
}

@media (hover: hover) {
  .touch-btn:hover { background: var(--paper-edge); }
  .touch-btn--accent:hover { background: var(--ink); }
  .icon-btn:hover { background: var(--accent); }
}

/* ============== ANIMATIONS ============== */

@keyframes flash {
  0%, 100% { background: var(--paper-dim); }
  50% { background: var(--accent); color: var(--paper); }
}
.stat--flash .stat__value { animation: flash 0.4s ease; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.paused #board { animation: pulse 1.2s ease infinite; }

/* Flash blanc bref sur line clear simple */
@keyframes line-flash {
  0%   { box-shadow: 6px 6px 0 var(--ink), 0 0 0 0 rgba(255,255,255,0); }
  20%  { box-shadow: 6px 6px 0 var(--ink), 0 0 0 6px rgba(255,255,255,0.85); }
  100% { box-shadow: 6px 6px 0 var(--ink), 0 0 0 0 rgba(255,255,255,0); }
}
.board-wrap.flash {
  animation: line-flash 0.25s ease-out;
}

/* Flash spécial TETRIS — vermillon, plus long, plus fort */
@keyframes tetris-flash {
  0%   { box-shadow: 6px 6px 0 var(--ink), 0 0 0 0 var(--accent); transform: translate(0, 0); }
  10%  { box-shadow: 6px 6px 0 var(--ink), 0 0 0 12px var(--accent); transform: translate(-3px, 0); }
  20%  { transform: translate(3px, 0); }
  30%  { transform: translate(-2px, 0); }
  40%  { transform: translate(2px, 0); }
  50%  { box-shadow: 6px 6px 0 var(--ink), 0 0 0 8px var(--accent); transform: translate(0, 0); }
  100% { box-shadow: 6px 6px 0 var(--ink), 0 0 0 0 var(--accent); }
}
.board-wrap.flash--tetris {
  animation: tetris-flash 0.6s ease-out;
}
