:root {
  --cream:     #fff4e0;
  --cream-2:   #ffe9c5;
  --ink:       #181227;
  --ink-50:    #4a4264;
  --ink-30:    #8a829e;
  --ink-line:  rgba(24, 18, 39, .12);
  --pink:      #ff3d7f;
  --pink-deep: #c41858;
  --pink-soft: #ffe1ec;
  --yellow:    #ffd93d;
  --yellow-soft:#fff3b8;
  --gold-deep: #92580c;
  --mint:      #5ad9a8;
  --coral:     #ff7755;
  --bonus:     #2fb88a;
  --tile-bg:   #fff4e0;
  --tile-size: 64px;
  --br:        12px;
  --serif: 'Fraunces',Georgia,serif;
  --sans:  'DM Sans',system-ui,sans-serif;
  --mono:  'JetBrains Mono',ui-monospace,monospace;
}
[data-theme="dark"] {
  --cream:    #1c1829;
  --cream-2:  #281f3d;
  --ink:      #ede4d8;
  --ink-50:   #b0a8c4;
  --ink-30:   #6a6282;
  --ink-line: rgba(237, 228, 216, .15);
  --pink:     #ff6ba0;
  --pink-deep:#ff3d7f;
  --pink-soft:#3a1f2e;
  --yellow-soft:#3a2e1a;
  --gold-deep:#ffb84d;
  --mint:     #4ecf9e;
  --coral:    #ff8866;
  --bonus:    #4ecf9e;
  --tile-bg:  #281f3d;
}

*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
html, body {
  position: fixed; inset: 0; width: 100%; height: 100%;
  overflow: hidden; overscroll-behavior: none; touch-action: none;
  background: var(--cream); color: var(--ink);
  font-family: var(--sans); -webkit-font-smoothing: antialiased;
  -webkit-user-select: none; user-select: none;
}
button, .icon-btn, #done, a { touch-action: manipulation; }
html { transition: background-color .25s, color .25s; }
.tile, .wr-sheet, .wr-sheet-head, .wr-sheet-body, .breakdown, .instruct-step, header,
.puzzle-pill, .icon-btn, .word-chip, #done, .score-sticker, .wr-close, #loadVeil {
  transition: background-color .25s, border-color .25s, color .25s, opacity .2s;
}

header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  padding: max(env(safe-area-inset-top), 12px) 14px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--cream);
  pointer-events: none;
}
header .puzzle-pill,
header .icon-btn { pointer-events: auto; }
.brand {
  font-family: var(--serif); font-weight: 900; font-size: 22px;
  letter-spacing: -.03em; display: flex; align-items: center; gap: 7px; line-height: 1;
}
.brand-mark {
  width: 24px; height: 24px; background: var(--pink); border: 2px solid var(--ink);
  border-radius: 6px; transform: rotate(-8deg); flex-shrink: 0; position: relative;
}
.brand-mark::before {
  content: 'W'; position: absolute; inset: 0; text-align: center; line-height: 20px;
  font-family: var(--serif); font-weight: 900; font-size: 14px; color: #fff;
}
.top-actions { display: flex; gap: 6px; align-items: center; }

.puzzle-pill {
  font-family: var(--mono); font-size: 10px; color: var(--ink-50);
  padding: 0 11px; background: var(--cream-2); border: 2px solid var(--ink);
  border-radius: 999px; line-height: 1; white-space: nowrap;
  height: 28px; display: flex; align-items: center; gap: 6px;
}
.puzzle-pill strong {
  color: var(--ink); font-weight: 700;
  font-family: var(--mono); font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.puzzle-pill .pill-link {
  color: var(--ink); text-decoration: none; font-weight: 700;
  border-bottom: 1.5px solid var(--ink);
}
.puzzle-pill .pill-link:active { opacity: .7; }
.puzzle-pill .countdown {
  font-variant-numeric: tabular-nums; min-width: 56px; display: inline-block;
}

.icon-btn {
  width: 28px; height: 28px;
  border: 2px solid var(--ink); background: var(--cream);
  border-radius: 50%; cursor: pointer; color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  padding: 0; flex-shrink: 0;
}
.icon-btn:active { background: var(--cream-2); }
.icon-btn svg { display: block; }
.icon-btn.help-btn {
  font-family: var(--serif); font-weight: 900; font-size: 15px; line-height: 1;
  padding-bottom: 1px;
}

#viewport {
  position: fixed; top: 0; bottom: 0; left: 0; right: 0;
  overflow: hidden; touch-action: none; cursor: grab;
}
#viewport.panning { cursor: grabbing; }
#board {
  position: absolute; width: 5000px; height: 5000px; will-change: transform;
}

