* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: #0e0f16;
  color: #f1f0e9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#bgCanvas { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.screen { display: none; flex-direction: column; align-items: center; }
.screen.active { display: flex; }
.home { max-width: 360px; width: 100%; text-align: center; }
@keyframes riseIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
.home .logo { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.05s; }
.home h1 { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.15s; }
.home .tagline { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.25s; }
.home .card { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.35s; }
.home .difficulty { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.45s; }
.home .btn-play { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.55s; }
.home .rules { animation: riseIn 0.5s ease-out backwards; animation-delay: 0.65s; }
.logo {
  width: 64px; height: 64px; border-radius: 18px; background: #EF9F27;
  color: #14151c; display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800; margin: 0 auto 18px;
}
h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 4px; }
.tagline { color: #f5c877; font-size: 15px; font-weight: 600; margin-bottom: 22px; }
.card { background: #171822; border-radius: 16px; padding: 12px 20px; margin-bottom: 20px; width: 100%; }
.card .label { font-size: 11px; color: #9a998f; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.card .value { font-size: 30px; font-weight: 800; color: #EF9F27; letter-spacing: -0.01em; margin-top: 2px; }
.difficulty { width: 100%; margin-bottom: 18px; text-align: left; }
.difficulty .label {
  font-size: 11px; color: #9a998f; text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: 600; margin-bottom: 8px;
}
.segmented { display: flex; gap: 4px; background: #171822; border-radius: 999px; padding: 4px; }
button.seg {
  flex: 1; background: transparent; color: #b5b3a8; border: none; border-radius: 999px;
  padding: 9px 4px; font-size: 11px; font-weight: 700; cursor: pointer;
  text-transform: uppercase; letter-spacing: 0.04em; font-family: inherit;
}
button.seg:hover { color: #f1f0e9; background: #1c1d29; }
button.seg.active, button.seg.active:hover { background: #EF9F27; color: #14151c; }
.diff-hint {
  color: #9a998f; font-size: 12px; line-height: 1.6;
  margin-top: 9px; min-height: 2.4em; text-align: center;
}
.btn-play {
  width: 100%; background: #EF9F27; color: #14151c; font-weight: 800; font-size: 17px;
  border: none; border-radius: 999px; padding: 13px; margin-bottom: 14px; cursor: pointer;
}
.btn-play:hover { background: #f5b754; }
.rules { color: #b5b3a8; font-size: 13px; line-height: 1.75; padding: 0 6px; }
.rules b { color: #f5c877; font-weight: 700; }
.game { max-width: 340px; width: 100%; }
.game-col { width: 100%; display: flex; flex-direction: column; align-items: center; }

/* The side panels are desktop-only furniture. Below the breakpoint the game
   is exactly the single column it has always been -- phones never see them. */
.side { display: none; }

@media (min-width: 940px) {
  .screen.game {
    max-width: 900px;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    gap: 26px;
  }
  .game-col { width: 340px; flex: 0 0 340px; }
  .side { display: block; width: 224px; flex: 0 0 224px; padding-top: 34px; }
}

.panel { background: #171822; border-radius: 16px; padding: 16px; margin-bottom: 10px; }
.panel-title {
  font-size: 11px; color: #9a998f; text-transform: uppercase;
  letter-spacing: 0.08em; font-weight: 600; margin-bottom: 13px;
}
.panel-note { color: #82817a; font-size: 12px; line-height: 1.65; }

/* Every pair summing to 9 has the same combined width, because radius is
   linear in the number. The rows line up on their own -- that is the game's
   arithmetic showing through, not a layout trick. */
.ladder { display: flex; flex-direction: column; gap: 5px; }
.rung {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 5px 6px; border-radius: 12px; opacity: 0.5;
  transition: opacity 0.18s ease, background-color 0.18s ease;
}
.rung.lit { opacity: 1; background: rgba(239, 159, 39, 0.09); }
.pip {
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 800; line-height: 1;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85);
}
.plus { color: #6d6c66; font-size: 11px; font-weight: 700; }

.readout { display: flex; flex-direction: column; }
.reading {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 7px 0; border-top: 1px solid #21222e;
}
.reading:first-child { border-top: none; padding-top: 0; }
.reading dt { color: #9a998f; font-size: 12px; }
.reading dd {
  color: #f1f0e9; font-size: 16px; font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.ramp-head {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; color: #9a998f; margin-bottom: 8px;
}
.ramp-name { color: #EF9F27; font-weight: 700; }
.ramp { height: 4px; border-radius: 999px; background: #21222e; overflow: hidden; }
.ramp-fill {
  height: 100%; width: 0; border-radius: 999px; background: #EF9F27;
  transition: width 0.3s ease;
}
.ramp + .panel-note { margin-top: 9px; }

@media (prefers-reduced-motion: reduce) {
  .rung, .ramp-fill { transition: none; }
}
.topbar { display: flex; align-items: center; width: 100%; margin-bottom: 12px; }
.topbar a {
  display: flex; align-items: center; gap: 5px; color: #e4e2d8; text-decoration: none; cursor: pointer;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  border: 1px solid #33343f; border-radius: 999px; padding: 6px 12px 6px 10px;
}
.topbar a .arrow { color: #EF9F27; font-weight: 900; }
.topbar a:hover { border-color: #EF9F27; background: #1c1d29; }
.brand { margin-left: auto; color: #EF9F27; font-weight: 800; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.brand .mark { width: 18px; height: 18px; border-radius: 6px; background: #EF9F27; color: #14151c; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 900; }
.stats { display: flex; gap: 8px; margin-bottom: 10px; width: 100%; }
.stat { background: #171822; border-radius: 12px; padding: 10px 14px; flex: 1; text-align: center; }
.stat .label { font-size: 10px; color: #9a998f; text-transform: uppercase; letter-spacing: 0.07em; font-weight: 600; }
.stat .value { font-size: 24px; font-weight: 800; letter-spacing: -0.01em; margin-top: 1px; }
.stat.score .value { color: #EF9F27; }
.stat.streak .value { color: #D85A30; }
.stat.level .value { color: #7F77DD; }
.controls { display: flex; gap: 8px; margin-bottom: 10px; width: 100%; }
button.ctrl {
  flex: 1; background: transparent; color: #f1f0e9; border: 1px solid #33343f;
  border-radius: 12px; padding: 10px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
button.ctrl:hover { background: #1c1d29; }
#minusBtn { color: #5DCAA5; border-color: #1D9E75; }
#minusBtn .icon { width: 16px; height: 16px; border-radius: 50%; background: #1D9E75; color: #0e0f16; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 900; }
#minusBtn .count { background: rgba(93,202,165,0.18); color: #5DCAA5; border-radius: 999px; padding: 1px 7px; font-size: 11px; }
#minusBtn.active .count { background: rgba(14,15,22,0.25); color: #0e0f16; }
#minusBtn.active { background: #1D9E75; color: #0e0f16; }
#minusBtn.active .icon { background: #0e0f16; color: #5DCAA5; }
#restartBtn { color: #9a998f; }
#restartBtn:hover { color: #f1f0e9; }
.board {
  background: #171822; border-radius: 16px; padding: 12px;
  display: flex; flex-direction: column; align-items: center; position: relative; width: 100%;
}
canvas { touch-action: none; cursor: pointer; max-width: 100%; border-radius: 8px; }
.over {
  display: none; position: absolute; inset: 12px; border-radius: 12px;
  background: rgba(14,15,22,0.92); flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; text-align: center; padding: 0 20px;
}
.over.show { display: flex; }
.over .sub { color: #9a998f; font-size: 13px; }
.over .score { font-size: 30px; font-weight: 800; color: #EF9F27; }
.over .newbest { display: none; color: #f5c877; font-size: 12px; }
.over .newbest.show { display: block; }
.over .row { display: flex; gap: 8px; margin-top: 6px; }
.btn-solid { background: #EF9F27; color: #14151c; font-weight: 700; border: none; border-radius: 999px; padding: 9px 18px; font-size: 13px; cursor: pointer; }
.btn-outline { background: transparent; color: #f1f0e9; border: 1px solid #33343f; border-radius: 999px; padding: 9px 18px; font-size: 13px; cursor: pointer; }
