/* Tetris. Loads after base.css, which supplies the tokens, reset, background and
   card chrome. The well and the two trays are canvases, so everything below is
   chrome. */

:root {
  --gap: 8px;
  --board-radius: 12px;
  /* The well drives the layout: its height is picked first and the 1:2 aspect
     ratio derives the width, so a short viewport shrinks the whole board rather
     than pushing the footer off screen. */
  --well-height: clamp(300px, 54vh, 520px);
  --side-width: 108px;
}

.card {
  max-width: 480px;
}

.card__body {
  padding: 26px 26px 22px;
}

.card__foot {
  padding: 13px 26px;
}

/* Header: title + scores */
.head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.title {
  position: relative;
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(2rem, 8vw, 2.9rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  background: linear-gradient(
    100deg,
    var(--accent-cyan) 0%,
    #818cf8 45%,
    var(--accent-violet) 100%
  );
  background-size: 200% auto;
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  animation:
    rise 700ms var(--ease-smooth) 120ms both,
    shimmer 8s linear infinite;
}

.scores {
  display: flex;
  gap: 8px;
  animation: fade-in 700ms var(--ease-smooth) 240ms both;
}

.score {
  position: relative;
  min-width: 74px;
  padding: 6px 10px 7px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
  text-align: center;
}

.score__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.4;
}

.score__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Floating "+800" that rises out of the score box on a clear */
.score__gain {
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent-lime);
  opacity: 0;
  pointer-events: none;
}

.score__gain--run {
  animation: gain 700ms var(--ease-smooth);
}

/* Hint line */
.hint {
  margin: 18px 0 14px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.03em;
  animation: fade-in 600ms var(--ease-smooth) 320ms both;
}

.hint__sigil {
  color: var(--accent-lime);
  margin-right: 8px;
}

.hint__touch { display: none; }

/* Coarse pointers get the swipe wording instead of the keyboard one. */
@media (hover: none) and (pointer: coarse) {
  .hint__desktop { display: none; }
  .hint__touch { display: inline; }
}

/* Playfield: the well plus the side column */
.play {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 12px;
  animation: rise 700ms var(--ease-smooth) 400ms both;
}

/* Padding is equal on all sides, so the canvas inside the border box keeps the
   1:2 ratio of the 10x20 grid it draws. */
.board {
  position: relative;
  flex: none;
  height: var(--well-height);
  aspect-ratio: 1 / 2;
  padding: var(--gap);
  border: 1px solid var(--border-color);
  border-radius: var(--board-radius);
  background: rgba(255, 255, 255, 0.025);
  /* Swipes must not scroll the page while the finger is on the well. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.board__canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Red wash on a top-out, held just long enough to be read before the overlay
   lands on top of it. */
.board--dead {
  animation: crash 320ms ease-out;
}

.side {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
  width: var(--side-width);
}

.tray {
  padding: 6px 8px 8px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
}

.tray__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.4;
}

.tray__canvas {
  display: block;
  width: 100%;
}

/* Three queued pieces stacked in one square-ish box... */
.tray__canvas--next { aspect-ratio: 2 / 3; }

/* ...against a single slot for the held one. */
.tray__canvas--hold { aspect-ratio: 2 / 1; }

.meters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.meter {
  padding: 5px 9px 6px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
}

.meter__label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  line-height: 1.4;
}

.meter__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  border-radius: var(--board-radius);
  background: rgba(5, 5, 7, 0.82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  text-align: center;
  animation: fade-in 320ms var(--ease-smooth) both;
}

.overlay[hidden] { display: none; }

.overlay__title {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(100deg, var(--accent-cyan), var(--accent-violet));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.overlay__text {
  margin: 0 0 12px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-secondary);
}

.overlay__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* Buttons */
.controls {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-chip);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition:
    color var(--duration-short) var(--ease-smooth),
    border-color var(--duration-short) var(--ease-smooth),
    background var(--duration-short) var(--ease-smooth);
}

.btn:hover:not(:disabled),
.btn:focus-visible {
  color: var(--accent-cyan);
  border-color: var(--border-hover);
  outline: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  color: var(--text-primary);
  border-color: rgba(34, 211, 238, 0.25);
  background: rgba(34, 211, 238, 0.1);
}

.btn[aria-pressed="true"] {
  color: var(--accent-lime);
  border-color: rgba(74, 222, 128, 0.35);
  background: rgba(74, 222, 128, 0.1);
}

/* Square glyph-only button, so it does not eat the row on a narrow phone. */
.btn--icon {
  flex: none;
  min-width: 46px;
  padding: 9px 0;
  font-size: 0.95rem;
}

.btn--icon[aria-pressed="false"] {
  color: var(--text-dim);
  text-decoration: line-through;
}

/* The well is narrow, so overlay buttons stack rather than sit side by side. */
.overlay .btn {
  flex: none;
  width: 100%;
  max-width: 150px;
}

/* Animation Keyframes */
@keyframes gain {
  0% { opacity: 0; transform: translateY(0); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-26px); }
}

@keyframes crash {
  0% {
    background: rgba(244, 63, 94, 0.3);
    border-color: rgba(244, 63, 94, 0.7);
  }
  100% {
    background: rgba(255, 255, 255, 0.025);
    border-color: var(--border-color);
  }
}

/* Responsive Design */
@media (max-width: 560px) {
  :root {
    --gap: 6px;
    --well-height: clamp(280px, 50vh, 460px);
    --side-width: 88px;
  }

  .stage { padding: 14px; }

  .card__body { padding: 20px 16px 18px; }

  .card__foot { padding: 12px 16px; }

  .hint { font-size: 0.68rem; }
}
