/* ==========================================================================
   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;
}

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: rgba(244,241,234,.55);
  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%; }

/* ==========================================================================
   WEEK PROGRESS BAR
   ========================================================================== */
.week-bar { display: flex; gap: 4px; padding: 14px 28px 0; }
.week-pip {
  flex: 1; height: 3px;
  background: rgba(27,27,24,.12);
  transition: background .3s;
}
.week-pip.done    { background: var(--ink); }
.week-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-day-lbl {
  font-size: 11px; font-weight: 700;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 2px;
}
.game-day-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: 12px;
  color: rgba(154,151,143,.5);
  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; color: var(--muted); 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: var(--red); 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: transparent;
  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;
  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: 11px; color: var(--muted); 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;
}

.rtile.gold        { border-color: var(--gold); }
.rtile.gold .rl    { color: var(--gold); }
.rtile.gold .rv    { color: var(--gold); opacity: .7; }

.rtile.carry-t     { border: 1.5px dashed rgba(27,27,24,.3); }
.rtile.carry-t .rl { color: var(--muted); }

.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; }

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

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

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

.week-btns { display: flex; flex-direction: column; gap: 9px; }

.week-foot {
  text-align: center;
  font-size: 12px; color: var(--ink);
  line-height: 1.7;
  padding: 8px 28px 44px;
}

/* ==========================================================================
   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;
  }
}
