:root {
  --bg: #171229;
  --bg-2: #1f1837;
  --surface: #261e45;
  --ink: #1a1430;
  --cream: #fff3d6;
  --cream-2: #f3e2bb;
  --gold: #f7c548;
  --gold-2: #d99a1e;
  --coral: #ff5c7a;
  --teal: #37d99a;
  --violet: #8f7cf6;
  --muted: #a398c7;
  --text: #f4efff;
  --tile: clamp(34px, calc((100vw - 104px) / 7), 52px);
  --radius: 10px;
  --serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 600px at 50% -200px, #2d2254 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button { font-family: inherit; cursor: pointer; }

/* ---------- header ---------- */
.top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 10px 12px 4px;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.04);
  color: var(--muted);
  font-weight: 700;
  font-size: 18px;
  display: grid; place-items: center;
}
.icon-btn:active { transform: scale(.94); }
.wordmark {
  margin: 0;
  display: flex; justify-content: center; gap: 3px;
  font-family: var(--serif);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 0;
}
.wm-tile {
  display: grid; place-items: center;
  width: 28px; height: 32px;
  background: var(--cream);
  color: var(--ink);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--cream-2), 0 4px 10px rgba(0,0,0,.35);
}
.wm-tile.lifted {
  background: var(--gold);
  box-shadow: 0 2px 0 var(--gold-2), 0 6px 14px rgba(247,197,72,.35);
  transform: translateY(-5px) rotate(-8deg);
}

/* ---------- job bar ---------- */
.game {
  flex: 1;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 4px 14px 24px;
  display: flex; flex-direction: column;
}
.jobbar { text-align: center; margin-bottom: 8px; }
.jobmeta { color: var(--muted); font-size: 13px; font-weight: 500; letter-spacing: .02em; }
.jobmeta .dot { margin: 0 6px; opacity: .5; }
.jobtitle {
  margin: 2px 0 6px;
  font-family: var(--serif);
  font-weight: 700;
  font-style: italic;
  font-size: 26px;
  color: var(--gold);
  text-wrap: balance;
}
.jobdots { list-style: none; display: flex; gap: 6px; justify-content: center; margin: 0; padding: 0; }
.jobdots li { width: 22px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.12); transition: background .3s; }
.jobdots li.done { background: var(--teal); }
.jobdots li.now { background: var(--gold); }

/* ---------- marks ---------- */
.marks {
  display: flex; flex-direction: column; gap: 10px;
  padding: 6px 0;
  flex: 1;
  justify-content: center;
}
.mark {
  display: grid;
  grid-template-columns: 22px 1fr 22px;
  align-items: center;
  gap: 6px;
}
.mark-num {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--muted);
  text-align: center;
}
.mark-status { text-align: center; font-size: 14px; }
.tiles { display: flex; justify-content: center; gap: 5px; min-height: var(--tile); }
.mark.shake .tiles { animation: shake .45s cubic-bezier(.36,.07,.19,.97) both; }

.tile {
  width: var(--tile); height: var(--tile);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 700;
  font-size: calc(var(--tile) * .58);
  line-height: 1;
  text-transform: uppercase;
  box-shadow: 0 3px 0 var(--cream-2), 0 6px 14px rgba(0,0,0,.35);
  transition: transform .12s, width .3s cubic-bezier(.4,0,.2,1), margin .3s cubic-bezier(.4,0,.2,1), opacity .2s, box-shadow .2s;
  position: relative;
  overflow: hidden;
  flex: 0 0 auto;
}
.tile:active:not(.gone) { transform: translateY(2px); box-shadow: 0 1px 0 var(--cream-2), 0 2px 6px rgba(0,0,0,.3); }
.tile.gone { width: 0; margin: 0 -2.5px; opacity: 0; pointer-events: none; }
.tile.bad { animation: flash-bad .5s both; }
.tile.tip { box-shadow: 0 3px 0 var(--gold-2), 0 0 0 3px var(--gold), 0 0 22px rgba(247,197,72,.75); animation: tip-bounce 1s ease-in-out infinite; }
.mark.done .tile { background: #efe6cf; color: #4c4365; box-shadow: 0 3px 0 #d9ccaf, 0 6px 14px rgba(0,0,0,.25); }
.mark.done .tile.gone { opacity: 0; }

/* flying clone */
.flyer {
  position: fixed;
  z-index: 50;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--gold);
  color: var(--ink);
  font-family: var(--serif); font-weight: 900; text-transform: uppercase;
  box-shadow: 0 3px 0 var(--gold-2), 0 10px 24px rgba(0,0,0,.45);
  pointer-events: none;
  will-change: transform;
}

