/* ============================================================
   Shared chrome: reset, paper grain, HUD, toast, hint sheet,
   win card. Every level page loads tokens.css then this file.
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-ui);
  color: var(--c-ink);
  background: var(--c-wall);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

/* --- paper texture ------------------------------------------
   Two frequencies: a coarse tooth that darkens and a fine
   fibre that lifts. Both stay subtle so the palette survives.
   ----------------------------------------------------------- */

.grain,
.grain-fine {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.grain {
  z-index: 2;
  background-image: var(--noise-coarse);
  background-size: 180px 180px;
  opacity: 0.07;
  mix-blend-mode: multiply;
}

.grain-fine {
  z-index: 3;
  background-image: var(--noise-fine);
  background-size: 120px 120px;
  opacity: 0.05;
  mix-blend-mode: soft-light;
}

/* --- vignette: pulls the eye to the middle of the frame --- */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
    ellipse 120% 90% at 50% 46%,
    rgba(58, 52, 46, 0) 42%,
    rgba(58, 52, 46, 0.09) 82%,
    rgba(58, 52, 46, 0.17) 100%
  );
}

/* ============================================================
   HUD
   ============================================================ */

.hud {
  position: fixed;
  z-index: 20;
  display: flex;
  gap: 10px;
  align-items: center;
}

.hud--top-left {
  top: 16px;
  left: 16px;
}

.hud--top-right {
  top: 16px;
  right: 16px;
}

.hud-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--c-ink-soft);
  background: var(--c-paper);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-rest);
  transition: transform var(--dur-lift) var(--ease-soft), box-shadow var(--dur-lift) var(--ease-soft),
    color var(--dur-lift) var(--ease-soft);
}

.hud-btn:hover {
  transform: translateY(-1px);
  color: var(--c-ink);
  box-shadow: var(--shadow-hover);
}

.hud-btn:active {
  transform: scale(0.94);
}

.hud-btn svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hud-btn.is-off {
  color: var(--c-ink-faint);
}

/* The technical solve shortcut. It carries a word rather than an icon
   because it is not a thing to reach for by feel, and it is tinted
   like the clay accent so it never reads as part of the game. */
.hud-btn--solve {
  width: auto;
  height: 34px;
  padding: 0 14px;
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--c-paper);
  background: var(--c-clay);
  opacity: 0.85;
}

.hud-btn--solve:hover {
  color: var(--c-paper);
  opacity: 1;
}

/* Level title strip, top-centre. */
.level-tag {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 7px 16px;
  transform: translateX(-50%);
  background: rgba(244, 239, 230, 0.82);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-rest);
  backdrop-filter: blur(3px);
}

