/* public/css/minigames/fracture.css
   Fracture — drag fraction labels onto fracturing shape pieces
*/

.ui-sheet.mg-fr {
  padding-top: 10px;
}

/* ============================================================
   Top header (matches other minigames)
============================================================ */

.mg-fr__head {
  display: grid;
  gap: 8px;
}

.mg-fr__headRow1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.mg-fr__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.mg-fr__title {
  margin: 0;
  min-width: 0;
  font-size: 20px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mg-fr__back {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 14px;
  display: grid;
  place-items: center;
}

.mg-fr__meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
}

.mg-fr__pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 900;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  white-space: nowrap;
  opacity: 0.9;
}

.mg-fr__pill i {
  opacity: 0.9;
}

/* ============================================================
   Body
============================================================ */

.mg-fr__body {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.mg-fr__statusText {
  font-size: 13px;
  font-weight: 800;
  opacity: 0.7;
  white-space: nowrap;
  flex-shrink: 0;
  min-height: 1.2em;
}

.mg-fr__statusText[data-kind="good"] {
  color: #10b981;
  opacity: 1;
}

/* progress row */
.mg-fr__progressRow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: -2px 0 6px;
  padding-top: 2px;
}

.mg-fr__hint {
  font-size: 12px;
  opacity: 0.85;
  white-space: nowrap;
}

.mg-fr__bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
  min-width: 80px;
}

.mg-fr__barFill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--rainbow);
  transition: width 180ms ease;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.mg-fr__timer {
  font-size: 12px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  white-space: nowrap;
}

/* card head */
.mg-fr__cardHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 10px;
  min-width: 0;
}

.mg-fr__cardTitle {
  margin: 0;
  font-weight: 950;
  font-size: 13px;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ============================================================
   Shape area — the fracturing rectangle
============================================================ */

.mg-fr__shapeWrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 250px;
  background: none;
  border: none;
  box-shadow: none;
}

.mg-fr__spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: 0.5;
}

.mg-fr__shape {
  position: relative;
  width: 100%;
  max-width: 380px;
  aspect-ratio: 1 / 1;
  background: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ============================================================
   Pieces — absolutely positioned within the shape
============================================================ */

.mg-fr__piece {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  box-sizing: border-box;
  transition: background 250ms, box-shadow 250ms, opacity 250ms, filter 250ms;
  cursor: default;
}

/* Shared SVG border overlay for clipped shapes */
.mg-fr__borderSvg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

/* Active piece — needs labeling. SVG overlay draws dashed border. */
.mg-fr__piece.is-active {
  background: rgba(80, 80, 80, 0.06);
  opacity: 0.7;
}

/* Hover target while dragging over */
.mg-fr__piece.is-hover {
  background: rgba(120, 160, 255, 0.18);
  opacity: 1;
  box-shadow: inset 0 0 20px rgba(120, 160, 255, 0.12);
  transform: scale(1.015);
}

/* Solved piece — colored by denominator (bg set inline by JS). SVG draws solid border. */
.mg-fr__piece.is-solved {
  filter: saturate(1.15) brightness(1.05);
  opacity: 1;
}

/* Pending (optimistic, waiting for server) */
.mg-fr__piece.is-pending {
  background: rgba(80, 80, 80, 0.04);
}

/* Validating (server call in flight) */
.mg-fr__piece.is-validating {
  animation: frBreath 0.85s ease-in-out infinite;
  overflow: hidden;
}

.mg-fr__piece.is-validating::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.35) 50%, transparent 100%);
  animation: frShimmer 1s ease-in-out infinite;
  mix-blend-mode: overlay;
  pointer-events: none;
}

@keyframes frBreath {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.12); }
}

@keyframes frShimmer {
  0% { transform: translateX(-130%); opacity: 0; }
  15% { opacity: 0.55; }
  100% { transform: translateX(130%); opacity: 0; }
}

/* Wrong — red shake, whole piece flashes */
.mg-fr__piece.is-wrong {
  animation: frShake 360ms ease;
  background: rgba(239, 68, 68, 0.18) !important;
  border-color: rgba(239, 68, 68, 0.55) !important;
}