/* ---------- haul ---------- */
.haul {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 18px;
  padding: 12px 14px 14px;
  margin-top: 8px;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25) inset, 0 10px 30px rgba(0,0,0,.25);
}
.haul-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.haul-label { font-family: var(--serif); font-style: italic; font-size: 15px; color: var(--muted); }
.text-btn {
  background: transparent; border: 1.5px solid rgba(255,255,255,.14); color: var(--text);
  padding: 6px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
}
.text-btn:disabled { opacity: .35; cursor: default; }
.slots { display: flex; justify-content: center; gap: 7px; }
.slots.shake { animation: shake .45s both; }
.slots.win .slot { animation: win-pop .6s cubic-bezier(.34,1.56,.64,1) both; }
.slots.win .slot:nth-child(2) { animation-delay: .06s; }
.slots.win .slot:nth-child(3) { animation-delay: .12s; }
.slots.win .slot:nth-child(4) { animation-delay: .18s; }
.slots.win .slot:nth-child(5) { animation-delay: .24s; }
.slots.win .slot:nth-child(6) { animation-delay: .30s; }
.slot {
  width: calc(var(--tile) * 1.05); height: calc(var(--tile) * 1.05);
  border-radius: var(--radius);
  border: 2px dashed rgba(247,197,72,.45);
  background: rgba(0,0,0,.18);
  color: var(--ink);
  display: grid; place-items: center;
  font-family: var(--serif); font-weight: 900; font-size: calc(var(--tile) * .6); text-transform: uppercase;
  padding: 0;
  position: relative;
  transition: background .2s, border-color .2s, transform .15s;
}
.slot::after {
  content: attr(data-n);
  position: absolute; bottom: -17px; left: 0; right: 0;
  font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 12px; color: var(--muted);
  text-transform: none;
}
.slot.filled {
  border-style: solid; border-color: var(--gold-2);
  background: var(--gold);
  box-shadow: 0 3px 0 var(--gold-2), 0 8px 18px rgba(247,197,72,.25);
}
.slot.filled:active { transform: translateY(2px); }
.slot.wrong { background: var(--coral); border-color: #c93a56; box-shadow: 0 3px 0 #c93a56; }
.slot.hidden-letter { color: transparent; }

.fence {
  margin: 24px 0 0;
  min-height: 40px;
  text-align: center;
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
  text-wrap: balance;
}
.fence b { color: var(--gold); }
.fence.bad { color: var(--coral); }
.fence.good { color: var(--teal); }
.actions { display: flex; justify-content: center; gap: 10px; margin-top: 8px; min-height: 0; }
.actions:empty { display: none; }

.primary, .secondary {
  border: 0;
  border-radius: 999px;
  padding: 13px 22px;
  font-size: 16px; font-weight: 700;
  transition: transform .1s;
}
.primary { background: var(--gold); color: var(--ink); box-shadow: 0 3px 0 var(--gold-2), 0 8px 20px rgba(247,197,72,.3); }
.primary:active, .secondary:active { transform: translateY(2px); }
.secondary { background: rgba(255,255,255,.08); color: var(--text); border: 1.5px solid rgba(255,255,255,.14); }

/* ---------- modals ---------- */
.modal {
  border: 0; padding: 0; background: transparent;
  width: min(100vw, 520px);
  max-width: 100vw;
  max-height: 100dvh;
  margin: auto;
  color: var(--text);
}
.modal::backdrop { background: rgba(10, 6, 24, .72); backdrop-filter: blur(4px); }
.modal-card {
  position: relative;
  background: var(--bg-2);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 22px;
  padding: 24px 22px 22px;
  margin: 12px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: rise .3s cubic-bezier(.2,.9,.3,1.2) both;
  max-height: calc(100dvh - 24px);
  overflow: auto;
}
.modal h2 { font-family: var(--serif); font-weight: 900; font-size: 30px; margin: 0 0 8px; color: var(--gold); }
#sum-title { font-size: 26px; }
#btn-today { display: none; width: 100%; margin-top: 10px; }
.practice #btn-today { display: block; }
.modal h3 { font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 16px; color: var(--muted); margin: 18px 0 8px; }
.modal .close {
  position: absolute; top: 12px; right: 12px;
  width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.08); color: var(--text); font-size: 20px; line-height: 1;
}
.lede { font-size: 16px; line-height: 1.45; margin: 0 0 10px; }
.rules { padding-left: 20px; margin: 0 0 14px; line-height: 1.45; font-size: 15px; }
.rules li { margin-bottom: 6px; }
.rules b, .lede b { color: var(--gold); }
.example { display: flex; flex-direction: column; gap: 8px; background: rgba(0,0,0,.2); padding: 12px; border-radius: 14px; }
.ex-row { display: flex; align-items: center; gap: 12px; }
.ex-word { display: flex; gap: 3px; }
.ex-tile {
  width: 26px; height: 28px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--cream); color: var(--ink);
  font-family: var(--serif); font-weight: 700; font-size: 15px;
  box-shadow: 0 2px 0 var(--cream-2);
}
.ex-tile.good { background: var(--gold); box-shadow: 0 2px 0 var(--gold-2); transform: translateY(-3px) rotate(-6deg); }
.ex-tile.bad { background: var(--coral); color: #fff; box-shadow: 0 2px 0 #c93a56; transform: translateY(-3px) rotate(6deg); }
.ex-note { font-size: 14px; color: var(--muted); }
.ex-note b { color: var(--text); }
.fine { font-size: 13px; color: var(--muted); line-height: 1.4; margin: 14px 0; }
.modal .primary { width: 100%; }
.eyebrow { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); font-weight: 700; }
.grid {
  font-size: 20px; line-height: 1.3; letter-spacing: 2px;
  background: rgba(0,0,0,.22); border-radius: 14px; padding: 12px; margin: 12px 0;
  text-align: center;
  font-family: var(--sans);
}
.hauls { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 14px; }
.hauls span {
  background: var(--gold); color: var(--ink);
  font-family: var(--serif); font-weight: 900; letter-spacing: .08em;
  padding: 4px 10px; border-radius: 8px; font-size: 15px;
  box-shadow: 0 2px 0 var(--gold-2);
}
.row { display: flex; gap: 10px; }
.row .primary, .row .secondary { flex: 1; width: auto; }
.statgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.statgrid .n { font-family: var(--serif); font-size: 30px; font-weight: 900; color: var(--gold); line-height: 1; }
.statgrid .l { font-size: 11px; color: var(--muted); margin-top: 4px; }
.dist { display: flex; flex-direction: column; gap: 5px; }
.dist .bar { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: center; font-size: 13px; }
.dist .bar .lab { color: var(--muted); text-align: right; }
.dist .bar .fill { height: 20px; background: rgba(255,255,255,.1); border-radius: 5px; min-width: 24px; color: var(--ink); font-weight: 700; display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; }
.dist .bar.hit .fill { background: var(--gold); }

/* ---------- misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--cream); color: var(--ink);
  padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
@keyframes flash-bad {
  0% { background: var(--coral); color: #fff; }
  100% { background: var(--cream); color: var(--ink); }
}
@keyframes tip-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
@keyframes win-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.18) rotate(-4deg); background: var(--teal); border-color: #1fa877; }
  100% { transform: scale(1); }
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 521px) {
  :root { --tile: 52px; }
}
@media (max-height: 700px) {
  .jobtitle { font-size: 22px; margin-bottom: 4px; }
  .marks { gap: 7px; }
  .fence { margin-top: 20px; min-height: 36px; font-size: 14px; }
}