.level-tag__num {
  font-size: var(--t-xs);
  font-weight: 700;
  color: var(--c-clay);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.level-tag__name {
  font-family: var(--font-display);
  font-size: var(--t-sm);
  font-weight: 600;
  color: var(--c-ink);
}

/* ============================================================
   Stars — one per distinct valid solution
   ============================================================ */

.stars {
  display: flex;
  gap: 5px;
}

.star {
  width: 17px;
  height: 17px;
  fill: rgba(58, 52, 46, 0.13);
  transition: fill var(--dur-snap) var(--ease-soft), transform var(--dur-snap) var(--ease-snap);
}

.star.is-earned {
  fill: var(--c-mustard);
}

@keyframes star-pop {
  0% {
    transform: scale(0.4) rotate(-22deg);
  }
  65% {
    transform: scale(1.28) rotate(5deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

.star.is-new {
  animation: star-pop var(--dur-reward) var(--ease-snap) both;
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 34px;
  left: 50%;
  z-index: 40;
  max-width: min(84vw, 420px);
  padding: 11px 20px;
  font-size: var(--t-sm);
  color: var(--c-ink);
  text-align: center;
  pointer-events: none;
  background: var(--c-paper-hi);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-card);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity var(--dur-snap) var(--ease-soft), transform var(--dur-snap) var(--ease-soft);
}

.toast.is-shown {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================================================
   Hint sheet — a scribbled-over diagram the player erases as
   much of as they like. Help is metered by the player, so
   asking for it never feels like defeat.
   ============================================================ */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: rgba(58, 52, 46, 0.42);
  opacity: 0;
  transition: opacity var(--dur-scene) var(--ease-soft);
}

.sheet[hidden] {
  display: none;
}

.sheet.is-shown {
  opacity: 1;
}

.sheet__card {
  position: relative;
  width: min(90vw, 460px);
  padding: 22px;
  background: var(--c-paper);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  transform: scale(0.94);
  transition: transform var(--dur-scene) var(--ease-snap);
}

.sheet.is-shown .sheet__card {
  transform: scale(1);
}

.sheet__title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: var(--t-md);
  font-weight: 600;
}

.sheet__hint {
  margin: 0 0 14px;
  font-size: var(--t-xs);
  color: var(--c-ink-soft);
}

.sheet__canvas {
  display: block;
  width: 100%;
  height: auto;
  cursor: crosshair;
  background: var(--c-paper-hi);
  border-radius: var(--r-tray);
  box-shadow: var(--shadow-inset);
  touch-action: none;
}

.sheet__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  padding: 10px 22px;
  font-size: var(--t-sm);
  font-weight: 700;
  border-radius: var(--r-pill);
  transition: transform var(--dur-lift) var(--ease-soft), box-shadow var(--dur-lift) var(--ease-soft),
    background var(--dur-lift) var(--ease-soft);
}

.btn:active {
  transform: scale(0.96);
}

.btn--primary {
  color: var(--c-paper-hi);
  background: var(--c-clay);
  box-shadow: var(--shadow-rest);
}

.btn--primary:hover {
  background: var(--c-clay-deep);
  box-shadow: var(--shadow-hover);
}

.btn--ghost {
  color: var(--c-ink-soft);
  background: rgba(58, 52, 46, 0.07);
}

.btn--ghost:hover {
  color: var(--c-ink);
  background: rgba(58, 52, 46, 0.12);
}

/* ============================================================
   Win card
   ============================================================ */

/* The reward for solving the puzzle is looking at the solved
   puzzle. A centred modal covers exactly the thing the player just
   earned, so the win card is a bottom sheet and the scrim is only a
   soft gradient at the foot of the screen. */
.win {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 14px calc(20px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, transparent 46%, rgba(58, 52, 46, 0.3) 100%);
  opacity: 0;
  transition: opacity var(--dur-scene) var(--ease-soft);
}

.win[hidden] {
  display: none;
}

.win.is-shown {
  opacity: 1;
}

.win__card {
  width: min(94vw, 430px);
  padding: 18px 24px 16px;
  text-align: center;
  background: var(--c-paper);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-lift), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  transform: translateY(26px);
  transition: transform var(--dur-reward) var(--ease-snap);
}

.win.is-shown .win__card {
  transform: translateY(0);
}

.win__title {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: var(--t-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.win__text {
  margin: 0 0 2px;
  font-size: var(--t-sm);
  color: var(--c-ink-soft);
}

.win__stars {
  display: flex;
  gap: 9px;
  justify-content: center;
  margin: 12px 0 10px;
}

.win__stars .star {
  width: 30px;
  height: 30px;
}

.win__solutions {
  margin: 0;
  font-size: var(--t-xs);
  color: var(--c-ink-faint);
}

.win__actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 15px;
}

/* On a short landscape window the sheet would eat the frame, so it
   tightens up rather than scrolling. */
@media (max-height: 560px) {
  .win__card {
    padding: 12px 20px 12px;
  }

  .win__stars {
    margin: 8px 0 6px;
  }

  .win__stars .star {
    width: 24px;
    height: 24px;
  }

  .win__actions {
    margin-top: 10px;
  }
}

/* ============================================================
   Shared object behaviour
   ============================================================ */

.draggable {
  touch-action: none;
  cursor: grab;
}

.draggable.is-held {
  z-index: 30;
  cursor: grabbing;
}

/* Animations use `transform` rather than the individual `translate`
   and `scale` properties: those need Chrome 104+, and Android
   WebViews on RuStore devices are not always that recent. */
@keyframes reject-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-4px);
  }
  50% {
    transform: translateX(3px);
  }
  75% {
    transform: translateX(-2px);
  }
}

.is-rejected {
  animation: reject-shake 180ms var(--ease-reject);
}

@keyframes settle-in {
  0% {
    transform: translateY(-2px) scale(1.03);
  }
  60% {
    transform: translateY(0) scale(0.995);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes scene-breath {
  0%,
  100% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.012);
  }
}

.is-solved-breath {
  animation: scene-breath 520ms var(--ease-soft) 1;
}

/* ============================================================
   Accessibility. The snap behaviour stays under reduced motion;
   only decorative overshoot, stagger and breath are dropped.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 80ms !important;
  }
}

@media (max-width: 640px) {
  .hud--top-left {
    top: 12px;
    left: 12px;
  }

  .hud--top-right {
    top: 12px;
    right: 12px;
  }

  .hud-btn {
    width: 40px;
    height: 40px;
  }

  .level-tag {
    top: 13px;
    padding: 5px 13px;
  }

  .level-tag__name {
    font-size: var(--t-xs);
  }
}