@keyframes frShake {
  0%, 100% { transform: translateX(0); }
  18% { transform: translateX(-3px); }
  36% { transform: translateX(3px); }
  54% { transform: translateX(-2px); }
  72% { transform: translateX(2px); }
}

/* Fracturing piece — amber glow before splitting */
.mg-fr__piece.is-fracturing {
  animation: frCrack 500ms ease forwards;
  border-color: rgba(251, 191, 36, 0.6) !important;
  background: rgba(251, 191, 36, 0.15) !important;
}

@keyframes frCrack {
  0% { transform: scale(1); opacity: 1; }
  30% { transform: scale(1.02); }
  60% { transform: scale(0.98); }
  100% { transform: scale(1); opacity: 0; }
}

/* New pieces entering after fracture */
.mg-fr__piece.is-entering {
  animation: frEnter 350ms ease-out;
}

@keyframes frEnter {
  0% { opacity: 0; transform: scale(0.92); }
  100% { opacity: 1; transform: scale(1); }
}

/* ============================================================
   Hint label — "1/?" shown centered on active pieces
============================================================ */

.mg-fr__hintLabel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0px;
  pointer-events: none;
  opacity: 1;
  font-weight: 900;
  line-height: 1;
  color: var(--text-secondary, #888);
}

.mg-fr__hintLabel__num {
  font-size: 18px;
}

.mg-fr__hintLabel__bar {
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  margin: 2px 0;
}

.mg-fr__hintLabel__den {
  font-size: 20px;
}

/* ============================================================
   Solved label — small, floats to top-left corner
============================================================ */

.mg-fr__solvedLabel {
  position: absolute;
  top: 4px;
  left: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0px;
  pointer-events: none;
  font-weight: 900;
  line-height: 1;
  opacity: 0.4;
}

.mg-fr__solvedLabel__num {
  font-size: 11px;
}

.mg-fr__solvedLabel__bar {
  width: 14px;
  height: 1.5px;
  background: currentColor;
  border-radius: 1px;
  margin: 1px 0;
  opacity: 0.6;
}

.mg-fr__solvedLabel__den {
  font-size: 11px;
}

/* ============================================================
   Centered label — used during validation
============================================================ */

.mg-fr__pieceLabel {
  font-weight: 900;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0px;
  pointer-events: none;
}

.mg-fr__pieceLabel__num {
  font-size: 18px;
}

.mg-fr__pieceLabel__bar {
  width: 22px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  margin: 2px 0;
  opacity: 0.6;
}

.mg-fr__pieceLabel__den {
  font-size: 20px;
}

/* ============================================================
   Compact inline label — for narrow pieces where stacked doesn't fit
============================================================ */

.mg-fr__compactLabel {
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
  white-space: nowrap;
  opacity: 0.85;
}

.mg-fr__piece.is-active .mg-fr__compactLabel {
  color: var(--text-secondary, #888);
}

/* ============================================================
   Tray — draggable fraction tiles (colored by denominator)
============================================================ */

.mg-fr__tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 12px 8px;
  min-height: 54px;
}

.mg-fr__tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0px;
  min-width: 48px;
  height: 54px;
  padding: 4px 14px;
  border-radius: 10px;
  /* bg + borderColor set inline by JS for per-tile color */
  border-width: 2px;
  border-style: dashed;
  font-weight: 900;
  font-size: 17px;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform 80ms, box-shadow 80ms, filter 80ms;
  filter: brightness(1.1) saturate(1.2);
}

.mg-fr__tile:active {
  cursor: grabbing;
}

.mg-fr__tile.is-dragging {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  transform: scale(1.08);
  z-index: 9999;
  pointer-events: none;
  filter: brightness(1.15) saturate(1.2);
}

