:root {
  color-scheme: light;
  --ink: #182b24;
  --muted: #4f6157;
  --line: #d5dccf;
  --paper: #f4f4e9;
  --surface: #fffef8;
  --board: #16352c;
  --board-text: #e7f1e9;
  --lime: #d8f376;
  --lime-pale: #edf6ce;
  --mono: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font: 100%/1.5 system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, textarea:focus-visible {
  outline: 2px solid #477346;
  outline-offset: 3px;
}
.build button:focus-visible { outline-color: var(--lime); }

.quiet {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 11px;
  color: var(--ink);
  background: transparent;
  font-weight: 680;
}
.quiet:hover:not(:disabled) { background: #e6ebdd; }
.quiet:disabled { color: #667268; opacity: .78; }
.help { border-color: var(--line); font-size: .875rem; white-space: nowrap; }
.help > span {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 3px;
  border: 1px solid currentColor;
  border-radius: 50%;
  font: 700 .75rem/1 var(--mono);
}

main { max-width: 794px; margin: 0 auto; padding: 0 24px 35px; }
.heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 16px;
  padding: 18px 0 11px;
}
.puzzle-title h1 {
  margin: 0 0 3px;
  font: 800 1.125rem/1.1 var(--mono);
  letter-spacing: .07em;
}
.puzzle-label {
  margin: 0;
  color: var(--muted);
  font: 700 .875rem/1.5 var(--mono);
  letter-spacing: .055em;
}
.puzzle-label.practice-label { text-transform: uppercase; }
.puzzle-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 7px; }
.difficulty {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.difficulty .quiet { min-height: 36px; padding: 4px 13px; font-size: .875rem; }
.difficulty .quiet[aria-pressed="true"] { color: var(--board-text); background: var(--board); }

.board {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  box-shadow: 0 5px 0 #dfe4d7, 0 10px 30px #1837270c;
}
.build {
  min-height: 143px;
  padding: 16px 20px 14px;
  color: var(--board-text);
  background-color: var(--board);
  background-image: radial-gradient(#c8dfcd2a 1px, transparent 1px);
  background-size: 14px 14px;
  box-shadow: inset 0 0 0 2px transparent;
}
.build[data-result="solved"] { box-shadow: inset 0 0 0 2px #8aceaa; }
.build[data-result="star"] { box-shadow: inset 0 0 0 2px var(--lime); }
.confetti {
  position: fixed;
  z-index: 9;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.confetti span {
  position: absolute;
  width: clamp(9px, 2.6vw, 13px);
  height: 8px;
  border: 1px solid #182b2440;
  border-radius: 2px;
}
.confetti-star span { width: clamp(10px, 3vw, 15px); height: 10px; }
.confetti-star .confetti-sparkle {
  width: clamp(15px, 4vw, 21px);
  height: clamp(15px, 4vw, 21px);
  clip-path: polygon(50% 0%, 64% 34%, 100% 38%, 73% 63%, 81% 100%, 50% 80%, 19% 100%, 27% 63%, 0% 38%, 36% 34%);
}
.board h2, .challenge h2 { margin: 0; font-size: 1rem; font-weight: 750; }
.board-top, .rack-top, .board-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.board-top { flex-wrap: wrap; }
.timers { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-left: auto; }
.timer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  min-width: 70px;
  padding: 3px 8px;
  border: 1px solid #5d786d;
  border-radius: 5px;
  color: #e6f2e8;
  background: #102b23;
  font: 700 .875rem/1.45 var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.timer-icon { font-size: 1rem; }
.timer-label { font-family: system-ui, -apple-system, sans-serif; }
.timer-split { background: transparent; }
.equation, .rack {
  --tile-gap: clamp(4px, 1vw, 8px);
  display: grid;
  grid-template-columns: repeat(var(--tile-count, 7), minmax(0, 1fr));
  gap: var(--tile-gap);
  margin-top: 10px;
}
.slot, .tile {
  display: grid;
  place-items: center;
  height: clamp(43px, 8.6vw, 64px);
  min-width: 0;
  padding: 0;
  border-radius: 6px;
  font: 750 clamp(1.04rem, 4.5vw, 1.95rem)/1 var(--mono);
}
.slot { position: relative; border: 1px dashed #6f8e80; background: #102d24a8; }
.tile {
  position: relative;
  border: 1px solid #b8c7ba;
  color: var(--ink);
  background: #f8f9ee;
  box-shadow: inset 0 -4px #dfe6d9;
  touch-action: none;
  user-select: none;
}
.tile.operator, .demo-tile.operator {
  border-color: #a8ba72;
  color: #28391b;
  background: var(--lime-pale);
  box-shadow: inset 0 -4px #d6e5ac;
}
.equation .tile { border-color: #f8f9ee; }
.equation .tile.operator { border-color: var(--lime-pale); }
.tile:hover:not(:disabled) { border-color: #5e7a4a; background: #e8f1d9; }
.tile:active:not(:disabled) { box-shadow: inset 0 -1px #c5d4bd; }
.tile.spent {
  border: 1px dashed #d5ddcf;
  color: transparent;
  background: #f4f6ee;
  box-shadow: none;
}
.equation .joins-left {
  margin-left: calc(-.35 * var(--tile-gap));
  border-top-left-radius: 2px;
  border-bottom-left-radius: 2px;
}
.equation .joins-right {
  margin-right: calc(-.35 * var(--tile-gap));
  border-top-right-radius: 2px;
  border-bottom-right-radius: 2px;
}
.drag-source { opacity: .34; }
.tile.drag-ghost {
  position: fixed;
  z-index: 10;
  margin: 0;
  pointer-events: none;
  box-shadow: 0 5px 13px #102b2366;
}
.drop-zone { outline: 2px solid #94b37c; outline-offset: 4px; border-radius: 5px; }
.drop-before::before, .drop-after::after {
  content: '';
  position: absolute;
  z-index: 1;
  inset-block: 0;
  width: 3px;
  border-radius: 2px;
  background: var(--lime);
}
.drop-before::before { left: -3px; }
.drop-after::after { right: -3px; }

.feedback-line { min-height: 23px; padding-top: 5px; }
.feedback { margin: 0; color: #ffcfaf; font-size: .91rem; font-weight: 670; overflow-wrap: anywhere; }
.build[data-result="solved"] .feedback { color: #b9efd2; }
.build[data-result="star"] .feedback { color: var(--lime); }
.rack-area { padding: 14px 20px 16px; }
.rack-top span { color: var(--muted); font-size: .9rem; }
.reveal { padding-top: 9px; }
.reveal p { margin: 0; color: var(--muted); }
.primary {
  min-height: 43px;
  border: 1px solid var(--board);
  border-radius: 7px;
  padding: 8px 15px;
  color: var(--board-text);
  background: var(--board);
  font-weight: 720;
}
.primary:hover:not(:disabled) { background: #24503f; }
.primary:disabled { border-color: #dce3d4; color: #536350; background: #e9eee3; }
#reveal { border-color: #8fad42; color: var(--ink); background: var(--lime); }
#reveal:hover { background: #caea5e; }
.board-bottom { margin-top: 12px; }
.edits, .practice, .practice-nav { display: flex; align-items: center; gap: 4px; }
.challenge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 6px 10px;
  border: 1px solid #cad6bf;
  border-radius: 10px;
  background: #e8eede;
}
.challenge:has(.earned) { border-color: #a9b973; background: #f0f4d9; }
.challenge-details { display: flex; align-items: baseline; flex: 1; flex-wrap: wrap; gap: 1px 10px; min-width: 0; }
.challenge h2, .challenge p { margin: 0; font-size: .875rem; overflow-wrap: anywhere; }
.challenge p { color: var(--muted); }
.retry-star { min-height: 34px; border-color: #b4c5a9; font-size: .875rem; }
.share-button { flex-shrink: 0; min-height: 34px; border-color: #b4c5a9; background: var(--surface); font-size: .875rem; white-space: nowrap; }
.star-mark {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  height: 32px;
  border: 1px solid #c7d4bc;
  border-radius: 7px;
  color: var(--board);
  background: var(--surface);
  font-size: 1.2rem;
}
.star-mark.earned { border-color: #a9b973; color: var(--board); background: var(--lime); }
.daily-results {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.daily-results summary {
  padding: 10px 13px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 750;
}
.daily-results summary:focus-visible { outline: 2px solid #477346; outline-offset: 2px; border-radius: 9px; }
.daily-results-content { padding: 0 13px 10px; }
.daily-results-content p { margin: 0 0 5px; color: var(--muted); font-size: .875rem; }
#community-status:empty { display: none; }
.community-charts { display: grid; gap: 12px; }
.community-charts h3 { margin: 0 0 3px; font-size: .95rem; }
.community-charts section + section { border-top: 1px solid var(--line); padding-top: 10px; }
.result-bars { display: grid; gap: 5px; margin: 8px 0 4px; padding: 0; list-style: none; }
.result-bars li {
  display: grid;
  grid-template-columns: minmax(8.8rem, .35fr) minmax(0, 1fr) 7ch;
  align-items: center;
  gap: 8px;
  font: 650 .8rem/1.4 var(--mono);
  overflow-wrap: anywhere;
}
.result-bars li > :last-child { text-align: right; }
.result-track { height: 8px; border-radius: 3px; background: #e8eede; }
.result-track::before {
  content: '';
  display: block;
  width: var(--fraction);
  height: 100%;
  border-radius: inherit;
  background: #689079;
}
.your-result { color: #245848; }
.your-result .result-track::before { background: #245848; }
.refresh-results { margin-top: 6px; padding-inline: 0; font-size: .875rem; }
.history-form {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.history-form label { display: grid; gap: 3px; font-size: .875rem; font-weight: 680; }
.history-form input, .history-form select {
  width: 100%;
  min-height: 40px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  font: inherit;
}
#history-key { max-width: 13rem; }
#history-status { margin: 10px 0; color: var(--muted); font-size: .9rem; }
.history-form .primary:disabled { opacity: .65; }
.practice { flex-wrap: wrap; margin-top: 7px; }
.practice-nav { margin-left: auto; }

dialog {
  width: min(482px, calc(100% - 28px));
  padding: 18px 20px;
  border: 1px solid #c4d0bf;
  border-radius: 13px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 18px 64px #142d2850;
}
dialog::backdrop { background: #0e231cb5; }
.dialog-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dialog-top h2 { margin: 0; font: 700 2rem/1.05 Georgia, serif; letter-spacing: -.045em; }
dialog p { margin: 11px 0; }
.tutorial-summary p { font-size: .95rem; }
.tutorial-overview { min-height: 34px; border-color: var(--line); font-size: .875rem; }
.tutorial-heading { margin: 16px 0 3px; font-size: .95rem; }
.tutorial-rules { margin: 0 0 9px; padding-inline-start: 1rem; }
.tutorial-rules li + li { margin-top: 2px; }
.tutorial-rules li::marker { color: #50704c; }
.tutorial-rule {
  display: block;
  width: 100%;
  min-height: 35px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  background: transparent;
  font-size: .875rem;
  font-weight: 680;
  text-align: left;
}
.tutorial-rule:hover { background: #f0f3e9; }
.tutorial-rule[aria-expanded="true"], .tutorial-overview[aria-expanded="true"] { border-color: #bdcdb4; background: #e8eede; }
.tutorial-example { margin: 7px 0 10px; }
.demo-detail { margin: 7px 0 2px; color: var(--muted); font-size: .875rem; }
.tutorial-replay { min-height: 32px; padding-inline: 5px; font-size: .875rem; }
.help-actions, .result-actions { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 8px; }
.help-actions { margin-top: 9px; }
.result-text {
  display: block;
  width: 100%;
  margin: 14px 0 10px;
  padding: 12px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  font: 1rem/1.5 system-ui, -apple-system, sans-serif;
}
.result-actions p { flex: 1 1 145px; margin: 0; color: var(--muted); font-size: .875rem; }
.result-actions p:empty { display: none; }
.demo {
  --demo-gap: clamp(3px, 1.3vw, 6px);
  --demo-size: clamp(32px, 9vw, 47px);
  --demo-row-gap: 10px;
  --demo-start: .3s;
  --demo-stagger: .22s;
  --demo-travel: .32s;
  padding: 10px 11px 11px;
  border-radius: 8px;
  color: var(--board-text);
  background: var(--board);
}
.demo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  font: 700 .875rem/1.3 var(--mono);
}
.demo-check { opacity: 0; color: var(--lime); text-align: right; }
.demo-check.invalid { color: #ffcfaf; }
.demo-equation, .demo-tray {
  display: grid;
  grid-template-columns: repeat(var(--demo-count, 7), minmax(0, 1fr));
  grid-auto-rows: var(--demo-size);
  gap: var(--demo-gap);
}
.demo-tray { margin-top: var(--demo-row-gap); }
.demo-equation span, .demo-tile { border: 1px dashed #6d8d7e; border-radius: 5px; }
.demo-tile {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  border: 1px solid #b8c7ba;
  color: var(--ink);
  background: #f8f9ee;
  box-shadow: inset 0 -4px #dfe6d9;
  font: 750 clamp(.95rem, 4.5vw, 1.45rem)/1 var(--mono);
}
.demo.is-playing .demo-tile {
  animation: demo-place var(--demo-travel) cubic-bezier(.22, .7, .2, 1) calc(var(--demo-start) + var(--step) * var(--demo-stagger)) both;
}
.demo.is-playing .demo-check {
  animation: demo-verify .2s ease-out calc(var(--demo-start) + (var(--demo-count) - 1) * var(--demo-stagger) + var(--demo-travel)) both;
}
@keyframes demo-place {
  to { transform: translate(calc(var(--move) * (100% + var(--demo-gap))), calc(-1 * (var(--demo-size) + var(--demo-row-gap)))); }
}
@keyframes demo-verify { to { opacity: 1; } }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (max-width: 480px) {
  main { padding: 0 11px 21px; }
  .heading { padding: 12px 0 9px; }
  .difficulty .quiet { min-height: 40px; padding-inline: 8px; }
  .help { padding-inline: 8px; }
  .help > span { display: none; }
  .build, .rack-area { padding-inline: 10px; }
  .tile, .slot { border-radius: 4px; }
  .equation.extreme { --tile-gap: 3px; }
  .rack.extreme { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .primary { padding-inline: 11px; }
  .board-bottom button { font-size: .9rem; white-space: nowrap; }
  .edits .quiet { padding-inline: 8px; }
  .practice .quiet { padding-inline: 8px; font-size: .875rem; }
}
@media (max-width: 410px) {
  .puzzle-tools { flex: 1 0 100%; justify-content: space-between; }
  #instructions { padding: 10px 14px; }
  .tutorial-summary p { margin-block: 7px; }
  .tutorial-heading { margin-top: 11px; }
  .tutorial-rule { min-height: 32px; padding: 3px 5px; }
  .demo { --demo-row-gap: 7px; padding-block: 8px; }
  .help-actions { margin-top: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti { display: none; }
  .demo.is-playing .demo-tile, .demo.is-playing .demo-check {
    animation-duration: .001s;
    animation-delay: 0s;
  }
  #replay { display: none; }
}
