/* ==========================================================================
   Letter Rain — styles
   ========================================================================== */

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

:root {
  --paper: #F4F1EA;
  --ink: #1B1B18;
  --red: #C83C1A;
  --muted: #9A978F;
  --gold: #A87B20;
  --faint: rgba(27,27,24,.07);
  --focus: #1B1B18;

  /* Le Corbusier Polychromie Architecturale — point-value colours */
  --lc-20:  #39774f;  /* 32050  vert foncé              */
  --lc-30:  #69372b;  /* 4320D  terre sienne brûlée 59  */
  --lc-40:  #2f2624;  /* 4320J  terre d'ombre brûlée 59 */
  --lc-50:  #9c2128;  /* 32090  rouge vermillon 31       */
  --lc-80:  #559778;  /* 4320G  vert 59                  */
  --lc-100: #395a8e;  /* 4320K  bleu outremer 59         */
}

html { height: 100%; background: var(--paper); }
html, body { background: var(--paper); }

body {
  min-height: 100%;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  font-family: 'Barlow', sans-serif;
  color: var(--ink);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

#app {
  width: 100%;
  max-width: 390px;
  min-height: 100svh;
  position: relative;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0 60px rgba(0,0,0,.15);
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease, transform .28s ease;
  transform: translateY(10px);
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* Focus ring for keyboard users (using :focus-visible so mouse users don't see it) */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ==========================================================================
   INTRO
   ========================================================================== */
#screen-intro { align-items: center; justify-content: center; overflow: hidden; }

#rainCanvas { position: absolute; inset: 0; pointer-events: none; }

.rain-tile {
  position: absolute;
  top: -56px;
  display: flex; align-items: center; justify-content: center;
  width: 26px; height: 32px;
  border: 1px solid rgba(27,27,24,.22);
  background: var(--paper);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px; font-weight: 500;
  color: rgba(27,27,24,.4);
  animation: rainFall linear infinite;
}

@keyframes rainFall {
  0%   { transform: translateY(0); opacity: 0; }
  7%   { opacity: 1; }
  88%  { opacity: .85; }
  100% { transform: translateY(110vh); opacity: 0; }
}

.intro-card {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  padding: 44px 36px;
}

.intro-logo {
  font-size: 11px; font-weight: 700;
  letter-spacing: .28em; text-transform: uppercase;
  margin-bottom: 10px;
}

.intro-hed {
  font-size: 32px; font-weight: 300;
  line-height: 1.22;
  margin-bottom: 40px;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  background: var(--ink); color: var(--paper);
  border: none;
  padding: 16px 40px;
  font-family: 'Barlow', sans-serif;
  font-size: 12px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  cursor: pointer;
  transition: opacity .15s;
  -webkit-tap-highlight-color: transparent;
  display: inline-block; text-align: center;
}
.btn:active { opacity: .7; }
.btn.full { width: 100%; }

/* Outline variant — same shape as .btn, transparent fill + ink border.
   Used for secondary actions (e.g. View My Stats, Back). */
.btn.outline {
  background: transparent;
  color: var(--ink);
  border: 1.5px solid var(--ink);
  /* Compensate the 1.5px border on each side so outline buttons sit at the
     same height as their filled siblings. */
  padding: 14.5px 38.5px;
}

/* ==========================================================================
   ROUND PROGRESS BAR
   ========================================================================== */
.game-bar { display: flex; gap: 4px; padding: 14px 28px 0; }
.game-pip {
  flex: 1; height: 3px;
  background: rgba(27,27,24,.12);
  transition: background .3s;
}
.game-pip.done    { background: var(--ink); }
.game-pip.current { background: var(--muted); }

/* ==========================================================================
   GAME
   ========================================================================== */
#screen-game { display: flex; flex-direction: column; overflow: hidden; }

.game-head {
  padding: 14px 28px 12px;
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 1px solid var(--faint);
  flex-shrink: 0;
}
.game-round-name { font-size: 20px; font-weight: 600; line-height: 1; }
.pts-prev {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 27px; font-weight: 600; line-height: 1;
  text-align: right;
  color: rgba(27,27,24,.18);
  transition: color .2s;
}
.pts-prev.on { color: var(--ink); }
.gh-lbl {
  font-size: 9px; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-top: 3px; text-align: right;
}

/* Word zone -------------------------------------------------------------- */
.word-zone {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--faint);
  flex-shrink: 0;
}
.wz-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.wz-lbl {
  font-size: 9px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}
.wz-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; color: var(--muted);
}
.word-tiles {
  display: flex; gap: 4px;
  min-height: 56px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 2px;
}
.word-tiles::-webkit-scrollbar { display: none; }
.word-empty {
  font-size: 13px;
  color: rgba(154,151,143,.8);
  font-style: italic;
}