/* ============================================================
   Drag-hint ghost — phantom tile that loops from tray to target
   piece so visitors see the "drag & drop" mechanic without reading
   anything. Positions (start/end) are computed by JS and passed
   via --hint-dx / --hint-dy. Dismissed on first real tile grab.
============================================================ */
.mg-fr__dragHint {
  pointer-events: none !important;
  user-select: none;
  -webkit-user-select: none;
  z-index: 20;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  filter: brightness(1.08) saturate(1.12);
  animation: mg-fr-dragHint 3.6s cubic-bezier(0.4, 0, 0.2, 1) 0.8s infinite;
  will-change: transform, opacity;
}

@keyframes mg-fr-dragHint {
  0%   { transform: translate(0, 0) scale(1);       opacity: 0; }
  8%   { transform: translate(0, 0) scale(1);       opacity: 1; }
  16%  { transform: translate(0, -5px) scale(1.12); opacity: 1; }
  52%  { transform: translate(var(--hint-dx, 0px), var(--hint-dy, 0px)) scale(1.12); opacity: 1; }
  62%  { transform: translate(var(--hint-dx, 0px), var(--hint-dy, 0px)) scale(1);    opacity: 1; }
  82%  { transform: translate(var(--hint-dx, 0px), var(--hint-dy, 0px)) scale(1);    opacity: 0.9; }
  95%  { transform: translate(var(--hint-dx, 0px), var(--hint-dy, 0px)) scale(0.85); opacity: 0; }
  100% { transform: translate(0, 0) scale(1);       opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .mg-fr__dragHint { display: none; }
}

@media (hover: hover) {
  .mg-fr__tile:hover {
    filter: brightness(1.15) saturate(1.2);
    transform: scale(1.03);
  }
}

.mg-fr__tile__num,
.mg-fr__tile__den {
  line-height: 1.1;
}

.mg-fr__tile__bar {
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  opacity: 0.5;
  margin: 1px 0;
}

html.is-grabbing,
html.is-grabbing * {
  cursor: grabbing !important;
}

/* ============================================================
   Responsive
============================================================ */

@media (max-width: 420px) {
  .mg-fr__title {
    font-size: 16px;
  }
  .mg-fr__cardTitle {
    font-size: 12px;
  }
  .mg-fr__shape {
    max-width: 320px;
  }
  .mg-fr__tile {
    min-width: 42px;
    height: 48px;
    padding: 3px 10px;
    font-size: 14px;
  }
  .mg-fr__hintLabel__num {
    font-size: 15px;
  }
  .mg-fr__hintLabel__den {
    font-size: 16px;
  }
  .mg-fr__solvedLabel__num,
  .mg-fr__solvedLabel__den {
    font-size: 10px;
  }
}

/* ============================================================
   /try layout — minimal marketing wrapper
============================================================ */

.try-main {
  min-height: 100vh;
  padding: 16px 12px 24px;
  display: flex;
  justify-content: center;
}

.try-container {
  width: 100%;
  max-width: 560px;
}

.try-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
}

.try-brand__logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.try-brand__name {
  font-family: "Baloo 2", system-ui, sans-serif;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.try-cta {
  white-space: nowrap;
}

/* ============================================================
   Demo completion modal
============================================================ */

html.try-modal-open,
html.try-modal-open body {
  overflow: hidden;
}

.try-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
}

.try-modal[hidden] {
  display: none;
}

.try-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.try-modal__card {
  position: relative;
  background: var(--surface, #fff);
  color: var(--app-fg, #111);
  border-radius: 18px;
  padding: 24px 22px 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: tryModalIn 220ms ease-out;
}

@keyframes tryModalIn {
  0% { opacity: 0; transform: translateY(8px) scale(0.98); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.try-modal__title {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 900;
  line-height: 1.15;
}

.try-modal__body {
  margin: 0 0 18px;
  font-size: 15px;
  line-height: 1.45;
  opacity: 0.9;
}

.try-modal__actions {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.try-modal__cta {
  width: 100%;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 16px;
}

.try-modal__fine {
  margin: 0;
  font-size: 12px;
  opacity: 0.6;
}

@media (max-width: 420px) {
  .try-modal__card {
    padding: 20px 18px 16px;
  }
  .try-modal__title {
    font-size: 20px;
  }
}
