/* Gem Match. The board is a square; app.js sizes it (--side on .frame, shared/fit.js) to the room .board-wrap is given.
   Upright screens: the counters in a row above the board.
   Desktop: the score and the moves or time on one side of the board, the best score and the kind of game on the other.
   A sideways phone: all of them in one column beside the board. */
.stage { --edge: 8px; flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px max(var(--edge), var(--gk-safe-end)) max(var(--edge), var(--gk-safe-bottom)) max(var(--edge), var(--gk-safe-start)); }
.hud { flex: none; max-width: 100%; display: flex; align-items: stretch; justify-content: center; gap: 8px; }
/* The counters stand above the board's shadow. */
.stats, .record { position: relative; z-index: var(--gk-z-stage); display: flex; align-items: stretch; gap: 8px; min-width: 0; }
.hud .gk-stat { justify-content: center; min-width: 78px; padding: 4px 10px; }
/* The kind of game and the level being played. In a narrow column it takes two lines rather than being cut short. */
#mode { align-self: center; max-width: 100%; text-align: center; white-space: normal; line-height: var(--gk-tight); }
/* How much of the moves or the time is left. Only its transform changes. */
.meter { display: block; width: 100%; min-width: 64px; height: 5px; margin: 3px 0 2px; border-radius: var(--gk-r-pill); background: var(--gk-line); overflow: hidden; direction: ltr; }
.meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--gk-gold-warm), var(--gk-gold-pale)); transform-origin: 0 50%; transition: transform var(--gk-move) linear; }
.meter i.low { background: linear-gradient(90deg, var(--gk-leave), var(--gk-bad)); }

/* The wrap takes all the room the layout leaves; the frame is the largest square that fits it, up to 720px. */
.board-wrap { flex: 1; min-width: 0; min-height: 0; width: 100%; display: grid; place-items: center; }
.frame {
  --side: 280px; position: relative; flex: none; width: var(--side); height: var(--side);
  padding: clamp(4px, calc(var(--side) * .014), 10px); border-radius: var(--gk-r-lg);
  background: linear-gradient(145deg, var(--gk-gold-pale), var(--gk-gold-deep) 42%, var(--gk-on-gold-soft)); border: 1px solid var(--gk-gold-edge);
  box-shadow: 0 0 0 3px var(--gk-rim), var(--gk-shadow-2), inset 0 1px 0 var(--gk-shine), inset 0 -2px 0 var(--gk-dark);
}
/* Navy squares in two shades. The cells themselves stay clear, so a gem that slides over its neighbour is never covered. */
.board {
  width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr));
  direction: ltr; overflow: hidden; border-radius: var(--gk-r-md); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background: var(--gk-room); background: repeating-conic-gradient(var(--gk-panel-deep) 0 25%, var(--gk-well) 0 50%) 0 0 / 25% 25% var(--gk-room);
  box-shadow: inset 0 0 0 1px var(--gk-night);
}
.board.done { opacity: .8; }
.cell { position: relative; min-width: 0; min-height: 0; border-radius: 18%; cursor: pointer; }
.cell:focus { outline: none; }
.cell:focus-visible { outline: var(--gk-focus); outline-offset: -3px; }
.cell.picked { background: color-mix(in srgb, var(--gk-gold) 19%, transparent); box-shadow: inset 0 0 0 2px var(--gk-gold); }

/* A gem is as large as its square, so moving it by 100% is exactly one square; app.js moves it, and only it.
   The picture inside is the part that CSS styles and pulses; art.js draws it, colours and all, in the set the player wears. */
.gem { position: absolute; inset: 0; display: block; pointer-events: none; }
.gem.none { visibility: hidden; }
/* Behind the New game pop-up on arrival the table is empty. */
html.gk-clear #board .gem { visibility: hidden; }
.art { position: absolute; inset: 8%; width: 84%; height: 84%; overflow: visible; transition: transform var(--gk-fast); }
.cell.picked .art { transform: scale(1.12); }
.cell.hint .art { animation: gem-hint .8s ease-in-out infinite alternate; }
@keyframes gem-hint { to { transform: scale(1.2); } }
/* Only under a mouse (app.js marks the board): on a touch screen the last gem touched would stay enlarged. */
.board.mouse .cell:hover .art { transform: scale(1.06); }
.board.mouse .cell.picked:hover .art { transform: scale(1.12); }