.wtile {
  width: 38px; height: 54px;
  border: 1.5px solid var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  cursor: grab;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  flex-shrink: 0;
  background: var(--paper);
  transition: opacity .15s;
}
.wtile.dragging { opacity: .25; }
.wtile.drag-over {
  border-color: var(--red);
  background: rgba(200,60,26,.05);
}
.wtile .wl { font-size: 23px; font-weight: 500; line-height: 1; }
.wtile .wv { font-size: 10px; font-weight: 700; color: var(--ink); margin-top: 2px; }

.wz-hint-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 8px;
  min-height: 17px;
}
.w-hint { font-size: 11px; color: var(--muted); transition: color .18s; }
.w-hint.ok  { color: var(--ink); font-weight: 500; }
.w-hint.bad { color: var(--red); }
.w-bonus    { font-size: 10px; color: #0e2d58; font-weight: 600; }

/* Rack ------------------------------------------------------------------- */
.rack-zone { flex: 1; padding: 12px 18px 6px; overflow-y: auto; }
.rack-lbl {
  font-size: 9px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
}
.rack-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
}

.rtile {
  /* Reset button defaults */
  appearance: none;
  background: var(--paper);
  font: inherit;
  color: inherit;
  margin: 0;

  aspect-ratio: 1;
  border: 1.5px solid var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: background .14s, border-color .14s;
  position: relative;
}
.rtile[disabled] { cursor: default; }
.rtile .rl { font-size: 28px; font-weight: 500; line-height: 1; }
.rtile .rv { font-size: 12px; font-weight: 700; color: var(--ink); margin-top: 3px; }

.rtile.drag-over {
  border-color: var(--red);
  background: rgba(200,60,26,.06);
}
.rtile.rack-dragging { opacity: .18; }
.rtile.sel {
  background: rgba(27,27,24,.09);
  border-color: rgba(27,27,24,.3);
}
.rtile.sel .rl, .rtile.sel .rv { opacity: .32; }
.rtile.sel::after {
  content: '';
  position: absolute; top: 5px; right: 5px;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--ink);
  opacity: .45;
}

/* Round-transition lockout — block input while the rack is animating */
#screen-game.transitioning .rack-tiles,
#screen-game.transitioning #wordTiles,
#screen-game.transitioning .game-foot {
  pointer-events: none;
}
#screen-game.transitioning .game-foot { opacity: .5; }



.game-foot {
  padding: 10px 18px 28px;
  border-top: 1px solid var(--faint);
  display: flex; gap: 8px;
  flex-shrink: 0;
}
.btn-clr {
  width: 88px;
  padding: 13px 8px;
  border: 1.5px solid var(--ink);
  background: transparent;
  font-family: 'Barlow', sans-serif;
  font-size: 11px; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  cursor: pointer;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.btn-clr:active { opacity: .6; }

.btn-sub {
  flex: 1;
  padding: 13px;
  background: var(--ink); color: var(--paper);
  border: none;
  font-family: 'Barlow', sans-serif;
  font-size: 12px; font-weight: 600;
  letter-spacing: .13em; text-transform: uppercase;
  cursor: pointer;
  opacity: .22;
  transition: opacity .18s;
  -webkit-tap-highlight-color: transparent;
}
.btn-sub.go     { opacity: 1; }
.btn-sub:active { opacity: .7; }

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  width: 38px; height: 54px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'IBM Plex Mono', monospace;
  box-shadow: 0 8px 28px rgba(0,0,0,.28);
}
.drag-ghost .wl { font-size: 18px; font-weight: 500; color: var(--paper); line-height: 1; }
.drag-ghost .wv { font-size: 8px; color: rgba(244,241,234,.45); margin-top: 2px; }

