/* Mosaic: game-specific styles. The board, tray and pieces are drawn on the canvas;
   the mosaic progress pill and the panels' extras are DOM. */

#game {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none; /* the stage reads the pointer; the canvas only draws */
}

/* ---------- mosaic progress pill (sits just above the board) ---------- */
.mo-hud {
  position: absolute;
  z-index: 1;
  top: 0; left: 0;
  display: flex;
  align-items: center;
}
.mo-prog {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 14px 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(17, 30, 90, 0.6);
  box-shadow: inset 0 0 0 1px var(--hairline);
  color: var(--parchment);
  font: inherit;
  text-align: start;
  cursor: pointer;
  touch-action: manipulation;
  transition: box-shadow 0.3s var(--ease-out), background-color 0.2s linear;
}
.mo-prog:active { background: rgba(17, 30, 90, 0.85); }
@media (hover: hover) { .mo-prog:hover { box-shadow: inset 0 0 0 1px rgba(232, 182, 90, 0.5); } }
.mo-prog__icon { flex: none; width: 18px; height: 18px; color: var(--gold); }
.mo-prog__name {
  flex: none;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}
.mo-prog__bar {
  position: relative;
  flex: 1 1 auto;
  min-width: 28px;
  height: 6px;
  border-radius: 3px;
  background: rgba(242, 234, 216, 0.12);
  overflow: hidden;
}
.mo-prog__fill {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border-radius: 3px;
  background: linear-gradient(90deg, #C9952F, var(--gold) 60%, var(--gold-soft));
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.7s var(--ease-out);
}
[dir="rtl"] .mo-prog__fill { transform-origin: right center; background: linear-gradient(270deg, #C9952F, var(--gold) 60%, var(--gold-soft)); }
.mo-prog__count {
  flex: none;
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--gold-soft);
  direction: ltr;
  unicode-bidi: isolate;
}
.mo-prog.is-glow { animation: mo-glow 0.9s var(--ease-out); }
@keyframes mo-glow {
  0% { box-shadow: inset 0 0 0 1px var(--hairline), 0 0 0 0 rgba(232, 182, 90, 0.55); }
  40% { box-shadow: inset 0 0 0 1px rgba(232, 182, 90, 0.8), 0 0 0 6px rgba(232, 182, 90, 0.18); }
  100% { box-shadow: inset 0 0 0 1px var(--hairline), 0 0 0 10px rgba(232, 182, 90, 0); }
}
/* landscape: the pill sits at the top of a narrow side column, so it wraps onto two lines */
.mo-hud.is-compact .mo-prog {
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 8px 12px;
  border-radius: 16px;
}
.mo-hud.is-compact .mo-prog__icon { width: 16px; height: 16px; }
.mo-hud.is-compact .mo-prog__name { font-size: 0.92rem; flex: 1 1 calc(100% - 30px); overflow: hidden; text-overflow: ellipsis; }
.mo-hud.is-compact .mo-prog__bar { order: 3; flex: 1 1 auto; }
.mo-hud.is-compact .mo-prog__count { order: 4; font-size: 0.84rem; }

/* ---------- panels ---------- */
.mo-art {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  box-shadow: 0 0 0 1px rgba(232, 182, 90, 0.6), 0 10px 26px rgba(2, 5, 20, 0.35);
}
.mo-art canvas { border-radius: 16px; }
.mo-art.is-shine::after {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(115deg, rgba(255, 240, 200, 0) 38%, rgba(255, 240, 200, 0.5) 50%, rgba(255, 240, 200, 0) 62%);
  background-size: 260% 100%;
  background-position: 120% 0;
  animation: mo-shine 1.5s var(--ease-out) 0.25s both;
}
@keyframes mo-shine { from { background-position: 120% 0; } to { background-position: -40% 0; } }

/* gallery */
.mo-gallery .fa-panel { max-width: 440px; }
.mo-gal {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 10px;
  text-align: center;
}
.mo-gal__item { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.mo-gal__thumb {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--hairline);
}
.mo-gal__thumb canvas { width: 100%; height: auto; }
.mo-gal__item.is-done .mo-gal__thumb { box-shadow: 0 0 0 1px rgba(232, 182, 90, 0.6); }
.mo-gal__item.is-current .mo-gal__thumb { box-shadow: 0 0 0 2px var(--gold), 0 0 14px rgba(232, 182, 90, 0.3); }
.mo-gal__name { font-size: 0.8rem; font-weight: 650; line-height: 1.2; color: var(--parchment); overflow-wrap: anywhere; }
.mo-gal__state { font-size: 0.72rem; line-height: 1.2; color: var(--mist); font-variant-numeric: tabular-nums; }
.mo-gal__item.is-locked .mo-gal__name { color: var(--mist-dim); font-weight: 550; }
.mo-gal__badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--lapis);
  font-size: 0.7rem;
  font-weight: 750;
  line-height: 1.3;
  direction: ltr;
}
[dir="rtl"] .mo-gal__badge { right: auto; left: 4px; }
@media (max-width: 340px) { .mo-gal { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* never let a button squeeze its icon */
.fa-btn svg { flex: none; }

/* game over: where the mosaic stands */
.mo-keep {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(242, 234, 216, 0.05);
  text-align: start;
}
.mo-keep canvas { flex: none; border-radius: 8px; box-shadow: 0 0 0 1px var(--hairline); }
.mo-keep__head { display: flex; align-items: baseline; gap: 6px; }
.mo-keep__name { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; line-height: 1.2; }
.mo-keep__dot { color: var(--mist-dim); }
.mo-keep__text { margin-top: 2px; font-size: 0.86rem; line-height: 1.35; color: var(--mist); }
.mo-keep__count { color: var(--gold-soft); font-weight: 700; font-variant-numeric: tabular-nums; }
.mo-over .fa-stats { margin-bottom: 12px; }

/* short phones (iPhone SE and friends): keep every panel on one screen */
@media (max-height: 639px) {
  .fa-panel { padding: 20px 18px 16px; }
  .fa-panel__art { margin-bottom: 8px; }
  .fa-panel__title { font-size: 1.6rem; margin-bottom: 6px; }
  .fa-panel__text { margin-bottom: 12px; font-size: 0.95rem; }
  .fa-howto { gap: 6px; margin-bottom: 14px; font-size: 0.95rem; }
  .fa-stats { margin-bottom: 12px; }
  .fa-stats dd { font-size: 1.3rem; }
  .mo-gal { gap: 10px 8px; }
}

/* landscape phones: panels go side by side so nothing needs scrolling */
@media (orientation: landscape) and (max-height: 500px) {
  .mo-wide .fa-panel {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    column-gap: 22px;
    align-items: center;
    max-width: 600px;
    padding: 16px 20px;
    text-align: start;
  }
  .mo-wide .fa-panel > * { grid-column: 2; }
  .mo-wide .fa-panel > .fa-panel__art { grid-column: 1; grid-row: 1 / span 6; margin: 0; }
  .mo-wide .fa-panel > .fa-panel__close { grid-column: auto; }
  .mo-wide .fa-panel__title { font-size: 1.45rem; margin: 2px 0 6px; }
  .mo-wide .fa-panel__text { margin: 0 0 10px; font-size: 0.9rem; line-height: 1.35; }
  .mo-wide .fa-howto { gap: 4px; margin-bottom: 10px; font-size: 0.9rem; }
  .mo-wide .fa-stats { margin-bottom: 10px; }
  .mo-wide .fa-stats > div { padding: 6px 6px 5px; }
  .mo-wide .fa-stats dd { font-size: 1.2rem; }
  .mo-wide .fa-btn { min-height: 44px; padding: 0.7em 1em; }
  .mo-cardpanel .mo-art canvas, .mo-cardpanel .mo-art { width: 118px !important; height: 118px !important; }
  .mo-startpanel .mo-art canvas, .mo-startpanel .mo-art { width: 96px !important; height: 96px !important; }
  /* game over: the result on the left, the buttons on the right */
  .mo-overpanel .fa-panel { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
  .mo-overpanel .fa-panel > * { grid-column: 1; }
  .mo-overpanel .fa-panel > .fa-panel__actions { grid-column: 2; grid-row: 1 / span 3; }
  .mo-overpanel .fa-panel__eyebrow, .mo-overpanel .fa-panel__title { text-align: center; }
  /* gallery: one row of eight */
  .mo-gallery.mo-wide .fa-panel { display: block; max-width: 760px; text-align: center; }
  .mo-gallery .fa-panel__text { display: none; }
  .mo-gallery .mo-gal { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; }
  .mo-gallery .mo-gal__name { font-size: 0.72rem; }
}
@media (orientation: landscape) and (max-height: 340px) {
  .mo-startpanel .fa-howto { display: none; }
}
