:root {
  --bg: #fafaf7;
  --cell: #ecebe6;
  --text: #3a3a3a;
  --muted: #8a8a85;
  --line: #dcdbd5;
  --picked: #3a3a3a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
header {
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 8px;
}
.count { font-size: 18px; white-space: nowrap; }
.count b { font-weight: 600; }
.solved { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; }
.action {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  white-space: nowrap;
  color: var(--text);
  cursor: pointer;
}
.action:disabled { color: var(--muted); cursor: default; }
main {
  flex: 1;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  padding: 0 12px;
}
.grid {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  user-select: none;
  -webkit-user-select: none;
  /* The page must not scroll or zoom while a finger drags over the grid. */
  touch-action: none;
}
.cell {
  background: var(--cell);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 6vw, 28px);
  text-transform: uppercase;
  transition: background-color 0.25s;
}
.cell.hinted { box-shadow: inset 0 0 0 3px #e0a040; font-weight: 700; }
/* The word starts here: filled, so the reading direction is obvious. */
.cell.hint-start { background: #f5d9a8; }
.cell.picked { background: var(--picked); color: #fff; transition: none; }
.grid.miss .cell.picked { animation: shake 0.3s; }
@keyframes shake {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}
footer { padding: 12px 0 18px; font-size: 12px; color: var(--muted); }

/* Definition card */
.backdrop {
  position: fixed;
  inset: 0;
  display: none;
}
.sheet-open .backdrop { display: block; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 480px;
  max-height: 60dvh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.08);
  padding: 10px 20px calc(28px + env(safe-area-inset-bottom));
  transform: translateY(110%);
  transition: transform 0.25s ease-out;
  touch-action: none;
}
.sheet-open .sheet { transform: translateY(0); }
.sheet.dragging { transition: none; }
.grip {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line); margin: 0 auto 14px;
}
.word {
  font-size: 22px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; display: flex; align-items: center; gap: 10px;
}
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.defs { margin: 10px 0 0; padding-left: 20px; line-height: 1.45; font-size: 16px; }
.defs li + li { margin-top: 6px; }
.src { display: block; margin-top: 14px; font-size: 12px; color: var(--muted); }
/* Source links look like plain text, as before - they are just clickable now. */
.src { color: var(--muted); text-decoration: none; }
footer a { color: inherit; text-decoration: none; }

/* Celebration */
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 20; }
.win {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: rgba(250, 250, 247, 0);
  transition: background 0.25s;
}
.win.show { background: rgba(250, 250, 247, 0.6); }
.win-card {
  background: #fff; border-radius: 24px; padding: 28px 28px 20px; width: min(86%, 360px);
  text-align: center; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
  transform: scale(0.6); opacity: 0;
  transition: transform 0.45s cubic-bezier(0.2, 1.6, 0.4, 1), opacity 0.2s;
}
.win.show .win-card { transform: scale(1); opacity: 1; }
.win-title { font-size: 30px; font-weight: 700; }
.win-stats { margin-top: 8px; color: var(--muted); font-size: 15px; }
.win-next {
  margin-top: 22px; width: 100%; padding: 14px; border: 0; border-radius: 14px;
  background: var(--picked); color: #fff; font-size: 17px; cursor: pointer;
}
.win-hint { margin-top: 12px; font-size: 12px; color: var(--muted); }

/* Short message over the grid, e.g. "Собери слово по-другому" */
.toast {
  position: fixed; left: 50%; top: 22%; z-index: 15;
  transform: translate(-50%, -10px); opacity: 0; pointer-events: none;
  background: var(--picked); color: #fff; padding: 12px 20px; border-radius: 14px;
  font-size: 16px; white-space: nowrap; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Coins */
.coins { display: flex; align-items: center; gap: 5px; font-size: 17px; font-weight: 600; margin-left: auto; margin-right: 10px; }
.coin {
  display: inline-block; width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3b0, #f2c14e 45%, #c98a12 100%);
  box-shadow: inset 0 0 0 2px rgba(150, 95, 0, 0.35);
}
.coin.flying { position: fixed; left: 0; top: 0; margin: -9px 0 0 -9px; z-index: 30; pointer-events: none; }

/* Loading screen: a tiny self-solving filword over the page */
.loader {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  transition: opacity 0.35s;
}
.loader.hide { opacity: 0; pointer-events: none; }
.loader-grid {
  display: grid;
  grid-template-columns: repeat(6, 44px);
  grid-auto-rows: 44px;
  gap: 4px;
}
.loader-cell {
  background: var(--cell);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  transition: background 0.25s, color 0.25s, transform 0.25s;
}
.loader-cell.picked {
  background: var(--picked);
  color: #fff;
  transform: scale(1.08);
}
.loader-bar {
  width: 200px;
  height: 6px;
  border-radius: 3px;
  background: var(--cell);
  overflow: hidden;
}
.loader-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--text);
  transition: width 0.2s;
}
/* Size unknown: running stripes instead of a bar */
.loader.unknown .loader-fill {
  width: 40%;
  animation: loader-run 1.1s ease-in-out infinite;
}
@keyframes loader-run {
  from { transform: translateX(-100%); }
  to { transform: translateX(250%); }
}
.loader-quip { font-size: 14px; color: var(--muted); min-height: 1.2em; }
