/*
 * Rise & Grind — styles.
 *
 * Self-contained: no framework, no remote fonts. The palette mirrors
 * src/lib/brand.ts (riseAndGrindBundle.test.ts holds the shared values to it),
 * so the game reads as the shop after hours: logo ink on cream, Playfair italic
 * for anything that counts, banneton coils behind the sack.
 */

@font-face {
  font-family: 'Playfair Display';
  font-style: italic;
  font-weight: 400 900;
  font-display: swap;
  src: url('fonts/playfair-display-italic.woff2') format('woff2');
}

@font-face {
  font-family: 'DM Sans';
  font-style: normal;
  font-weight: 100 1000;
  font-display: swap;
  src: url('fonts/dm-sans.woff2') format('woff2');
}

:root {
  color-scheme: light;

  /* Shared with src/lib/brand.ts */
  --primary: #40281C;
  --primary-dark: #2A1810;
  --primary-light: #8A6A4E;
  --accent: #F6EFE2;
  --accent-dark: #E3D6C0;
  --background: #FBF8F2;
  --text-main: #2A211B;
  --text-muted: #6E6055;

  /* Game-only, and never behind or as text */
  --wheat: #C9954A;
  --coil: #EADCC4;

  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --text-count: clamp(2.25rem, 1.4rem + 3.6vw, 4.25rem);
  --text-magnitude: clamp(1.05rem, 0.75rem + 1.3vw, 1.75rem);
  --text-title: clamp(2.25rem, 1.5rem + 3vw, 3.5rem);
  --text-section: clamp(1.6rem, 1.2rem + 1.5vw, 2.2rem);

  --gutter: clamp(1rem, 0.5rem + 2.5vw, 3rem);
  --radius-soft: 14px;
  --radius-pill: 999px;

  --shadow-lift: 0 12px 32px rgba(64, 40, 28, 0.14), 0 4px 10px rgba(64, 40, 28, 0.08);

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 150ms;
  /* Matches FLOAT_LIFETIME_MS in game.js */
  --duration-float: 900ms;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html.is-booting .bakery,
html.is-booting .dock {
  visibility: hidden;
}

body {
  margin: 0;
  min-height: 100dvh;
  background-color: var(--background);
  /* A flour-dusted bench: a faint dot grid in the logo ink. */
  background-image: radial-gradient(rgba(64, 40, 28, 0.07) 1px, transparent 1.5px);
  background-size: 22px 22px;
  color: var(--text-main);
  font: 400 1rem/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, dl, dd, ol, ul {
  margin: 0;
}

ol, ul {
  padding: 0;
  list-style: none;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.noscript {
  padding: 2rem var(--gutter);
  text-align: center;
}

/* ── Layout ───────────────────────────────────────────────────────────── */

.bakery {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 var(--gutter) calc(env(safe-area-inset-bottom, 0px) + 6.5rem);
}

@media (min-width: 900px) {
  .bakery {
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: clamp(2rem, 5vw, 5rem);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 3rem);
  }

  /* The bench stays put while the shop scrolls beside it. */
  .bench {
    position: sticky;
    top: 0;
    height: 100dvh;
  }
}

/* ── Bench: title, tally, sack ────────────────────────────────────────── */

.bench {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: calc(env(safe-area-inset-top, 0px) + clamp(1.5rem, 4vh, 3rem));
  padding-bottom: 1.5rem;
}

.masthead {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.7rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--primary-light);
}

.eyebrow::before,
.eyebrow::after {
  content: '';
  width: 2rem;
  height: 1px;
  background: currentColor;
}

.title {
  font: italic 600 var(--text-title) / 0.95 var(--font-display);
  letter-spacing: -0.02em;
  color: var(--primary);
}

.title .amp {
  font-weight: 400;
  color: var(--primary-light);
}

.tagline {
  max-width: 32ch;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-wrap: balance;
}

.tally {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  margin-top: clamp(1.25rem, 3vh, 2.25rem);
}

/* Three stacked rows — the number, its magnitude word, then the unit. Laid out
   one above the other rather than wrapped: as a flex line the count changed
   width ten times a second, so the word behind it shuffled sideways and, near
   the wrap point, hopped between lines. */
.count {
  display: grid;
  justify-items: center;
  gap: 0.1rem;
  color: var(--text-main);
}

.count-value {
  font: italic 600 var(--text-count) / 1 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
  letter-spacing: -0.02em;
}

.count-magnitude {
  font: italic 500 var(--text-magnitude) / 1 var(--font-display);
  letter-spacing: 0.01em;
}

.unit {
  /* Number and magnitude read as one figure, so the unit gets the air. */
  margin-top: 0.2rem;
  font: 500 0.9rem / 1 var(--font-body);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.rate {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.per-click::before {
  content: '·';
  margin: 0 0.6em;
}

/* A size container, so the basket and sack scale to whichever runs out first —
   the stage's width or its height. Fixed sizes spilled up over the rate line at
   tablet widths, where the stage is wide but only its min-height tall. */
.stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  width: 100%;
  min-height: min(calc(80vw + 1.5rem), 400px);
  margin-top: 0.5rem;
  container-type: size;
}

@media (min-width: 900px) {
  /* Beside the shop, the sticky bench hands the stage its leftover height. */
  .stage {
    min-height: 240px;
  }
}

/* Banneton coils: the proving basket the sack sits in. */
.stage::before {
  content: '';
  position: absolute;
  width: min(80%, 370px);
  width: min(80cqw, 370px, 94cqh);
  aspect-ratio: 1;
  border-radius: 50%;
  background: repeating-radial-gradient(circle at center, var(--accent) 0 9px, var(--coil) 9px 12px);
  box-shadow:
    inset 0 0 0 1px var(--accent-dark),
    inset 0 12px 30px rgba(64, 40, 28, 0.1);
}

.sack {
  position: relative;
  z-index: 1;
  display: block;
  width: min(56%, 250px);
  /* Two thirds of the basket, which keeps the whole sack inside the coils. */
  width: calc(min(80cqw, 370px, 94cqh) * 0.68);
  padding: 0;
  border: 0;
  border-radius: 40%;
  background: none;
  cursor: pointer;
  filter: drop-shadow(0 18px 16px rgba(64, 40, 28, 0.18));
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 220ms var(--ease-out);
}

.sack:hover {
  transform: rotate(-3deg) scale(1.03);
}

.sack:active {
  transform: scale(0.96);
}

.sack-art {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 240 / 290;
}

.float {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  white-space: nowrap;
  font: italic 700 1.6rem / 1 var(--font-display);
  color: var(--primary);
  text-shadow: 0 1px 0 var(--background), 0 0 12px var(--background);
  transform: translate(-50%, -50%);
  animation: rise var(--duration-float) var(--ease-out) forwards;
}

.puff {
  position: absolute;
  z-index: 2;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 0 0 1px rgba(64, 40, 28, 0.08);
  pointer-events: none;
}

.welcome {
  max-width: 36ch;
  margin-top: 1rem;
  padding: 0.6rem 1.1rem;
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius-pill);
  background: var(--accent);
  font-size: 0.875rem;
  color: var(--text-main);
  animation: fade-up 500ms var(--ease-out) both;
}

/* ── Shop: producers and tools ────────────────────────────────────────── */

.shop {
  padding-block: clamp(1.5rem, 6vh, 4rem) 2rem;
}

.shop h2 {
  font: italic 600 var(--text-section) / 1.1 var(--font-display);
  color: var(--text-main);
}

.shop-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--primary);
}

