/* ==========================================================================
 * game.css — Board, keyboard, overlays
 *
 * Visual language matches the CR Coffee Design System: cream ground,
 * charcoal type, hairline borders, square corners. Playfair Display
 * carries editorial headlines, Inter handles body + UI, JetBrains Mono
 * does the all-caps eyebrows.
 * ========================================================================== */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--cr-red); color: #fff; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

/* The full fireplace photo lives behind the page content, with a cream
 * gradient fading it from R bottom downward so the board sits on a
 * washed-out version of the cavity instead of the full-saturation image. */
#app {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background-image:
    linear-gradient(180deg,
      rgba(250, 248, 245, 0) 0%,
      rgba(250, 248, 245, 0) 42%,
      rgba(250, 248, 245, 0.45) 55%,
      rgba(250, 248, 245, 0.85) 70%,
      var(--bg) 85%),
    url('../assets/img/fireplace.jpg');
  background-size: 100% auto, 100% auto;
  background-position: center top, center top;
  background-repeat: no-repeat, no-repeat;
  background-color: var(--bg);
}

/* ==========================================================================
 * Header — sticky, hairline-divided, monogram + serif title
 * ========================================================================== */

/* Sticky header — Daily Grind title on the left, action icons on the
 * right. Both overlay the CR sign area of the photo in white. */
.app-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-md) var(--space-sm);
  background: linear-gradient(180deg,
    rgba(0, 0, 0, 0.55) 0%,
    rgba(0, 0, 0, 0.2) 70%,
    rgba(0, 0, 0, 0) 100%);
}

.app-header__title {
  margin: 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(1.625rem, 1.2rem + 2vw, 2.25rem);
  letter-spacing: -0.01em;
  line-height: 1;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.8);
}

.app-header__actions {
  display: flex;
  gap: var(--space-xs);
}

/* ==========================================================================
 * Masthead — CR Coffee Shop logo + "The Daily Grind" subtitle
 *
 * The brand identity is the logo image (Cafe Brewery is rendered into it).
 * Editorial type underneath identifies this specific experience without
 * trying to mimic the unlicensed display font.
 * ========================================================================== */

/* Masthead is gone — the title moved into the sticky header.
 * Empty space above the board (board-wrap padding) reveals the CR sign
 * and wooden mantel from the photo. */

.app-header__actions {
  display: flex;
  gap: var(--space-xs);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  font-family: var(--font-sans);
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  transition: background-color var(--transition-base), border-color var(--transition-base);
}
.icon-btn:hover,
.icon-btn:focus-visible {
  background: rgba(0, 0, 0, 0.5);
  border-color: #fff;
  outline: none;
}

/* ==========================================================================
 * Eyebrow above the board — sets the editorial tone
 * ========================================================================== */

.board-eyebrow {
  text-align: center;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  margin: 0;
}

/* ==========================================================================
 * Board
 * ========================================================================== */

/* The board starts right below the R of the CR sign in the fireplace
 * photo. Photo positioning under background-size: cover differs by
 * viewport aspect: on portrait phones the photo fits height-exactly so
 * CR ends at ~39vh; on landscape/desktop the photo overflows vertically
 * so CR ends at ~58vh. We use a media query to put the board in the
 * right spot for each case. */
/* Board lands where the R of CR ends in the photo, sitting visually
 * inside the wooden cavity. The photo is positioned via the #app
 * background (100% width, natural aspect), so R bottom is at ~52% of
 * #app width. Padding-top targets that minus the header height. */
.board-wrap {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: calc(52% - 56px) var(--side-pad-min) var(--space-md);
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, var(--tile-size));
  grid-template-rows: repeat(6, var(--tile-size));
  gap: var(--tile-gap);
  width: var(--board-width);
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-sans);
  font-weight: 800;
  font-size: calc(var(--tile-size) * 0.48);
  text-transform: uppercase;
  letter-spacing: 0;
  border: 2px solid var(--tile-empty-border);
  background: transparent;
  color: var(--fg-strong);
  user-select: none;
  border-radius: 0;
  transition: transform 80ms ease, border-color var(--transition-base), background-color var(--transition-base);
}
.tile.is-typed {
  border-color: var(--fg-strong);
  background: transparent;
  animation: tile-pop 120ms ease;
}
.tile.is-correct {
  background: var(--tile-correct);
  border-color: var(--tile-correct);
  color: var(--tile-text-revealed);
}
.tile.is-present {
  background: var(--tile-present);
  border-color: var(--tile-present);
  color: var(--tile-text-revealed);
}
.tile.is-absent {
  background: var(--tile-absent);
  border-color: var(--tile-absent);
  color: var(--tile-text-revealed);
}
.tile.is-revealing {
  animation: tile-flip 600ms ease;
  animation-fill-mode: forwards;
}
.tile.is-win {
  animation: tile-bounce 600ms ease;
}