/* Special gems. A beam carries a bright bar along the line it clears, a burst sits in a bright ring, a prism has every colour. */
.mark { display: none; position: absolute; pointer-events: none; }
.gem.row .mark, .gem.col .mark { display: block; inset: 40% 2%; border-radius: var(--gk-r-pill); background: linear-gradient(90deg, transparent, var(--gk-white) 20%, var(--gk-white) 80%, transparent); box-shadow: 0 0 7px 1px color-mix(in srgb, var(--gk-white) 80%, transparent); animation: gem-glow .9s ease-in-out infinite alternate; }
.gem.col .mark { transform: rotate(90deg); }
@keyframes gem-glow { from { opacity: .5; } }
.gem.burst .art { inset: 17%; width: 66%; height: 66%; }
.gem.burst .mark { display: block; inset: 3%; border-radius: 50%; border: clamp(2px, calc(var(--side) * .007), 4px) solid var(--gk-white); box-shadow: 0 0 8px 1px color-mix(in srgb, var(--gk-white) 80%, transparent), inset 0 0 8px 1px color-mix(in srgb, var(--gk-white) 60%, transparent); animation: gem-ring .9s ease-in-out infinite alternate; }
@keyframes gem-ring { from { transform: scale(.86); opacity: .55; } }
.gem.prism .art { inset: 5%; width: 90%; height: 90%; animation: gem-turn 8s linear infinite; }
@keyframes gem-turn { to { transform: rotate(1turn); } }

/* "×2", "×3" over the board while a chain runs. */
.chain { position: absolute; left: 50%; top: 50%; z-index: 3; translate: -50% -50%; opacity: 0; pointer-events: none; direction: ltr; color: var(--gk-white); white-space: nowrap;
  font: var(--gk-number) clamp(40px, calc(var(--side) * .15), 96px)/1 var(--gk-font); text-shadow: 0 3px 0 var(--gk-on-gold-soft), 0 0 22px var(--gk-gold), 0 6px 18px var(--gk-dark); }
#gem-art { position: absolute; width: 0; height: 0; overflow: hidden; }

/* A phone: the counters only. */
@media (max-width: 599px) { #mode { display: none; } }
/* A tablet: a larger row above the board. */
@media (min-width: 600px) and (max-width: 1023px) { .stage { --edge: 12px; gap: 14px; padding-top: 14px; } .hud, .stats, .record { gap: 12px; } .hud .gk-stat { min-width: 96px; padding: 6px 14px; } }
/* Desktop: the board takes the height, with a column on each side of it. */
@media (min-width: 1024px) {
  .stage { --edge: 12px; flex-direction: row; justify-content: center; gap: 22px; padding-top: 14px; }
  .hud { display: contents; }
  .stats, .record { flex: none; width: 148px; flex-direction: column; gap: 12px; }
  .stats { order: 1; } .record { order: 3; }
  .board-wrap { order: 2; flex: 0 1 auto; width: auto; height: 100%; max-height: 720px; aspect-ratio: 1; }
  .hud .gk-stat { padding: 8px 12px; } .hud .gk-stat b { font-size: var(--gk-text-xl); }
}
/* A sideways phone: one column of counters beside the board. */
@media (orientation: landscape) and (max-height: 560px) {
  .stage { --edge: 10px; display: grid; grid-template-columns: 124px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 10px; padding-top: 6px; padding-bottom: max(6px, var(--gk-safe-bottom)); }
  .hud { display: flex; flex-direction: column; gap: 6px; }
  .stats, .record { order: 0; width: auto; flex-direction: column; gap: 6px; }
  .board-wrap { order: 0; width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }
  .hud .gk-stat { min-width: 0; padding: 3px 8px; } .hud .gk-stat b { font-size: var(--gk-text-lg); }
}
/* Without movement a possible move is marked by a still ring instead of a pulse. */
@media (prefers-reduced-motion: reduce) { .cell.hint { box-shadow: inset 0 0 0 2px var(--gk-gold-pale); } }
