/* The --paper-* and --font-* brand tokens live in site/theme.css, shared
   with the website and loaded before this file via index.html. */
:root {
  --flash-duration: 600ms;
  --flash-removed-color: var(--c-warning, #c0392b);
  --flash-added-glow: var(--c-accent, #1f77b4);

  --chrome-height: 8.25rem;
  --grid-size: min(calc(100vw - 3rem), calc(100vh - var(--chrome-height)));

  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--paper-ink);
  background-color: var(--paper-bg);

  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--paper-bg);
  color: var(--paper-ink);
  min-height: 100vh;
}

h1,
h2,
h3 {
  font-family: var(--font-serif);
  color: var(--paper-ink);
}

button,
select,
input {
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--paper-ink);
  background: transparent;
  border: 1px solid var(--paper-line);
  border-radius: 4px;
  padding: 0.35rem 0.75rem;
}

button {
  cursor: pointer;
}

button:hover {
  border-color: var(--paper-accent);
  color: var(--paper-accent);
}

button:active {
  background-color: rgba(26, 78, 122, 0.08);
}

a {
  color: var(--paper-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 2rem 1.5rem;
  min-height: 100vh;
  box-sizing: border-box;
  font-family: var(--font-sans);
  color: var(--paper-ink-2);
}

/* The grid scales to whichever of the viewport width or height is the binding constraint. */
.grid-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

/* Wraps the SVG and the footer stats row below it. */
.puzzle-wrap {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
}

/* Three-column row: cage-stats on the left, the fix/unfix button centered
   beneath the puzzle, and solution-count on the right. The equal 1fr side
   columns keep the button centered regardless of the side content. */
.puzzle-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: flex-start;
  padding-top: 0.35rem;
  min-height: 1.5em;
}

.grid-svg {
  display: block;
  width: var(--grid-size);
  height: auto;
  aspect-ratio: 1 / 1;
  /* SVG clips at its viewport by default; the operation selector is anchored
     to a cage's anchor cell and must be able to overhang the puzzle edge
     rather than be cut off (issue #95). */
  overflow: visible;
}

.solution-count {
  grid-column: 3;
  font-size: 1rem;
  font-weight: 600;
  color: var(--paper-ink-2);
  margin-left: auto;
  /* Mirror the cage-stats left indent on the right side. */
  padding-right: calc(var(--grid-size) * 14 / 600);
}

.cage-stats {
  grid-column: 1;
  font-size: 1rem;
  font-weight: 600;
  color: var(--paper-ink-2);
  /* Indent to align with the inner grid border, not the SVG outer edge.
     SVG viewBox is 600 units wide; MARGIN=14, so offset = grid-size * 14/600. */
  padding-left: calc(var(--grid-size) * 14 / 600);
}

/* Flash overlay animations.

   Ghost glyphs for candidates removed by the latest change hold at full
   opacity for the first part of the flash, then fade; `forwards` keeps them
   invisible afterwards (they stay in the DOM until the next re-mount). A cell
   that collapsed to a single value flashes that digit from the accent color
   back to its normal ink (the end frame matches the SVG fill attribute, so no
   `forwards` is needed). */
@keyframes flash-remove {
  0%,
  60% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes flash-add {
  from {
    fill: var(--flash-added-glow);
    text-shadow: 0 0 6px color-mix(in srgb, var(--flash-added-glow) 60%, transparent);
  }
  to {
    fill: var(--paper-ink);
    text-shadow: none;
  }
}

.flash-removed {
  fill: var(--flash-removed-color);
  text-decoration: line-through;
  animation: flash-remove var(--flash-duration) ease-out forwards;
  pointer-events: none;
}

.flash-added {
  animation: flash-add var(--flash-duration) ease-out;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --flash-duration: 0ms;
  }
}
