:root {
  --bg: #ecfbfb;
  --ink: #1d2328;
  --accent: #e0a100;
  --card: #f1f9d6;
  --card-edge: #b9c97a;
  --bar: #000;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--bar);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
}
.topbar a { color: #fff; text-decoration: none; }
.topbar .brand { font-weight: 700; }
main { flex: 1; padding: 16px; max-width: 1100px; width: 100%; margin: 0 auto; }
h1 { text-align: center; margin: 12px 0 4px; font-size: clamp(1.6rem, 4vw, 2.4rem); }
.lead { text-align: center; color: #3c464d; margin: 0 0 24px; }
.mode-cards {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
}
.mode-card {
  width: 220px;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  border: 3px solid transparent;
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.mode-card:hover, .mode-card:focus-visible { border-color: var(--accent); outline: none; }
.mode-art { display: block; background: #f4f4f4; border-radius: 8px; padding: 10px; }
.mode-art svg { width: 100%; height: auto; display: block; }
.mode-name { display: block; margin-top: 10px; font-weight: 600; }
.attribution {
  background: #3a2350;
  color: #f2eefa;
  font-size: .9rem;
  padding: 12px 16px;
  text-align: center;
}
.attribution a { color: #ffe27a; }
.prose { max-width: 720px; margin: 0 auto; line-height: 1.6; }
.prose h1 { text-align: left; }
@media (max-width: 480px) {
  .mode-card { width: 100%; max-width: 320px; }
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.level-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 10px;
  background: var(--card);
  border: 2px solid var(--card-edge);
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.level-card:hover, .level-card:focus-visible { border-color: var(--accent); outline: none; }
.level-stars { color: var(--accent); font-size: 1.3rem; letter-spacing: 2px; }
.play { max-width: 760px; margin: 0 auto; }
.play-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.play-head h1 { margin: 8px 0; font-size: 1.6rem; }
.back { color: var(--ink); text-decoration: none; font-weight: 600; }
.counter { color: #3c464d; font-size: .95rem; }
.target {
  font-size: 1.6rem;
  text-align: center;
  margin: 8px 0 12px;
  min-height: 3.2rem;
}
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: 1.4em; line-height: 1.1; margin: 0 4px; }
.frac .num { border-bottom: 3px solid var(--ink); padding: 0 6px; }
.frac .den { padding: 0 6px; }
.whole { font-weight: 700; margin-right: 4px; }
.bars { display: flex; flex-direction: column; gap: 14px; align-items: center; min-height: 120px; }
.bar {
  display: flex;
  width: min(92vw, 640px);
  height: 72px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
.seg {
  flex: 1 1 0;
  border-right: 2px dashed #9aa3a8;
  background: #fff;
  cursor: pointer;
  transition: background .15s;
}
.seg:last-child { border-right: none; }
.seg.filled { background: #e0584f; border-right: 2px solid #7a2a24; }
.seg.filled:hover { background: #cf463d; }
.feedback { min-height: 1.6em; text-align: center; font-weight: 600; }
.feedback.ok { color: #1b7a33; }
.feedback.bad { color: #a12424; }
.actions { display: flex; justify-content: center; gap: 12px; margin: 8px 0 16px; }
.btn {
  appearance: none;
  border: 2px solid var(--ink);
  background: #fff;
  color: var(--ink);
  padding: 8px 18px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn.primary { background: var(--accent); border-color: #7a5a00; }
.btn:disabled { opacity: .5; cursor: default; }
.tray {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  min-height: 72px;
  padding: 12px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 12px;
  touch-action: none;
}
.piece {
  width: 56px;
  height: 56px;
  background: #e0584f;
  border: 2px solid #7a2a24;
  border-radius: 6px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.piece:focus-visible { outline: 3px solid var(--accent); }
.ghost {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  width: 48px;
  height: 48px;
  opacity: .9;
  box-shadow: 0 4px 10px rgba(0,0,0,.3);
}
.hint { text-align: center; color: #4a555c; font-size: .9rem; }
.result { text-align: center; background: #fff; border-radius: 12px; padding: 16px; margin-top: 16px; }
.result .stars { color: var(--accent); font-size: 2rem; letter-spacing: 4px; }
[hidden] { display: none !important; }
.ghost { background: #e0584f; border: 2px solid #7a2a24; border-radius: 6px; }
.lab { max-width: 760px; margin: 0 auto; text-align: center; }
.lab-controls { display: flex; justify-content: center; align-items: center; gap: 12px; flex-wrap: wrap; margin: 12px 0; }
.lab-controls .count { min-width: 2.5ch; font-weight: 700; }
.pies { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; min-height: 180px; }
.pie { width: 170px; height: 170px; }
.pie path { cursor: pointer; fill: #fff; stroke: #333; stroke-width: 1.5; }
.pie path.on { fill: #e0584f; }
.pie path:hover { stroke: var(--accent); stroke-width: 2.5; }
.lab-result { font-size: 1.4rem; margin: 16px 0 4px; }
.lab-result .frac { font-size: 1.1em; }
.lab-note { color: #4a555c; font-size: .9rem; }
.goal { text-align: center; color: #3c464d; margin: 0 0 12px; }