.tile {
  position: absolute; width: var(--tile-size); height: var(--tile-size);
  background: var(--tile-bg); border: 2.5px solid var(--ink); border-radius: var(--br);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 900; font-size: 30px; color: var(--ink);
  cursor: grab; touch-action: none; z-index: 10; -webkit-touch-callout: none;
}
.tile.dragging { cursor: grabbing; z-index: 500; box-shadow: 0 8px 28px rgba(0, 0, 0, .22); }
.tile.snapping {
  transition: left .22s cubic-bezier(.34, 1.56, .64, 1),
              top  .22s cubic-bezier(.34, 1.56, .64, 1);
}
.tile.valid   { background: var(--mint); color: var(--ink); }
.tile.invalid { background: var(--coral); color: var(--ink); }
.tile.locked  { cursor: default; pointer-events: none; }

/* Dark mode: when a tile is mint or coral, the letter goes black for contrast */
[data-theme="dark"] .tile.valid,
[data-theme="dark"] .tile.valid *,
[data-theme="dark"] .tile.invalid,
[data-theme="dark"] .tile.invalid * { color: #181227 !important; }

/* Special tiles — neutral uses a tinted fill; valid/invalid take the standard
   mint/coral fill and reveal the corner badge defined below. */
.tile.tile-wild {
  background: var(--pink-soft);
  border-color: var(--pink-deep);
  color: var(--pink-deep);
}
.tile.tile-lucky {
  background: var(--yellow-soft);
  border-color: var(--gold-deep);
  color: var(--gold-deep);
}
.tile.tile-wild.valid,
.tile.tile-lucky.valid {
  background: var(--mint);
  border-color: var(--ink);
  color: var(--ink);
}
.tile.tile-wild.invalid,
.tile.tile-lucky.invalid {
  background: var(--coral);
  border-color: var(--ink);
  color: var(--ink);
}

/* Corner badge — flat, only appears when the tile is part of a valid or invalid word.
   Wild shows "?". Lucky shows a 4-pointed star rotated 45° so it reads as ×3. */
.tile.tile-wild .badge,
.tile.tile-lucky .badge {
  position: absolute;
  top: -9px; right: -9px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--ink);
  display: none;
  align-items: center; justify-content: center;
  font-family: var(--serif); font-weight: 900; font-size: 15px; line-height: 1;
  z-index: 3;
  pointer-events: none;
}
.tile.tile-wild.valid .badge,
.tile.tile-wild.invalid .badge,
.tile.tile-lucky.valid .badge,
.tile.tile-lucky.invalid .badge {
  display: flex;
  animation: badge-pop 0.28s cubic-bezier(.34, 1.56, .64, 1);
}
.tile.tile-wild  .badge { background: var(--pink);   color: #fff; }
.tile.tile-lucky .badge { background: var(--yellow); }
.tile.tile-lucky .badge svg { width: 15px; height: 15px; display: block; transform: rotate(45deg); }
.tile.tile-lucky .badge svg polygon { fill: #181227; }
@keyframes badge-pop {
  0%   { transform: scale(0) rotate(-25deg); }
  70%  { transform: scale(1.18) rotate(6deg); }
  100% { transform: scale(1) rotate(0); }
}

.instruct-tile {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: var(--tile-bg);
  border: 2.5px solid var(--ink); border-radius: 7px;
  font-family: var(--serif); font-weight: 900; font-size: 18px;
  color: var(--ink); line-height: 1;
  flex-shrink: 0; margin-top: -1px;
}
.instruct-tile.wild  { background: var(--pink-soft);   border-color: var(--pink-deep);  color: var(--pink-deep); }
.instruct-tile.lucky { background: var(--yellow-soft); border-color: var(--gold-deep); color: var(--gold-deep); }

.score-sticker {
  position: fixed; top: 60px; right: 12px;
  width: 64px; height: 64px;
  background: var(--yellow); border: 2.5px solid var(--ink); border-radius: 50%;
  transform: rotate(-8deg) scale(0); z-index: 150; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; line-height: 1;
  color: #181227;
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
.score-sticker.show  { transform: rotate(-8deg) scale(1); }
.score-sticker .num  { font-family: var(--serif); font-weight: 900; font-size: 24px; letter-spacing: -.04em; color: inherit; }
.score-sticker .lbl  { font-family: var(--sans); font-size: 8px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; margin-top: 1px; color: inherit; }
body.locked .score-sticker { pointer-events: auto; cursor: pointer; }
body.locked .score-sticker:active { transform: rotate(-8deg) scale(.94); }

#done {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom), 16px);
  right: 16px;
  z-index: 200;
  font-family: var(--sans); font-weight: 700; font-size: 14px;
  padding: 11px 22px; border: 2.5px solid var(--ink); border-radius: 999px;
  background: var(--pink); color: #fff; cursor: pointer; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18);
}
#done:active   { opacity: .85; }
#done:disabled { background: var(--cream-2); color: var(--ink-30); cursor: not-allowed; box-shadow: none; }

.wr-curtain {
  position: fixed; inset: 0; background: rgba(24, 18, 39, .6);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px;
  touch-action: auto;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .22s ease, visibility .22s;
}
.wr-curtain.open { opacity: 1; visibility: visible; pointer-events: auto; }

.wr-sheet {
  position: relative;
  background: var(--cream); border: 2.5px solid var(--ink); border-radius: 24px;
  max-width: 420px; width: 100%; max-height: calc(100dvh - 32px);
  overflow: hidden; display: flex; flex-direction: column;
  opacity: 0; transform: translateY(14px) scale(.97);
  transition: opacity .28s cubic-bezier(.32, .72, .36, 1),
              transform .28s cubic-bezier(.32, .72, .36, 1);
}
.wr-curtain.open .wr-sheet { opacity: 1; transform: none; }

.wr-sheet-head {
  position: relative;
  padding: 18px 20px 14px; background: var(--cream-2);
  border-bottom: 2px solid var(--ink); text-align: center;
}
.wr-sheet-head h2 { font-family: var(--serif); font-weight: 900; font-size: 26px; letter-spacing: -.03em;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; }
.wr-sheet-head p  { font-size: 13px; color: var(--ink-50); margin-top: 3px; }

/* Special-day badge in the end-modal title (matches the in-game corner badge) */
.title-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 2.5px solid var(--ink);
  font-family: var(--serif); font-weight: 900; font-size: 17px; line-height: 1;
  transform: rotate(-8deg); flex-shrink: 0;
}
.title-badge.wild  { background: var(--pink);   color: #fff; }
.title-badge.lucky { background: var(--yellow); color: var(--ink); }
.title-badge svg { width: 17px; height: 17px; display: block; transform: rotate(45deg); }
.title-badge svg polygon { fill: #181227; }

.wr-close {
  position: absolute; top: 12px; right: 12px;
  width: 28px; height: 28px;
  border: 2px solid var(--ink); background: var(--cream);
  color: var(--ink); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer;
  transition: background-color .15s, transform .08s;
}
.wr-close:active { background: var(--cream-2); transform: scale(.94); }
.wr-close svg    { display: block; }

.wr-sheet-body {
  padding: 18px 20px; overflow-y: auto; flex: 1;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
}

.final-score-row {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 16px;
}
.final-score-sticker {
  position: relative;
  flex: 0 0 auto;
  width: 168px; height: 168px;
  background: var(--yellow); border: 2.5px solid var(--ink); border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; line-height: 1;
  color: #181227;
  transform: rotate(-4deg) scale(0);
  transition: transform .42s cubic-bezier(.34, 1.56, .64, 1);
  cursor: default;
  box-shadow: none;
}
.final-score-sticker.show { transform: rotate(-4deg) scale(1); }
.final-score-sticker .num {
  font-family: var(--serif); font-weight: 900; font-size: 64px;
  letter-spacing: -.05em; color: inherit; line-height: 1;
}
.final-score-sticker .lbl {
  font-family: var(--sans); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .18em; margin-top: 7px; color: inherit;
}
.final-score-sticker .sticker-sparkle {
  position: absolute; top: 12px; right: 14px;
  color: var(--ink);
  opacity: 0;
  transform: rotate(8deg) scale(.4);
  transition: opacity .35s ease .25s, transform .55s cubic-bezier(.34, 1.56, .64, 1) .25s;
  pointer-events: none;
}
.final-score-sticker.show .sticker-sparkle {
  opacity: 1;
  transform: rotate(8deg) scale(1);
}
.final-score-row .word-chips {
  flex: 1 1 auto; margin-bottom: 0;
  justify-content: flex-end;
}

.playable-note {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-30);
  text-align: center;
  letter-spacing: .02em;
}

.word-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; justify-content: center; }
.word-chip {
  font-family: var(--mono); font-weight: 700; font-size: 12px;
  padding: 4px 10px; border: 2px solid var(--ink); border-radius: 999px;
  letter-spacing: .04em; line-height: 1;
}
.word-chip.valid   { background: var(--mint);  color: #181227; }
.word-chip.invalid { background: var(--coral); color: #181227; text-decoration: line-through; opacity: .75; }
.word-chip .wild-char { color: var(--pink-deep); font-weight: 900; }
.word-chip .pts    { font-family: var(--sans); font-size: 10px; opacity: .65; margin-left: 2px; }

.breakdown { background: var(--cream-2); border: 2px solid var(--ink); border-radius: 10px; padding: 10px 14px; }
.breakdown-row {
  display: flex; justify-content: space-between;
  padding: 4px 0; font-size: 14px;
  border-bottom: 1px dashed var(--ink-line);
}
.breakdown-row:last-child       { border-bottom: none; }
.breakdown-row.bonus    .value  { color: var(--bonus); }
.breakdown-row.penalty  .value  { color: var(--coral); font-weight: 600; }
.breakdown-row.total {
  border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px;
  font-family: var(--serif); font-weight: 700; font-size: 16px;
}
.breakdown-row.total .value { font-size: 19px; }

.wr-sheet-foot {
  padding: 14px 18px 18px; border-top: 2px solid var(--ink); background: var(--cream);
  display: flex; flex-direction: column; gap: 10px;
}
.wr-sheet-foot button {
  width: 100%; padding: 13px 16px; border: 2px solid var(--ink); border-radius: 12px;
  font-family: var(--sans); font-weight: 700; font-size: 15px; cursor: pointer;
  background: var(--cream); color: var(--ink); line-height: 1;
}
.wr-sheet-foot .wr-cta {
  background: var(--pink); color: #fff; font-size: 16px; padding: 14px 16px;
  box-shadow: 3px 3px 0 var(--ink); transition: transform .08s, box-shadow .08s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.wr-sheet-foot .wr-cta .cta-icon { flex: 0 0 auto; margin-top: -2px; }
.wr-sheet-foot .wr-cta:hover  { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.wr-sheet-foot .wr-cta:active { transform: translate(2px, 2px);  box-shadow: 1px 1px 0 var(--ink); }
.wr-sheet-foot .past-btn {
  background: var(--cream); color: var(--ink); font-size: 14px;
  box-shadow: 2px 2px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.wr-sheet-foot .past-btn:hover  { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); background: var(--cream-2); }
.wr-sheet-foot .past-btn:active { transform: translate(1px, 1px);   box-shadow: 1px 1px 0 var(--ink); }
.wr-sheet-foot .btn-primary { background: var(--ink); color: var(--cream); }
.wr-sheet-foot .btn-primary:active { opacity: .85; }

.instruct-steps { display: flex; flex-direction: column; gap: 9px; }
.instruct-step {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  background: var(--cream-2); border: 2px solid var(--ink); border-radius: 10px;
  font-size: 14px; line-height: 1.5;
}
.instruct-step.special-wild  { background: var(--pink-soft);   border-color: var(--pink-deep); }
.instruct-step.special-lucky { background: var(--yellow-soft); border-color: var(--gold-deep); }
.instruct-step .alert-title  { font-family: var(--serif); font-weight: 900; font-size: 15px; display: block; margin-bottom: 2px; color: var(--ink); }
.instruct-icon { font-size: 19px; flex-shrink: 0; margin-top: 1px; }

.wr-flash {
  position: fixed; bottom: 78px; left: 50%; z-index: 2000;
  transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: var(--cream);
  padding: 8px 15px; border-radius: 999px; border: 2px solid var(--ink);
  font-weight: 600; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s;
}
.wr-flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

#loadVeil {
  position: fixed; inset: 0; background: var(--cream); z-index: 3000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; text-align: center;
  font-family: var(--sans); color: var(--ink-50); font-weight: 600; font-size: 14px;
}
#loadIndicator:not([hidden]) {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.spinner {
  width: 34px; height: 34px; border: 3px solid var(--ink-30);
  border-top-color: var(--pink); border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loadError:not([hidden]) {
  max-width: 320px;
  display: flex; flex-direction: column; align-items: center;
  animation: load-error-in .35s cubic-bezier(.32, .72, .36, 1) both;
}
@keyframes load-error-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.load-error-icon  { font-size: 56px; line-height: 1; margin-bottom: 14px; }
.load-error-title {
  font-family: var(--serif); font-weight: 900; font-size: 22px;
  color: var(--ink); letter-spacing: -.02em; line-height: 1.2;
  margin-bottom: 8px;
}
.load-error-body  {
  color: var(--ink); font-size: 14px; line-height: 1.55; font-weight: 500;
  margin-bottom: 4px;
}
.load-error-body.muted { color: var(--ink-50); margin-bottom: 0; }
#loadRetry {
  margin-top: 20px;
  padding: 11px 26px;
  border: 2.5px solid var(--ink); border-radius: 999px;
  background: var(--pink); color: #fff;
  font-family: var(--sans); font-weight: 700; font-size: 15px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
#loadRetry:hover  { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
#loadRetry:active { transform: translate(2px, 2px);   box-shadow: 1px 1px 0 var(--ink); }

@media (max-width: 360px) {
  :root { --tile-size: 54px; }
  .tile { font-size: 25px; }
}
@media (min-width: 600px) {
  :root { --tile-size: 70px; }
  .tile { font-size: 34px; border-radius: 14px; }
}