/*--------------------------------------------------------------
# Tetris page
# Reuses .calc-card / .search-button / .reset-button /
# .result-unit-toggle / .unit-tab / .calc-error / .presets-panel /
# .presets-header / .presets-title / .file-count / .action-row /
# .calc-field / .input-unit-wrap / .field-help from style.css.
--------------------------------------------------------------*/
.tt2-section { padding: 60px 0; }

/* Narrow card vs the default 900px from .calc-card. The playfield (canvas +
   side panels) is intrinsically narrow, so a wide card leaves a lot of
   awkward dead space around it. Keep the result/leaderboard panels in step. */
.t-card { padding: 28px 32px 32px; max-width: 680px; }
.t-result-card,
.t-leaderboard { max-width: 680px; }

.t-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid #eef0f2;
}
.t-stats { display: flex; gap: 28px; flex-wrap: wrap; }
.t-stat  { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.t-stat-label {
  font-size: 11px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 4px;
}
.t-stat-value {
  font-family: "Poppins", sans-serif; font-size: 28px; font-weight: 700;
  color: #45505b; font-variant-numeric: tabular-nums; transition: color 0.2s;
}
.t-stat-value.is-running { color: #0563bb; }
.t-stat-value.is-pulse  { animation: t-pulse 0.35s ease; }
@keyframes t-pulse {
  0% { transform: scale(1); color: #28a745; }
  60% { transform: scale(1.15); color: #28a745; }
  100% { transform: scale(1); }
}

/* Playfield layout */
.t-playfield {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: center;
}
.t-stage {
  position: relative;
  flex: 0 0 auto;
}
.t-stage canvas {
  display: block;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 10px;
  /* Always 1:2 so JS square-cell maths stays exact.
     Cap at 500 px tall so the board fits on a typical laptop without
     scrolling (250px wide × 500px tall = 10-col × 20-row at 25px/cell). */
  aspect-ratio: 1 / 2;
  height: min(500px, 58vh);
  width: auto;
}

/* Sidebar — fixed width so it never steals flex space from the canvas.
   align-self: flex-start stops it stretching to the canvas height. */
.t-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 0 0 150px;
  width: 150px;
  align-self: flex-start;
}
.t-side-block {
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 10px;
  padding: 12px;
}
.t-side-label {
  font-size: 11px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.t-side-block canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}
.t-keylist {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  color: #45505b;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.t-keylist li { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.t-keylist kbd, .t-overlay-sub kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid #d6dde5;
  background: #fff;
  color: #45505b;
  font-family: 'SFMono-Regular', Consolas, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  box-shadow: 0 1px 0 #d6dde5;
}

/* Overlay */
.t-overlay {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(248, 250, 253, 0.94);
  backdrop-filter: blur(2px);
  border-radius: 10px;
}
.t-overlay[hidden] { display: none; }
.t-overlay-card { text-align: center; padding: 20px 24px; max-width: 280px; }
.t-overlay-title {
  font-family: "Poppins", sans-serif; font-size: 24px; font-weight: 700;
  color: #45505b; margin-bottom: 4px;
}
.t-overlay-sub { font-size: 13px; color: #6c757d; margin-bottom: 14px; }
.hint-mobile { display: none; }
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
  .hint-desktop { display: none; }
  .hint-mobile  { display: inline; }
}

/* Touch pad (mobile only) */
.t-touchpad {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.t-tb {
  appearance: none;
  border: 1px solid #d6dde5;
  background: linear-gradient(180deg, #fff, #eef2f6);
  color: #45505b;
  border-radius: 10px;
  padding: 14px 0;
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s, background 0.1s;
}
.t-tb:active {
  transform: scale(0.96);
  background: linear-gradient(180deg, #e4eaf1, #d6dde5);
}

/* ── Result card ───────────────────────────────────────────────── */
.t-result-card { margin-top: 24px; }
.t-result-body { padding: 26px 28px 28px; }
.t-result-stats {
  display: flex; justify-content: center; gap: 28px; flex-wrap: wrap;
  padding-bottom: 22px; margin-bottom: 22px;
  border-bottom: 1px solid #eef0f2;
}
.t-result-stat {
  display: flex; flex-direction: column; align-items: center;
  background: #f8fafd; border: 1px solid #e4eaf1; border-radius: 10px;
  padding: 20px 28px; min-width: 120px;
}
.t-result-num {
  font-family: "Poppins", sans-serif; font-size: 32px; font-weight: 700;
  color: #0563bb; font-variant-numeric: tabular-nums;
}
.t-result-label {
  font-size: 12px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px; margin-top: 4px;
}
.t-submit-form { max-width: 520px; margin: 0 auto; }
.t-submit-status {
  margin-top: 14px; padding: 10px 14px; border-radius: 6px;
  font-size: 14px; text-align: center;
}
.t-submit-status.is-success { background: #e8f5ee; color: #146c2e; border-left: 4px solid #28a745; }
.t-submit-status.is-error   { background: #fff3f3; color: #dc3545; border-left: 4px solid #dc3545; }
.t-btn-label, .t-btn-spinner { display: inline-flex; align-items: center; gap: 6px; }
.t-btn-spinner .bx { animation: t-spin 0.8s linear infinite; }
@keyframes t-spin { to { transform: rotate(360deg); } }
.search-button[aria-busy="true"] { pointer-events: none; opacity: 0.85; }

/* ── Leaderboard ───────────────────────────────────────────────── */
.t-leaderboard { margin-top: 24px; }
.t-lb-body { padding: 4px 0 8px; }
.t-lb-table { width: 100%; border-collapse: collapse; }
.t-lb-table thead th {
  font-size: 11px; font-weight: 700; color: #6c757d;
  text-transform: uppercase; letter-spacing: 0.6px;
  padding: 10px 24px; text-align: left;
  border-bottom: 1px solid #eef0f2;
}
.t-lb-table tbody td {
  padding: 12px 24px; font-size: 14px; color: #45505b;
  border-bottom: 1px solid #f1f4f8; vertical-align: middle;
}
.t-lb-table tbody tr:last-child td { border-bottom: none; }
.t-lb-table tbody tr.is-self { background: rgba(5, 99, 187, 0.06); font-weight: 600; }
.t-lb-rank { width: 48px; }
.t-lb-num  { width: 80px; text-align: right; font-variant-numeric: tabular-nums; }
.t-lb-date { width: 110px; color: #6c757d; font-size: 12px; }
.t-lb-empty { padding: 28px !important; text-align: center; color: #adb5bd; font-size: 14px; }
.t-lb-rank-medal {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  font-size: 12px; font-weight: 700; color: #fff;
}
.t-lb-rank-medal.r1 { background: #d4af37; }
.t-lb-rank-medal.r2 { background: #aab2bd; }
.t-lb-rank-medal.r3 { background: #cd7f32; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .t-playfield { flex-direction: column; align-items: center; }
  .t-sidebar {
    flex-direction: row;
    min-width: 0;
    width: 100%;
    max-width: 360px;
  }
  .t-side-block { flex: 1; }
  .t-side-controls { display: none; }
  .t-sidebar { flex: none; width: 100%; max-width: 360px; }
  .t-stage canvas { height: min(480px, 60vh); }
}
@media (max-width: 768px) {
  .t-card { padding: 22px 16px 26px; }
  .t-toolbar { gap: 14px; }
  .t-stats { gap: 18px; }
  .t-stat-value { font-size: 22px; }
  .t-result-body { padding: 22px 18px; }
  .t-result-stat { padding: 16px 20px; min-width: 0; flex: 1; }
  .t-result-num { font-size: 26px; }
  .t-touchpad { display: grid; }
  .t-lb-table thead th, .t-lb-table tbody td { padding: 10px 14px; }
  .t-lb-date { display: none; }
}
@media (max-width: 480px) {
  .t-result-stats { gap: 12px; }
  .t-lb-num { width: 60px; }
}