@keyframes tile-pop {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.06); }
  100% { transform: scale(1); }
}
@keyframes tile-flip {
  0%   { transform: rotateX(0); }
  45%  { transform: rotateX(90deg); }
  55%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}
@keyframes tile-bounce {
  0%   { transform: translateY(0); }
  20%  { transform: translateY(-20px); }
  50%  { transform: translateY(0); }
  70%  { transform: translateY(-10px); }
  100% { transform: translateY(0); }
}

.row.is-invalid .tile { animation: row-shake 420ms ease; }
@keyframes row-shake {
  0%, 100% { transform: translateX(0); }
  15%      { transform: translateX(-8px); }
  30%      { transform: translateX(8px); }
  45%      { transform: translateX(-6px); }
  60%      { transform: translateX(6px); }
  75%      { transform: translateX(-3px); }
  90%      { transform: translateX(3px); }
}

/* ==========================================================================
 * Toast — appears above the board
 * ========================================================================== */

.toast {
  position: absolute;
  top: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  background: var(--cr-ink);
  color: var(--cr-cream);
  padding: 12px 18px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--text-sm);
  letter-spacing: 0.02em;
  border-radius: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
  z-index: 10;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.is-visible { opacity: 1; }

/* ==========================================================================
 * Keyboard — square keys, hairline borders, no shadows
 * ========================================================================== */

.keyboard {
  padding: var(--space-md) var(--space-sm) var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--key-gap);
  align-items: center;
  background: var(--bg);
}
.keyboard__row {
  display: flex;
  gap: var(--key-gap);
  width: 100%;
  max-width: 500px;
  justify-content: center;
}
.key {
  flex: 1 1 0;
  min-width: 0;
  height: var(--key-height);
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--text-md);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: var(--bg-panel);
  color: var(--fg-strong);
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--transition-base), color var(--transition-base);
}
.key:active { transform: scale(0.96); }
.key:hover,
.key:focus-visible {
  background: var(--cr-parchment);
  outline: none;
}
.key.key--wide {
  flex: 1.5 1 0;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
}
.key.is-correct {
  background: var(--tile-correct);
  color: var(--tile-text-revealed);
  border-color: var(--tile-correct);
}
.key.is-present {
  background: var(--tile-present);
  color: var(--tile-text-revealed);
  border-color: var(--tile-present);
}
.key.is-absent {
  background: var(--tile-absent);
  color: var(--tile-text-revealed);
  border-color: var(--tile-absent);
}

/* ==========================================================================
 * Footer — Million Dollar Red CTA, tagline, hairline divider
 * ========================================================================== */

.app-footer {
  padding: var(--space-md) var(--space-md) var(--space-lg);
  text-align: center;
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.footer-cta {
  display: inline-block;
  background: var(--cr-red);
  color: #fff;
  text-decoration: none;
  padding: 12px 28px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  border-radius: 0;
  transition: background-color var(--transition-base);
}
.footer-cta:hover,
.footer-cta:focus-visible {
  background: var(--cr-red-hover);
  outline: none;
}
.footer-tagline {
  margin: var(--space-sm) 0 0;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--text-sm);
  color: var(--fg-muted);
}
.footer-meta {
  margin: var(--space-xs) 0 0;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

/* ==========================================================================
 * Overlay — modals: how-to-play, stats, settings
 * ========================================================================== */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(250, 248, 245, 0.98);
  z-index: 100;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.overlay[hidden] { display: none; }

.overlay__inner {
  width: 100%;
  max-width: 460px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--space-xl) var(--space-lg);
  margin: var(--space-lg) auto;
  position: relative;
}