.quantity {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.25rem;
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.quantity-label {
  padding: 0 0.4rem 0 0.7rem;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quantity button {
  min-width: 2.75rem;
  min-height: 2rem;
  padding: 0 0.6rem;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--duration-fast), color var(--duration-fast);
}

.quantity button:hover {
  color: var(--text-main);
}

.quantity button[aria-pressed='true'] {
  background: var(--primary);
  color: var(--accent);
}

.producer {
  display: grid;
  grid-template-columns: 3.25rem minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 1rem;
  padding: 1rem 0;
  border-bottom: 1px dashed var(--accent-dark);
  animation: fade-up 450ms var(--ease-out) both;
}

.producer-owned {
  font: italic 600 2rem / 1 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
  text-align: center;
  color: var(--primary-light);
}

.producer.is-running .producer-owned {
  font-size: 2.25rem;
  color: var(--primary);
}

.producer-name {
  font: 600 1.05rem / 1.25 var(--font-body);
  color: var(--text-main);
}

.producer-flavor {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.producer-meta {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--primary-light);
}

/* Progress to the next ×2: decorative, the meta line says it in words. */
.producer-progress {
  display: block;
  max-width: 12rem;
  height: 3px;
  margin-top: 0.4rem;
  overflow: hidden;
  border-radius: 2px;
  background: var(--accent-dark);
}

.producer-progress-fill {
  display: block;
  height: 100%;
  background: var(--wheat);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 300ms var(--ease-out);
}

.buy {
  display: grid;
  justify-items: end;
  gap: 0.1rem;
  min-width: 6.5rem;
  padding: 0.55rem 0.9rem;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-soft);
  background: var(--primary);
  color: var(--accent);
  text-align: right;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--primary-dark);
  transition:
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast);
}

.buy-label {
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.buy-cost {
  font: italic 600 1.15rem / 1.1 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
}

.buy:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 0 var(--primary-dark);
}

.buy:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--primary-dark);
}

