/* Tetris-specific styles. shared/styles.css carries tokens + base + components.
   Piece colors are softened versions of the classic set so they sit with the
   media house palette; the canvas reads them from these custom properties. */

:root {
  --game: #7C9BE0;
  --game-ink: #1a1817;

  --tx-I: #5FB8C9;
  --tx-O: #E7C25E;
  --tx-T: #B08CC9;
  --tx-S: #8FBF7F;
  --tx-Z: #E2897E;
  --tx-J: #7EA6C8;
  --tx-L: #E0A060;
  --tx-board: #ffffff;
  --tx-grid: rgba(20, 18, 16, 0.10);
  --tx-board-edge: var(--line);
  --tx-dim: rgba(251, 250, 247, 0.62);
  --tx-flash: rgba(255, 255, 255, 0.9);
  --tx-ghost-alpha: 0.45;
}

:root.dark {
  --tx-I: #4FA4B5;
  --tx-O: #D2AE4C;
  --tx-T: #9E7BB8;
  --tx-S: #7DAA6E;
  --tx-Z: #CC786E;
  --tx-J: #6E95B8;
  --tx-L: #CB8F50;
  --tx-board: #1c1e24;
  --tx-grid: rgba(255, 255, 255, 0.06);
  --tx-board-edge: transparent;
  --tx-dim: rgba(0, 0, 0, 0.4);
  --tx-flash: rgba(255, 255, 255, 0.75);
  --tx-ghost-alpha: 0.5;
}

main.tx {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Sound toggle shows one of two icons depending on state. */
#sound-btn .tx-snd-off { display: none; }
#sound-btn[aria-pressed="false"] .tx-snd-on { display: none; }
#sound-btn[aria-pressed="false"] .tx-snd-off { display: block; }
#sound-btn[aria-pressed="false"] { color: var(--ink-muted); }

/* ---------- Layout ---------- */

.tx-layout {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) 128px;
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "hold  board next"
    "keys  board stats"
    "keys  board .";
  gap: 14px;
  align-items: start;
  justify-content: center;
}

.tx-hold  { grid-area: hold; }
.tx-next  { grid-area: next; }
.tx-stats { grid-area: stats; }
.tx-keys  { grid-area: keys; }
.tx-board-wrap { grid-area: board; }

.tx-board-wrap {
  position: relative;
  width: min(100%, calc((100vh - 220px) / 2));
  aspect-ratio: 1 / 2;
  margin: 0 auto;
  justify-self: center;
}

.tx-board {
  display: block;
  border-radius: 10px;
  box-shadow: 0 0 0 1px var(--tx-board-edge), var(--shadow-sm);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Line-clear callout, centred over the board. */
.tx-clear-msg {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.9);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tx-clear-msg.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* "Play again" sits on the dimmed board once the end dialog is closed. */
.tx-over-btn {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: none;
  box-shadow: var(--shadow-md);
}
body.is-over .tx-over-btn { display: inline-flex; }

/* ---------- Side panels ---------- */

.tx-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tx-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
  align-self: flex-start;
}

.tx-preview { display: block; }

.tx-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  position: relative;
}
.tx-stat { display: flex; flex-direction: column; gap: 2px; }
.tx-value {
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.tx-value-big { font-size: 24px; }
.tx-pause { position: absolute; top: 8px; right: 8px; }
.tx-pause:disabled { opacity: 0.35; cursor: default; }

/* ---------- Keyboard hints (desktop) ---------- */

.tx-keys {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--ink-muted);
  padding: 4px 2px;
}
.tx-key-row { display: flex; align-items: center; gap: 4px; }
.tx-key-row > span:last-child { margin-left: 4px; }
.tx-kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 var(--line);
  font-family: var(--font-num);
  font-size: 11px;
  color: var(--ink);
}
.tx-kbd-wide { font-size: 10px; }

/* ---------- Touch controls ---------- */

.tx-touch {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 360px;
  width: 100%;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}
.tx-tbtn {
  height: 54px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 80ms ease, transform 60ms ease;
}
.tx-tbtn svg { width: 24px; height: 24px; }
.tx-tbtn:active { background: var(--surface-sunken); transform: scale(0.96); }
.tx-tbtn-primary { background: var(--game); color: var(--game-ink); border-color: transparent; }
.tx-tbtn-primary:active { background: var(--game); opacity: 0.9; }

@media (pointer: coarse) {
  .tx-touch { display: grid; }
  .tx-keys { display: none; }
}

/* ---------- Stats modal ---------- */

.tx-stats-note { margin-top: 12px; margin-bottom: 0; text-align: center; }

/* ---------- Narrow screens ---------- */

@media (max-width: 600px) {
  main.tx { padding: 12px 12px 22px; gap: 12px; }
  .tx-layout {
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "hold  next"
      "stats stats"
      "board board";
    gap: 10px;
  }
  .tx-keys { display: none; }
  .tx-hold, .tx-next { padding: 8px 10px 6px; }
  .tx-next { align-items: flex-start; }
  .tx-board-wrap {
    width: min(100%, calc((100vh - 330px) / 2));
    min-width: 200px;
  }
  .tx-stats {
    flex-direction: row;
    align-items: flex-end;
    gap: 14px;
    padding: 8px 40px 8px 12px;
  }
  .tx-stat { flex: 1; }
  .tx-stats .tx-label { white-space: nowrap; font-size: 10px; }
  .tx-value { font-size: 16px; }
  .tx-value-big { font-size: 20px; }
  .tx-pause { top: 50%; transform: translateY(-50%); }
}