.drag-ghost.tile-ghost {
  background: var(--paper);
  border-color: var(--ink);
}
.drag-ghost.tile-ghost .wl { font-size: 28px; color: var(--ink); }
.drag-ghost.tile-ghost .wv { font-size: 11px; font-weight: 700; color: var(--ink); }

/* Point-value colours — Le Corbusier Polychromie Architecturale */
.rtile .rv.v0,  .wtile .wv.v0  { color: var(--muted); }
.rtile .rv.v20, .wtile .wv.v20 { color: var(--lc-20); }
.rtile .rv.v30, .wtile .wv.v30 { color: var(--lc-30); }
.rtile .rv.v40, .wtile .wv.v40 { color: var(--lc-40); }
.rtile .rv.v50, .wtile .wv.v50 { color: var(--lc-50); }
.rtile .rv.v80, .wtile .wv.v80 { color: var(--lc-80); }
.rtile .rv.v100,.wtile .wv.v100{ color: var(--lc-100);}
/* Ghost inherits the same value colours */
.drag-ghost .wv.v0   { color: var(--muted); }
.drag-ghost .wv.v20  { color: var(--lc-20); }
.drag-ghost .wv.v30  { color: var(--lc-30); }
.drag-ghost .wv.v40  { color: var(--lc-40); }
.drag-ghost .wv.v50  { color: var(--lc-50); }
.drag-ghost .wv.v80  { color: var(--lc-80); }
.drag-ghost .wv.v100 { color: var(--lc-100); }

/* ==========================================================================
   GAME SUMMARY
   ========================================================================== */
.summary-head {
  padding: 40px 28px 24px;
  border-bottom: 1px solid var(--faint);
  position: relative;
  overflow: hidden;
}
.summary-sun {
  position: absolute;
  top: -10px; right: -18px;
  width: 130px; height: 130px;
  opacity: .18;
}
.summary-logo {
  font-size: 11px; font-weight: 700;
  letter-spacing: .25em; text-transform: uppercase;
  margin-bottom: 6px;
}
.summary-eyebrow {
  font-size: 11px; color: var(--muted);
  letter-spacing: .1em; text-transform: uppercase;
  margin-bottom: 12px;
}
.summary-total {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 68px; font-weight: 600;
  line-height: 1;
  margin-bottom: 4px;
}
.summary-total-lbl {
  font-size: 13px; color: var(--muted); font-weight: 300;
}

.summary-body { padding: 24px 28px; }

.summary-rounds {
  border-top: 1px solid var(--faint);
  margin-bottom: 24px;
}
.summary-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--faint);
}
.summary-round {
  font-size: 10px; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
  width: 90px; flex-shrink: 0;
}
.summary-word {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 17px; font-weight: 500;
  text-transform: uppercase;
  flex: 1;
  padding: 0 8px;
}
.summary-pts {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px; color: var(--muted);
}
.summary-pts.best { color: var(--ink); font-weight: 600; }

/* Gap between Share Game and View My Stats is half a button height. */
.summary-btns { display: flex; flex-direction: column; gap: 24px; }

/* Flex spacer — absorbs remaining vertical space and centres the foot text
   halfway between the last button and the feedback link. */
.summary-lower {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 56px; /* offset for the absolute feedback-btn */
}

.summary-foot {
  text-align: center;
  font-size: 13px; color: var(--ink);
  line-height: 1.7;
  padding: 0 28px;
}

/* Ghost buttons (Rules / Feedback) */
.ghost-btn {
  display: block;
  background: none;
  border: none;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  padding: 8px 24px 36px;
  width: 100%;
  letter-spacing: .03em;
  -webkit-tap-highlight-color: transparent;
}
.ghost-btn:active { opacity: .5; }

.rules-btn {
  position: absolute;
  bottom: 0; left: 0; right: 0;
}

/* "Rules of the Game · Privacy" row at the bottom of the intro screen */
.intro-links {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
}
.intro-links .ghost-btn { width: auto; padding-left: 16px; padding-right: 16px; }
.intro-links-sep {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  padding-bottom: 36px; /* aligns vertically with the ghost-btn padding */
  line-height: 1;
  display: flex;
  align-items: flex-end;
}

