:root {
  --forest: #2d5036;
  --forest-deep: #1f3d2a;
  --leaf: #6f9d57;
  --leaf-soft: #dbeacb;
  --cream: #fffdf4;
  --paper-ink: #43583b;
  --peach: #e68d70;
  --sun: #e8b454;
  --line: rgba(45, 80, 54, .2);
  --shadow: 0 22px 55px rgba(65, 91, 48, .2);
  --branch-image: url("assets/branch.png");
  --branch-flower-image: url("assets/branch-flower.png");
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--forest-deep);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; touch-action: manipulation; }
body {
  -webkit-touch-callout: none;
  position: relative;
  min-width: 320px;
  margin: 0;
  background: #dcebd2 url("assets/spring-background.png") center top / cover fixed no-repeat;
  color: var(--forest-deep);
}
body::before {
  content: "";
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,246,.12), rgba(224,239,208,.42));
}
button, a { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--peach); outline-offset: 4px; }

.app-shell { position: relative; max-width: 1460px; margin: 0 auto; padding: 0 5.6vw; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 86px;
  border-bottom: 1px solid rgba(45,80,54,.22);
  color: var(--forest-deep);
}
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; font-size: 11px; line-height: 1.02; letter-spacing: .16em; font-weight: 800; }
.brand b { font-size: 12px; letter-spacing: .1em; }
.brand-mark { width: 28px; height: 32px; display: flex; align-items: center; justify-content: center; gap: 3px; transform: rotate(-12deg); }
.brand-mark i { display: block; width: 5px; height: 28px; border-radius: 3px; background: linear-gradient(90deg, #7f4d2e, #d68b4e 45%, #9e5a34); box-shadow: 2px 2px 0 rgba(68, 70, 38, .18); }
.brand-mark i:nth-child(2) { height: 21px; transform: translateY(4px) rotate(19deg); }
.brand-mark i:nth-child(3) { height: 25px; transform: translateY(-3px) rotate(39deg); }
.topbar-meta { display: flex; align-items: center; gap: 24px; color: rgba(45,80,54,.7); font-size: 12px; letter-spacing: .04em; }
.level-count { border-left: 1px solid rgba(45,80,54,.25); padding-left: 24px; }
.level-count b { color: #bd6d55; font-size: 16px; }

.main-grid { display: grid; grid-template-columns: minmax(0, 1fr) 292px; gap: clamp(42px, 7vw, 112px); padding: 66px 0 82px; }
.game-column { min-width: 0; }
.eyebrow-row { display: flex; align-items: center; gap: 12px; color: #ba6a52; font-size: 11px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }
.dot-separator { width: 4px; height: 4px; border-radius: 50%; background: var(--peach); }
.tiny-label { color: rgba(45,80,54,.64); letter-spacing: .1em; }
.game-heading-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin: 19px 0 30px; }
h1, h2, p { margin: 0; }
h1 { color: var(--forest-deep); font-size: clamp(43px, 6.1vw, 79px); line-height: .94; letter-spacing: -.07em; font-weight: 800; text-shadow: 0 2px 0 rgba(255,255,255,.5); }
.intro { max-width: 410px; margin-top: 18px; color: rgba(45,80,54,.72); font-size: 15px; line-height: 1.55; }
.timer-wrap { flex: 0 0 auto; min-width: 118px; padding-bottom: 5px; text-align: right; }
.timer-label { display: block; color: rgba(45,80,54,.58); font-size: 10px; letter-spacing: .16em; text-transform: uppercase; }
.timer { display: block; margin-top: 4px; color: var(--forest-deep); font-variant-numeric: tabular-nums; font-size: 25px; letter-spacing: .03em; }

.puzzle-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(235px, 1fr) auto auto;
  min-height: 510px;
  padding: 47px clamp(32px, 6vw, 82px) 43px;
  isolation: isolate;
  background: transparent url("assets/answer-board.png") center / 100% 100% no-repeat;
  filter: drop-shadow(0 20px 25px rgba(74, 101, 49, .16));
}
.paper-texture { display: none; }
.puzzle-topline, .puzzle-footer { display: flex; justify-content: space-between; align-items: center; color: rgba(67,88,59,.64); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
#moveState { color: #c36e55; }
.equation { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 2.1vw, 29px); min-height: 285px; padding: 18px 0 12px; }
.token { position: relative; width: clamp(74px, 9.8vw, 111px); height: clamp(132px, 15.8vw, 180px); flex: 0 0 auto; }
.token.operator, .token.equals { width: clamp(46px, 5.6vw, 65px); height: clamp(80px, 10.3vw, 108px); }
.segment {
  position: absolute;
  z-index: 2;
  display: block;
  border-radius: 7px;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  transition: transform .2s ease, opacity .2s ease, filter .2s ease;
}
.segment.horizontal { left: 12%; width: 76%; height: 18px; transform: skewX(-8deg); }
.segment.vertical { top: 6%; left: auto; width: 38%; height: 18px; transform: rotate(90deg); }
.segment.vertical.bottom { top: auto; bottom: 6%; }
.segment.top { top: 1%; }
.segment.middle { top: 43.5%; }
.segment.bottom { bottom: 1%; }
.segment.left { left: -5%; }
.segment.right { right: -5%; }
.segment.active { background-image: var(--branch-image); cursor: grab; filter: drop-shadow(1px 4px 2px rgba(72, 58, 27, .2)); }
.segment.flower { background-image: var(--branch-flower-image); }
.segment.empty { z-index: 1; background-image: var(--branch-image); opacity: 0; pointer-events: none; filter: saturate(.55) brightness(1.05); }
.segment.empty:hover, .segment.empty:focus-visible, .segment.target { opacity: .36; pointer-events: auto; background-color: rgba(142, 189, 102, .12); box-shadow: 0 0 0 5px rgba(142,189,102,.16); }
.segment.selected { filter: drop-shadow(0 0 10px rgba(232, 141, 112, .88)); transform: scale(1.08) skewX(-8deg); }
.segment.vertical.selected { transform: scale(1.08) rotate(90deg); }
.operator .segment.horizontal { top: 42%; left: 12%; width: 76%; }
.operator .segment.vertical { top: 20%; left: 12%; width: 76%; height: 18px; right: auto; }
.equals .segment.horizontal { left: 9%; width: 82%; height: 16px; }
.equals .segment.top { top: 28%; }
.equals .segment.bottom { bottom: 28%; }
.equation.won .segment.active { filter: drop-shadow(0 0 8px rgba(130, 169, 81, .8)); }
.board-message { display: flex; align-items: center; justify-content: center; gap: 9px; min-height: 28px; color: rgba(67,88,59,.74); font-size: 12px; letter-spacing: .02em; text-align: center; }
.message-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: var(--peach); box-shadow: 0 0 0 5px rgba(232,141,112,.15); }
.board-message.success { color: #4b8a51; font-weight: 800; }
.board-message.success .message-dot { background: #75a34e; box-shadow: 0 0 0 5px rgba(117,163,78,.18); }
.puzzle-footer { padding-top: 17px; border-top: 1px solid rgba(67,88,59,.17); }
.rule-chip { color: #b96b52; border: 1px solid rgba(185,107,82,.38); border-radius: 99px; padding: 7px 10px; font-size: 9px; letter-spacing: .12em; }
.reset-button { display: inline-flex; align-items: center; gap: 8px; border: 0; color: var(--forest); background: transparent; font-size: 12px; font-weight: 800; letter-spacing: .02em; }
.reset-button:hover { color: #b96b52; }
.reset-icon { display: inline-grid; place-items: center; width: 23px; height: 23px; border: 1px solid rgba(67,88,59,.38); border-radius: 50%; font-size: 18px; line-height: 1; transition: transform .25s ease; }
.reset-button:hover .reset-icon { transform: rotate(-45deg); }
.victory-art { position: absolute; z-index: 5; right: 4%; bottom: 8%; width: clamp(96px, 14vw, 165px); pointer-events: none; opacity: 0; transform: translateY(10px) rotate(3deg) scale(.86); transition: opacity .35s ease, transform .45s cubic-bezier(.2,.8,.2,1); }
.victory-art img { display: block; width: 100%; height: auto; }
.puzzle-card.is-won .victory-art { opacity: 1; transform: translateY(0) rotate(3deg) scale(1); }

.how-to { display: grid; grid-template-columns: 35px minmax(0,1fr) 1px 35px minmax(0,1fr); align-items: start; gap: 12px; margin-top: 34px; color: rgba(45,80,54,.82); }
.how-to-number { color: #ba6a52; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.how-to h2 { color: var(--forest-deep); font-size: 14px; letter-spacing: -.01em; }
.how-to p { max-width: 220px; margin-top: 6px; color: rgba(45,80,54,.67); font-size: 12px; line-height: 1.55; }
.how-to-line { width: 1px; height: 58px; background: rgba(45,80,54,.22); }

.side-column { padding-top: 19px; }
.side-kicker { color: #ba6a52; font-size: 10px; letter-spacing: .18em; font-weight: 800; }
.side-intro h2 { margin-top: 14px; color: var(--forest-deep); font-size: 27px; letter-spacing: -.04em; }
.side-intro p { margin-top: 9px; color: rgba(45,80,54,.68); font-size: 13px; line-height: 1.5; }
.level-list { display: grid; gap: 10px; margin-top: 32px; }
.level-item { display: grid; grid-template-columns: 37px 1fr auto; align-items: center; gap: 12px; min-height: 59px; padding: 9px 12px; border: 1px solid rgba(45,80,54,.2); border-radius: 14px; color: rgba(45,80,54,.72); background: rgba(255,253,244,.6); box-shadow: 0 8px 22px rgba(74,101,49,.08); text-align: left; transition: border-color .2s ease, background .2s ease, transform .2s ease; backdrop-filter: blur(5px); }
.level-item:not(:disabled):hover { transform: translateX(4px); border-color: rgba(186,106,82,.7); background: rgba(255,253,244,.86); }
.level-item.active { border-color: #cf8468; background: rgba(255,253,244,.86); box-shadow: inset 3px 0 #cf8468, 0 8px 22px rgba(74,101,49,.1); }
.level-item:disabled { cursor: not-allowed; opacity: .58; }
.level-number { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: rgba(111,157,87,.16); color: var(--forest); font-size: 12px; font-weight: 800; }
.level-item.active .level-number { color: #fffdf4; background: #cf8468; }
.level-name { color: var(--forest-deep); font-size: 13px; font-weight: 800; }
.level-meta { display: block; margin-top: 3px; color: rgba(45,80,54,.55); font-size: 10px; }
.level-status { color: rgba(45,80,54,.5); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.level-item.active .level-status { color: #ba6a52; }
.score-card { margin-top: 31px; padding: 17px 18px 20px; border-top: 1px solid rgba(45,80,54,.25); border-bottom: 1px solid rgba(45,80,54,.25); }
.score-topline { display: flex; align-items: center; justify-content: space-between; color: rgba(45,80,54,.62); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.trophy-mark { color: #cf8468; font-size: 17px; }
.score-card strong { display: block; margin-top: 9px; color: var(--forest-deep); font-size: 35px; letter-spacing: -.05em; font-variant-numeric: tabular-nums; }
.score-card p { margin-top: 4px; color: rgba(45,80,54,.55); font-size: 11px; line-height: 1.45; }
.side-quote { margin-top: 51px; padding-left: 15px; border-left: 2px solid #cf8468; }
.quote-mark { display: block; height: 23px; color: #cf8468; font-family: Georgia, serif; font-size: 42px; line-height: .8; }
.side-quote p { color: rgba(45,80,54,.7); font-size: 13px; line-height: 1.75; }

.footer { display: flex; justify-content: space-between; padding: 20px 0 27px; border-top: 1px solid rgba(45,80,54,.2); color: rgba(45,80,54,.55); font-size: 10px; letter-spacing: .1em; }
.success-toast { position: fixed; z-index: 20; right: 26px; bottom: 26px; display: flex; align-items: center; gap: 12px; max-width: min(440px, calc(100vw - 32px)); padding: 14px 16px; border: 1px solid rgba(111,157,87,.48); border-radius: 18px; color: var(--forest-deep); background: rgba(255,253,244,.94); box-shadow: 0 18px 45px rgba(74,101,49,.24); animation: toast-in .4s cubic-bezier(.2,.8,.2,1) both; backdrop-filter: blur(8px); }
.success-toast[hidden] { display: none; }
.toast-mark { display: grid; place-items: center; width: 37px; height: 37px; flex: 0 0 auto; border-radius: 50%; color: #fff; background: #75a34e; font-size: 22px; }
.toast-kicker { color: #5a8e4c; font-size: 9px; font-weight: 800; letter-spacing: .14em; }
.success-toast h2 { margin-top: 2px; font-size: 20px; letter-spacing: -.04em; }
.success-toast p { margin-top: 3px; color: rgba(45,80,54,.68); font-size: 12px; }
.toast-reset { margin-left: auto; border: 0; border-bottom: 1px solid rgba(45,80,54,.5); color: var(--forest); background: transparent; font-size: 11px; white-space: nowrap; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes board-wiggle { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.equation.wrong { animation: board-wiggle .25s ease-in-out 2; }

@media (max-width: 900px) {
  .app-shell { padding: 0 4vw; }
  .main-grid { grid-template-columns: 1fr; gap: 48px; }
  .side-column { padding-top: 0; display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
  .side-intro { grid-column: 1 / -1; }
  .level-list { grid-column: 1 / -1; grid-template-columns: repeat(3, 1fr); }
  .score-card, .side-quote { margin-top: 28px; }
}
@media (max-width: 620px) {
  body { background-attachment: scroll; }
  .topbar { height: 72px; }
  .header-note { display: none; }
  .level-count { padding-left: 0; border: 0; font-size: 11px; }
  .main-grid { padding: 43px 0 56px; }
  .game-heading-row { align-items: flex-start; flex-direction: column; gap: 18px; margin-bottom: 22px; }
  h1 { font-size: clamp(45px, 14vw, 68px); }
  .timer-wrap { display: flex; align-items: baseline; gap: 9px; padding: 0; text-align: left; }
  .timer { margin: 0; font-size: 23px; }
  .puzzle-card { min-height: 390px; padding: 36px 22px 31px; }
  .equation { min-height: 210px; gap: clamp(4px, 1.6vw, 14px); padding: 14px 0 8px; }
  .token { width: clamp(45px, 14vw, 72px); height: clamp(84px, 25vw, 126px); }
  .token.operator, .token.equals { width: clamp(29px, 8.5vw, 45px); height: clamp(53px, 17vw, 78px); }
  .segment.horizontal { height: 11px; }
  .segment.vertical { height: 11px; }
  .operator .segment.vertical { height: 11px; }
  .equals .segment.horizontal { height: 10px; }
  .board-message { min-height: 38px; font-size: 11px; }
  .puzzle-footer { padding-top: 12px; font-size: 9px; }
  .rule-chip { font-size: 8px; padding: 6px 8px; }
  .victory-art { width: 94px; right: 2%; bottom: 10%; }
  .how-to { grid-template-columns: 27px minmax(0,1fr); gap: 8px 10px; }
  .how-to-line { display: none; }
  .how-to > :nth-child(4), .how-to > :nth-child(5) { margin-top: 18px; }
  .side-column { display: block; }
  .level-list { grid-template-columns: repeat(2, 1fr); }
  .level-item { grid-template-columns: 31px 1fr; gap: 8px; padding: 8px; }
  .level-number { width: 30px; height: 30px; }
  .level-status { display: none; }
  .score-card { margin-top: 28px; }
  .side-quote { display: none; }
  .footer { flex-direction: column; gap: 7px; line-height: 1.45; }
  .success-toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Keep the equation and heading inside narrow screens while preserving the airy board composition. */
body { overflow-x: hidden; }
.game-heading-row > div:first-child,
.game-heading-row,
.puzzle-card,
.equation { min-width: 0; }
.game-heading-row h1 { max-width: 100%; overflow-wrap: anywhere; }
.segment.flower {
  z-index: 4;
  background-size: 132% 132%;
  background-position: 86% center;
}
.segment.flower::after {
  content: "✿";
  position: absolute;
  z-index: 5;
  top: -14px;
  right: -8px;
  color: #e78392;
  font-family: Georgia, serif;
  font-size: clamp(13px, 1.35vw, 19px);
  line-height: 1;
  text-shadow: 0 1px 0 #fff7dc, 0 2px 3px rgba(141, 76, 65, .22);
  pointer-events: none;
  transform: rotate(9deg);
}

@media (max-width: 620px) {
  .game-heading-row h1 { font-size: clamp(43px, 13vw, 62px); }
  .puzzle-card { overflow: hidden; }
  .equation { gap: clamp(2px, 1.4vw, 7px); }
  .token { width: clamp(44px, 14vw, 64px); height: clamp(82px, 23vw, 112px); }
  .token.operator, .token.equals { width: clamp(28px, 8vw, 42px); height: clamp(53px, 17vw, 78px); }
  .segment.flower::after { top: -11px; right: -6px; font-size: 15px; }
}

.puzzle-topline,
.puzzle-footer,
.board-message { min-width: 0; }


/* Branch segments use the same length in both directions; only their angle changes. */
.segment.vertical {
  top: 25%;
  left: 100%;
  right: auto;
  width: 76%;
  transform: translate(-50%, -50%) rotate(90deg);
}
.segment.vertical.left { left: 0; right: auto; }
.segment.vertical.right { left: 100%; right: auto; }
.segment.vertical.bottom {
  top: auto;
  bottom: 25%;
  transform: translate(-50%, 50%) rotate(90deg);
}
.segment.vertical.selected { transform: translate(-50%, -50%) scale(1.08) rotate(90deg); }
.segment.vertical.bottom.selected { transform: translate(-50%, 50%) scale(1.08) rotate(90deg); }
.operator .segment.vertical {
  top: 50%;
  left: 50%;
  right: auto;
  width: 76%;
  transform: translate(-50%, -50%) rotate(90deg);
}
.operator .segment.vertical.selected { transform: translate(-50%, -50%) scale(1.08) rotate(90deg); }
.puzzle-actions { display: flex; align-items: center; justify-content: flex-end; gap: 14px; flex-wrap: wrap; }
.hint-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  border: 0;
  border-bottom: 1px solid rgba(186,106,82,.45);
  color: #b96b52;
  background: transparent;
  font-size: 11px;
  font-weight: 800;
}
.hint-button:hover:not(:disabled) { color: #8d593f; }
.hint-button:disabled { cursor: default; opacity: .78; }
.hint-button[aria-pressed="true"] { color: #75a34e; border-color: rgba(117,163,78,.5); }
.hint-icon { font-size: 16px; line-height: 1; }
@media (max-width: 620px) {
  .puzzle-footer { align-items: flex-start; gap: 10px; flex-wrap: wrap; }
  .puzzle-actions { gap: 10px; }
  .segment.vertical { height: 11px; }
  .operator .segment.vertical { height: 11px; }
}

/* Three level categories with independent numbering. */
.level-list { gap: 22px; }
.level-group { display: grid; gap: 10px; }
.level-group-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.level-group-title { color: var(--forest-deep); font-size: 15px; letter-spacing: -.02em; }
.level-group-count { color: rgba(45,80,54,.5); font-size: 10px; letter-spacing: .08em; }
.level-group-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.level-item { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 7px 8px; border-radius: 12px; }
.level-number { width: 32px; height: 32px; border-radius: 9px; }
.level-status { color: #75a34e; font-size: 15px; font-weight: 900; }
.level-item.completed .level-number { color: #4f874c; background: rgba(117,163,78,.2); }
.level-item.active .level-status { color: #cf8468; }
.toast-actions { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.toast-next { border: 0; border-radius: 999px; padding: 9px 13px; color: #fffdf4; background: #75a34e; font-size: 11px; font-weight: 800; white-space: nowrap; }
.toast-next:hover { background: #5f914d; }
@media (max-width: 900px) {
  .level-list { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .level-group-grid { gap: 6px; }
  .level-item { min-height: 44px; padding: 6px; }
  .level-number { width: 29px; height: 29px; font-size: 11px; }
  .level-status { font-size: 13px; }
  .toast-actions { gap: 8px; }
  .toast-next { padding: 8px 10px; }
}