.overlay__close {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: var(--text-xl);
  color: var(--fg-muted);
  cursor: pointer;
  line-height: 1;
}
.overlay__close:hover { color: var(--cr-red); }

.overlay__eyebrow {
  margin: 0 0 var(--space-xs);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--fg-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.overlay__title {
  margin: 0 0 var(--space-md);
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: var(--text-3xl);
  line-height: 1.1;
  letter-spacing: -0.01em;
  color: var(--fg-strong);
}
.overlay__subtitle {
  margin: 0 0 var(--space-md);
  font-family: var(--font-serif);
  font-style: italic;
  font-size: var(--text-lg);
  line-height: 1.5;
  color: var(--fg);
}
.overlay__body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.7;
  color: var(--fg);
  margin: 0 0 var(--space-md);
}
.overlay__body strong { font-weight: 600; color: var(--fg-strong); }

.overlay__divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: var(--space-lg) 0;
}

.overlay__example {
  display: grid;
  grid-template-columns: repeat(5, 40px);
  gap: 4px;
  margin: var(--space-sm) 0 var(--space-md);
}
.overlay__example .tile {
  width: 40px;
  height: 40px;
  font-size: 22px;
}

/* ==========================================================================
 * Stats — distribution chart + countdown
 * ========================================================================== */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  margin: var(--space-md) 0 var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}
.stats__cell {
  text-align: center;
}
.stats__cell strong {
  display: block;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: var(--text-2xl);
  color: var(--fg-strong);
  line-height: 1.1;
}
.stats__cell span {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  color: var(--fg-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.distribution {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: var(--space-md) 0;
}
.distribution__row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}
.distribution__label {
  width: 14px;
  text-align: right;
  color: var(--fg-muted);
  font-weight: 700;
}
.distribution__bar {
  flex: 1;
  background: var(--bg-panel);
  border-radius: 0;
  overflow: hidden;
  height: 22px;
  position: relative;
}
.distribution__fill {
  background: var(--tile-absent);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 28px;
  transition: width 320ms ease;
}
.distribution__fill.is-current {
  background: var(--tile-correct);
}

.countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: var(--space-md);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 0;
  margin: var(--space-md) 0;
}
.countdown__label {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--fg-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.countdown__time {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: var(--text-2xl);
  font-variant-numeric: tabular-nums;
  color: var(--fg-strong);
  letter-spacing: 0.02em;
}

/* ==========================================================================
 * Buttons (overlay CTAs) — square, no shadows, brand-red primary
 * ========================================================================== */

.btn-row {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}
.btn {
  flex: 1;
  padding: 14px 18px;
  background: var(--cr-red);
  color: #fff;
  border: 1px solid var(--cr-red);
  border-radius: 0;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color var(--transition-base);
}
.btn:hover,
.btn:focus-visible { background: var(--cr-red-hover); border-color: var(--cr-red-hover); outline: none; }

.btn--ghost {
  background: transparent;
  color: var(--fg-strong);
  border: 1px solid var(--border-strong);
}
.btn--ghost:hover,
.btn--ghost:focus-visible {
  background: var(--bg-panel);
  border-color: var(--fg-strong);
}

/* ==========================================================================
 * Settings rows
 * ========================================================================== */

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  border-top: 1px solid var(--border);
  gap: var(--space-md);
}
.settings-row:first-of-type { border-top: 0; }
.settings-row__label {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--fg-strong);
}
.settings-row__hint {
  display: block;
  margin-top: 4px;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  font-weight: 400;
}
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--transition-base);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 1px;
  width: 20px;
  height: 20px;
  background: var(--cr-cream);
  border: 1px solid var(--border-strong);
  transition: transform var(--transition-base);
}
.toggle.is-on { background: var(--tile-correct); border-color: var(--tile-correct); }
.toggle.is-on::after { transform: translateX(20px); border-color: var(--tile-correct); }

/* ==========================================================================
 * Reduced motion
 * ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .tile.is-revealing, .tile.is-win, .tile.is-typed {
    animation: none;
  }
  .row.is-invalid .tile { animation: none; }
}