.feedback-btn {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding-bottom: 36px;
}

/* Rules modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(27,27,24,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
  background: var(--paper);
  border: 1.5px solid var(--ink);
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 32px 28px 28px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 14px; right: 18px;
  background: none;
  border: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
}

.modal-title {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0 0 20px;
}

.modal-body p {
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink);
  margin: 0 0 14px;
}
.modal-body p:last-child { margin-bottom: 0; }

/* ==========================================================================
   STATS
   ========================================================================== */
#screen-stats { display: flex; flex-direction: column; }

/* Eyebrow label shared by every stats section */
.stats-lbl {
  font-size: 9px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}

/* Header bar */
.stats-head {
  padding: 20px 28px 14px;
  border-bottom: 1px solid var(--faint);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.stats-logo {
  font-size: 11px; font-weight: 700;
  letter-spacing: .25em; text-transform: uppercase;
  color: var(--ink);
}
.stats-eyebrow {
  font-size: 9px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted);
}

/* Hero — current streak */
.stats-hero {
  padding: 32px 28px 24px;
  border-bottom: 1px solid var(--faint);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.stats-sun {
  position: absolute;
  top: -8px; right: -16px;
  width: 120px; height: 120px;
  opacity: .14;
}
.stats-hero .stats-lbl { margin-bottom: 8px; }
.stats-streak {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 80px; font-weight: 600;
  line-height: .9;
  color: var(--ink);
}
.stats-streak-sub {
  font-size: 13px; color: var(--muted);
  margin-top: 6px;
}

/* 2x2 stat grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--faint);
  flex-shrink: 0;
}
.stats-cell { padding: 18px 18px 16px; }
.stats-cell.border-r { border-right:  1px solid var(--faint); }
.stats-cell.border-b { border-bottom: 1px solid var(--faint); }
.stats-cell .stats-lbl { margin-bottom: 6px; }
.stats-val {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 32px; font-weight: 600;
  line-height: 1;
}
.stats-unit {
  font-size: 10px; color: var(--muted);
  letter-spacing: .04em;
  margin-top: 4px;
}
/* Best-word cell — word + score · date sub-line, no separate unit */
.stats-word {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 22px; font-weight: 600;
  line-height: 1;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.stats-word-meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; color: var(--ink);
  margin-top: 5px;
  min-height: 11px;
}
.stats-word-meta .dim { color: var(--muted); }

/* 14-day chart */
.stats-chart {
  padding: 18px 28px 12px;
  flex: 1;
}
.stats-chart-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 14px;
}
.stats-chart-range {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px; color: var(--muted);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}
.stats-chart-svg svg { display: block; overflow: visible; }
.sc-avg-lbl,
.sc-x-lbl {
  font-family: 'IBM Plex Mono', monospace;
  fill: var(--muted);
}
.sc-avg-lbl { font-size: 8px; }
.sc-x-lbl   { font-size: 8.5px; }
.sc-x-lbl.red { fill: var(--red); font-weight: 600; }

/* Footer (Back button) */
.stats-foot {
  padding: 10px 28px 26px;
  border-top: 1px solid var(--faint);
  flex-shrink: 0;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%      { transform: translateX(-7px); }
  40%      { transform: translateX(7px); }
  60%      { transform: translateX(-4px); }
  80%      { transform: translateX(4px); }
}
.shaking { animation: shake .36s ease; }

@keyframes rackPop {
  0%   { transform: scale(.85); opacity: .4; }
  60%  { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.rtile.shuffling {
  animation: rackPop .22s cubic-bezier(.34,1.56,.64,1) forwards;
}

/* Tile drops into the word zone when a letter is added */
@keyframes tileDrop {
  0%   { transform: translateY(-60px) scale(.85); opacity: 0; }
  60%  { transform: translateY(4px) scale(1.04); opacity: 1; }
  78%  { transform: translateY(-2px) scale(.99); }
  100% { transform: translateY(0) scale(1); opacity: 1; }
}
.wtile.raining {
  animation: tileDrop .42s cubic-bezier(.34,1.56,.64,1) forwards;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
