/* Merge Zen — widget-local styles. Widget chrome (HUD, arena base, overlays,
   score form, leaderboard) lives in ../../style.css. Here: the board, the
   tile tier ramp (light + dark variants — never hardcoded into JS), and the
   drag/keyboard affordances. */

:root {
  --mz-ink: #1c2a44;
  --mz-cell: rgba(27, 39, 64, 0.07);
  --mz-lift: rgba(27, 39, 64, 0.25);
  /* Tier ramp: gentle blue -> violet -> plum as the powers climb. */
  --mz-t1: #eef2f7;  --mz-t2: #e4ecf8;  --mz-t3: #d7e3f9;  --mz-t4: #c9d9fa;
  --mz-t5: #bbcefb;  --mz-t6: #aec2fb;  --mz-t7: #a8b4fa;  --mz-t8: #ada8f7;
  --mz-t9: #b89df2;  --mz-t10: #c493ec; --mz-t11: #cf8ae2; --mz-t12: #d981d3;
  --mz-t13: #e17ac0; --mz-t14: #e775ab; --mz-t15: #ec7196;
}

@media (prefers-color-scheme: dark) {
  :root {
    --mz-ink: #e9eef8;
    --mz-cell: rgba(255, 255, 255, 0.055);
    --mz-lift: rgba(0, 0, 0, 0.55);
    --mz-t1: #2b3446;  --mz-t2: #2d3a52;  --mz-t3: #2f4160;  --mz-t4: #31486f;
    --mz-t5: #334f7e;  --mz-t6: #36568c;  --mz-t7: #414f97;  --mz-t8: #4a4d9e;
    --mz-t9: #55489f;  --mz-t10: #61439e; --mz-t11: #6f3f99; --mz-t12: #7c3b90;
    --mz-t13: #883884; --mz-t14: #933577; --mz-t15: #9d3268;
  }
}

.arena-mz {
  height: auto;
  min-height: 0;
  padding: 16px;
  display: flex;
  justify-content: center;
  background: var(--surface);
}

/* touch-action: none on the board only — dragging tiles must not scroll the
   page, but everything around the board scrolls normally. */
.mz-board {
  position: relative;
  width: min(100%, 440px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 8px;
  touch-action: none;
  border-radius: 12px;
}

.mz-board:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 6px;
}

.mz-cell {
  background: var(--mz-cell);
  border-radius: 10px;
}

.mz-cell.open {
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

/* Tile = outer element that only translates (cheap to animate), inner .face
   that scales/flashes, so the two transforms never fight. */
.mz-tile {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  cursor: grab;
}

.mz-tile .face {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: 10px;
  font-weight: 800;
  color: var(--mz-ink);
  background: var(--mz-t1);
  box-shadow: 0 1px 3px rgba(27, 39, 64, 0.14);
}

.mz-tile.drag {
  z-index: 6;
  cursor: grabbing;
}

.mz-tile.drag .face {
  transform: scale(1.07);
  box-shadow: 0 10px 22px var(--mz-lift);
}

/* Merge target highlight while a tile is lifted. */
.mz-tile.mz-target .face {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.mz-v1 .face  { background: var(--mz-t1); }
.mz-v2 .face  { background: var(--mz-t2); }
.mz-v3 .face  { background: var(--mz-t3); }
.mz-v4 .face  { background: var(--mz-t4); }
.mz-v5 .face  { background: var(--mz-t5); }
.mz-v6 .face  { background: var(--mz-t6); }
.mz-v7 .face  { background: var(--mz-t7); }
.mz-v8 .face  { background: var(--mz-t8); }
.mz-v9 .face  { background: var(--mz-t9); }
.mz-v10 .face { background: var(--mz-t10); }
.mz-v11 .face { background: var(--mz-t11); }
.mz-v12 .face { background: var(--mz-t12); }
.mz-v13 .face { background: var(--mz-t13); }
.mz-v14 .face { background: var(--mz-t14); }
.mz-v15 .face { background: var(--mz-t15); }

@media (prefers-reduced-motion: no-preference) {
  .mz-tile {
    transition: transform 0.14s ease;
  }

  .mz-tile.drag {
    transition: none;
  }

  .face.pop {
    animation: mz-pop 0.2s ease-out;
  }

  .face.bump {
    animation: mz-bump 0.18s ease-out;
  }

  @keyframes mz-pop {
    from { transform: scale(0.45); opacity: 0.2; }
  }

  @keyframes mz-bump {
    45%  { transform: scale(1.16); }
    100% { transform: scale(1); }
  }
}

/* Reduced motion: positions jump, a brief opacity cue marks what changed. */
@media (prefers-reduced-motion: reduce) {
  .face.pop,
  .face.bump {
    animation: mz-fade 0.25s linear;
  }

  @keyframes mz-fade {
    from { opacity: 0.25; }
  }
}

/* Keyboard cursor: outlines the focused cell; .grab marks a held tile.
   Explicit left/top so this absolute child anchors to the board's origin
   instead of its auto-placed grid area. */
.mz-cursor {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 7;
  border: 3px solid var(--accent);
  border-radius: 12px;
  pointer-events: none;
  display: none;
}

.mz-cursor.show {
  display: block;
}

.mz-cursor.grab {
  border-style: dashed;
}

/* When the run ends, the results replace the board: a statically-positioned
   overlay sizes the arena to its own content, so nothing clips or scrolls
   inside a too-short box on phones (the absolute inset:0 overlay clipped —
   the arena is only as tall as the board). */
.arena-mz.ended {
  display: block;
}

.arena-mz.ended .mz-board {
  display: none;
}

.arena-mz.ended .overlay {
  position: static;
}

/* --- HUD extras ------------------------------------------------------------- */

.toolbar-spacer {
  flex: 1;
}

.btn-small {
  min-height: 44px;
  padding: 0 18px;
}

.hud .tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.hud .tool[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.hud .tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud .tool svg .fill {
  fill: currentColor;
  stroke: none;
}

#soundBtn .icon-when-on { display: none; }
#soundBtn[aria-pressed="true"] .icon-when-on { display: initial; }
#soundBtn[aria-pressed="true"] .icon-when-off { display: none; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