/* aria-disabled rather than disabled, so a button bought down to unaffordable keeps keyboard focus. */
.buy[aria-disabled='true'] {
  border-color: var(--accent-dark);
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

@media (max-width: 400px) {
  .producer {
    grid-template-columns: 2.5rem minmax(0, 1fr);
  }

  .buy {
    grid-column: 2;
    justify-self: start;
    justify-items: start;
    margin-top: 0.5rem;
    text-align: left;
  }
}

.tools-heading {
  margin-top: 2.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--primary);
}

.tools-empty {
  padding: 1rem 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.tools {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 12.5rem), 1fr));
  gap: 0.75rem;
  padding-top: 1rem;
}

.tool-button {
  display: grid;
  align-content: start;
  gap: 0.2rem;
  width: 100%;
  height: 100%;
  padding: 0.9rem 1rem 0.85rem;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-soft);
  background: var(--accent);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--primary);
  transition:
    transform var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out);
}

.tool-button:hover {
  transform: translateY(-2px) rotate(-0.5deg);
  box-shadow: 0 5px 0 var(--primary);
}

.tool-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--primary);
}

.tool-name {
  font-weight: 600;
  color: var(--text-main);
}

.tool-effect {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--text-muted);
}

.tool-cost {
  margin-top: 0.4rem;
  font: italic 600 1.05rem / 1 var(--font-display);
  color: var(--primary);
}

.tool-button[aria-disabled='true'] {
  border-color: var(--accent-dark);
  background: transparent;
  box-shadow: none;
  transform: none;
  cursor: not-allowed;
}

.tool-button[aria-disabled='true'] .tool-cost {
  color: var(--text-muted);
}

/* A tool in use: stamped rather than for sale. */
.tool.is-owned .tool-button {
  border-style: dashed;
  border-color: var(--primary-light);
  cursor: default;
}

.tool.is-owned .tool-cost {
  font: 600 0.68rem / 1 var(--font-body);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--primary-light);
}

.tool.is-owned .tool-cost::before {
  content: '✓ ';
}

/* ── Ledger ───────────────────────────────────────────────────────────── */

.ledger {
  display: grid;
  gap: 1.25rem;
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 2px solid var(--primary);
}

.shop .ledger h2 {
  font-size: 1.4rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr));
  gap: 1rem;
}

.stats dt {
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stats dd {
  font: italic 600 1.5rem / 1.2 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
  color: var(--text-main);
}

.restart {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.restart-button {
  padding: 0.5rem 0;
  border: 0;
  background: none;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.restart-button:hover {
  color: var(--primary);
}

.restart-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.75rem;
  padding: 0.9rem 1rem;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-soft);
  background: var(--accent);
  animation: fade-up 300ms var(--ease-out) both;
}

.restart-confirm p {
  flex-basis: 100%;
  font-weight: 600;
}

.restart-yes,
.restart-no {
  min-height: 2.5rem;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-pill);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.restart-yes {
  border: 1.5px solid var(--primary);
  background: var(--primary);
  color: var(--accent);
}

.restart-no {
  border: 1.5px solid var(--accent-dark);
  background: var(--background);
  color: var(--text-main);
}

.fine-print {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.real-bread {
  justify-self: start;
  font: italic 600 1.15rem / 1.3 var(--font-display);
  color: var(--primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
  transition: text-underline-offset var(--duration-fast);
}

.real-bread:hover {
  text-underline-offset: 2px;
}

/* ── Mobile dock ──────────────────────────────────────────────────────── */

.dock {
  display: none;
}

@media (max-width: 899px) {
  .dock {
    position: fixed;
    right: 0.75rem;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
    left: 0.75rem;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.45rem 0.45rem 0.45rem 1.25rem;
    border-radius: var(--radius-pill);
    background: var(--primary);
    color: var(--accent);
    box-shadow: var(--shadow-lift);
    visibility: hidden;
    opacity: 0;
    transform: translateY(calc(100% + 1.5rem));
    transition:
      transform 380ms var(--ease-out),
      opacity 200ms,
      visibility 0s linear 380ms;
  }

  .dock.is-visible {
    visibility: visible;
    opacity: 1;
    transform: none;
    transition:
      transform 380ms var(--ease-out),
      opacity 200ms,
      visibility 0s;
  }
}

.dock-tally {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 1.15;
}

.dock-count {
  overflow: hidden;
  font: italic 600 1.35rem / 1.15 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.dock-rate {
  font-size: 0.75rem;
}

.dock-sack {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 3.5rem;
  height: 3.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--duration-fast) var(--ease-out);
}

.dock-sack:active {
  transform: scale(0.92);
}

.dock-sack svg {
  width: 72%;
  height: 72%;
}

.dock-sack:focus-visible {
  outline-color: var(--accent);
}

/* ── Motion ───────────────────────────────────────────────────────────── */

@keyframes rise {
  from {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
  to {
    opacity: 0;
    transform: translate(-50%, -200%);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }

  /* The "+1" still shows where you kneaded; it just doesn't drift. */
  .float {
    animation: none !important;
  }

  .sack:hover,
  .tool-button:hover {
    transform: none;
  }
}
