:root {
  --bg: #fbf8f3;
  --card: #ffffff;
  --ink: #2b2a33;
  --muted: #8a8794;
  --line: #ebe6dd;
  --accent: #5b7cfa;
  --accent-soft: #e8edff;
  --good: #3fa66b;
  --good-soft: #e5f5ec;
  --bad: #d0504f;
  --bad-soft: #fdeeee;
  --radius: 14px;
  --font: 'Nunito', ui-rounded, 'SF Pro Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }

.app {
  max-width: 440px;
  margin: 0 auto;
  padding: 18px 18px 96px; /* room at the bottom so the pear buddy never hides content */
}

/* Header */
.header { position: relative; text-align: center; margin-bottom: 14px; }
.logo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.logo-pear { height: 2.4rem; margin-top: -6px; }
.date { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.help-button {
  position: absolute;
  top: 4px;
  right: 0;
  width: 34px;
  height: 34px;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  font-weight: 800;
  color: var(--muted);
  cursor: pointer;
  transition: transform 0.15s, color 0.15s;
}
.help-button:hover { color: var(--ink); transform: rotate(-8deg); }

/* Difficulty switcher */
.levels {
  display: flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--line);
  border-radius: 999px;
}
.levels button {
  flex: 1;
  padding: 7px 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.levels button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(0 0 0 / 0.08); }
.levels button.done::after { content: ' ✓'; color: var(--good); }

/* Puzzle heading */
.category {
  margin: 0;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.prompt { margin: 2px 0 12px; text-align: center; font-size: 1.3rem; font-weight: 800; line-height: 1.25; }
.loading { text-align: center; color: var(--muted); }

/* Status: tries left + latest result */
.status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 10px;
  padding: 10px 8px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.stat + .stat { border-left: 2px solid var(--line); }
.stat-label { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.dots { display: flex; justify-content: center; gap: 7px; height: 2.2rem; align-items: center; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); transition: background 0.3s; }
.dot.used { background: var(--line); }
.big-number { font-size: 2.2rem; font-weight: 800; line-height: 1; height: 2.2rem; display: grid; place-items: center; }

.result { display: block; padding: 12px; }
.result .stat-label { margin: 4px 0 0; }
.result-title { margin: 0; font-size: 1.35rem; font-weight: 800; }
.result.won { border-color: var(--good-soft); background: var(--good-soft); }
.result.won .result-title { color: var(--good); }

/* Items */
.end-label { margin: 4px 0; font-size: 0.82rem; font-weight: 600; color: var(--muted); text-align: center; }
.items { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.item {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 16px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.item:hover:not(:disabled) { border-color: #d8d2c6; }
.item:active:not(:disabled) { transform: scale(0.97); }
.item.selected { border-color: var(--accent); background: var(--accent-soft); animation: lift 0.25s ease-out; z-index: 1; }
.item:disabled { cursor: default; }
.finished .item { border-color: var(--good-soft); }
.finished li { animation: rise 0.35s ease-out backwards; }
.finished li:nth-child(2) { animation-delay: 0.05s; }
.finished li:nth-child(3) { animation-delay: 0.1s; }
.finished li:nth-child(4) { animation-delay: 0.15s; }
.finished li:nth-child(5) { animation-delay: 0.2s; }
.finished li:nth-child(6) { animation-delay: 0.25s; }
.item-value { color: var(--muted); font-weight: 400; font-size: 0.9rem; white-space: nowrap; }

/* After a loss: your board vs. the right order */
.compare {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 34px;
  row-gap: 7px;
}
.col-label {
  margin: 0;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tile {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 46px;
  padding: 8px 10px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
}
.tile.mine.right { background: var(--good-soft); border-color: #bfe5cf; }
.tile.mine.wrong { background: var(--bad-soft); border-color: #f2c5c5; color: var(--bad); }
.tile-value { font-size: 0.78rem; font-weight: 400; color: var(--muted); }

.links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.links line { stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 1; }
.links line.right { stroke: var(--good); }
.links line.wrong { stroke: var(--bad); }

/* The slide: your board moves left, the answer slides in, then the lines draw. */
.compare.animate .mine { animation: slide-left 0.6s cubic-bezier(.3,.8,.3,1) 0.15s backwards; }
.compare.animate .answer { animation: slide-in 0.45s ease-out backwards; animation-delay: calc(0.6s + var(--i, 0) * 0.05s); }
.compare.animate .links:not(.instant) line { stroke-dashoffset: 1; animation: draw 0.45s ease-out forwards; }

/* Check button */
.controls { margin-top: 14px; }
.check {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-size: 1.05rem;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}
.check:active:not(:disabled) { transform: scale(0.97); }
.check:disabled { opacity: 0.35; cursor: default; }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.9rem; }
.center { text-align: center; }

/* History */
.history { list-style: none; margin: 18px 0 0; padding: 0; border-top: 1px solid var(--line); }
.history li {
  display: flex;
  justify-content: space-between;
  padding: 8px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.history li span:first-child { color: var(--muted); }
.history .good { color: var(--good); font-weight: 700; }

/* How to play */
.help {
  width: min(92vw, 380px);
  padding: 24px 22px 20px;
  border: 0;
  border-radius: 20px;
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.15);
}
.help[open] { animation: pop-in 0.25s ease-out; }
.help::backdrop { background: rgb(43 42 51 / 0.35); }
.help h2 { margin: 0 0 12px; font-size: 1.35rem; font-weight: 800; text-align: center; }
.steps { margin: 0 0 12px; padding-left: 1.3em; display: grid; gap: 8px; }
.example, .levels-note { margin: 0 0 12px; font-size: 0.92rem; color: var(--muted); }
.example { padding: 10px 12px; background: var(--bg); border-radius: 10px; }

/* The pear buddy in the bottom-left corner */
.buddy {
  position: fixed;
  left: 14px;
  bottom: 12px;
  z-index: 5;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}
.buddy img {
  display: block;
  height: 56px;
  transform-origin: bottom center;
  animation: bounce 1.1s ease-in-out infinite;
}
.buddy.gone { opacity: 0; transform: translateY(16px); }
.buddy.sad img { animation: droop 0.7s ease-out forwards; }

.bubble {
  position: absolute;
  left: 50px;
  bottom: 50px;
  width: max-content;
  max-width: 200px;
  margin: 0;
  padding: 8px 12px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 0.08);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.3;
  opacity: 0;
  transform: scale(0.7);
  transform-origin: bottom left;
  transition: opacity 0.25s, transform 0.25s;
}
.bubble.show { opacity: 1; transform: scale(1); transition-delay: 0.5s; }

/* Short phone screens: a smaller buddy so he covers less of the page. */
@media (max-height: 720px) {
  .buddy { left: 8px; bottom: 8px; }
  .buddy img, .tumbling-pear { height: 42px; }
  .bubble { left: 38px; bottom: 38px; max-width: 170px; padding: 6px 10px; font-size: 0.8rem; }
}

/* The pear tumbles across the screen when you solve a puzzle (starting from his corner) */
.tumbling-pear {
  position: fixed;
  bottom: 12px;
  left: 14px;
  height: 56px;
  pointer-events: none;
  z-index: 10;
  animation: tumble 2.6s cubic-bezier(.4,.1,.6,.9) forwards;
}

/* Animations */
.pop { animation: pop 0.45s cubic-bezier(.2,1.6,.4,1); }

@keyframes pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes pop-in {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes lift {
  50% { transform: scale(1.03); }
}
@keyframes slide-left {
  from { transform: translateX(calc(50% + 17px)); }
}
@keyframes slide-in {
  from { transform: translateX(40px); opacity: 0; }
}
@keyframes draw {
  to { stroke-dashoffset: 0; }
}
@keyframes rise {
  from { transform: translateY(8px); opacity: 0; }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1.04, 0.96); }
  50%      { transform: translateY(-9px) scale(0.98, 1.03); }
}
@keyframes droop {
  to { transform: translateY(3px) rotate(-6deg); }
}
@keyframes tumble {
  0%   { transform: translateX(0) translateY(0) rotate(0deg); }
  15%  { transform: translateX(14vw) translateY(-46px) rotate(160deg); }
  30%  { transform: translateX(29vw) translateY(0) rotate(330deg); }
  45%  { transform: translateX(44vw) translateY(-32px) rotate(500deg); }
  60%  { transform: translateX(59vw) translateY(0) rotate(660deg); }
  75%  { transform: translateX(74vw) translateY(-18px) rotate(820deg); }
  88%  { transform: translateX(87vw) translateY(0) rotate(950deg); }
  100% { transform: translateX(calc(100vw + 80px)) translateY(0) rotate(1080deg); }
}
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .links line { stroke-dashoffset: 0 !important; }
}
