#subtraction {
  --sub-ink: #203b3f;
  --sub-muted: #47646a;
  --sub-teal: #176451;
  --sub-panel: #fefbf1;
  --sub-border: #afc9ba;
  --sub-focus: #165a9a;
  min-height: 0;
  border-radius: 22px;
  background: #eaf2e6;
  color: var(--sub-ink);
  text-shadow: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#subtraction.on { display: block; }
#subtraction * { box-sizing: border-box; }
#subtraction h1, #subtraction h2, #subtraction p { margin: 0; }
#subtraction [hidden] { display: none; }

#subtraction button {
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#subtraction button:disabled { cursor: default; }
#subtraction button:focus-visible { outline: 3px solid var(--sub-focus); outline-offset: 3px; }
#subtraction h1:focus { outline: none; }

.sub-page {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 100%;
  padding: 12px 14px 18px;
  background: linear-gradient(180deg, #d0ebe6 0, #eaf2e6 226px);
}

.sub-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 13px;
  font-weight: 700;
}

#subtraction .sub-nav-back {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid #91b4a9;
  border-radius: 9px;
  background: #f8fcf4;
  color: var(--sub-ink);
  font-size: 13px;
  font-weight: 800;
}

.sub-heading, .sub-celebrate { text-align: center; }
.sub-heading h1, .sub-celebrate h1 { font-size: clamp(25px, 7.4vw, 32px); line-height: 1.2; }
.sub-heading p, .sub-celebrate p { color: var(--sub-muted); font-size: 14px; margin-top: 6px !important; }
.sub-village svg { display: block; width: 100%; height: auto; }

.sub-feature {
  display: grid;
  gap: 8px;
  padding: 13px;
  border: 1px solid var(--sub-border);
  border-bottom-width: 4px;
  border-radius: 15px;
  background: var(--sub-panel);
}

.sub-feature h2, .sub-section-title h2 { font-size: 19px; line-height: 1.3; }
.sub-feature p { color: var(--sub-muted); font-size: 13px; }
.sub-feature .sub-note { color: var(--sub-ink); font-weight: 700; }

#subtraction .sub-main {
  width: 100%;
  min-height: 50px;
  padding: 8px 10px;
  border: 1px solid #104639;
  border-bottom-width: 4px;
  border-radius: 11px;
  background: var(--sub-teal);
  color: #fffdf1;
  font-size: 17px;
  font-weight: 900;
}

.sub-section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 9px; }
.sub-section-title span { font-size: 12px; color: var(--sub-muted); }
.sub-level-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }

#subtraction .sub-tile {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  padding: 7px 6px 8px;
  border: 1px solid var(--sub-border);
  border-bottom-width: 3px;
  border-radius: 12px;
  background: #f9fbf3;
  color: var(--sub-ink);
  text-align: center;
}

#subtraction .sub-tile.is-built { border-color: #d3b877; background: #fff4d5; }
#subtraction .sub-tile.is-current { border-color: #4b8e73; background: #ebf8ec; }
#subtraction .sub-tile.is-locked { background: #e2ece7; }
.sub-tile-art svg { display: block; width: 100%; aspect-ratio: 300 / 190; height: auto; }
.sub-tile strong { font-size: 14px; }
.sub-tile small { color: var(--sub-muted); font-size: 11px; line-height: 1.35; }
.sub-rule { color: var(--sub-muted); text-align: center; font-size: 13px; line-height: 1.4; }

.sub-history {
  padding: 8px 12px;
  border: 1px solid var(--sub-border);
  border-radius: 11px;
  color: var(--sub-ink);
  background: var(--sub-panel);
  font-size: 13px;
}

.sub-history summary { display: list-item; padding-block: 10px; cursor: pointer; }
.sub-history ul { padding: 0; margin: 0; list-style: none; }
.sub-history li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid #dce6d4; }

.sub-round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 800;
}

.sub-markers { display: flex; gap: 4px; }
.sub-markers i { width: 13px; height: 11px; border: 1px solid #7ca397; border-radius: 2px; background: #f7fbf5; }
.sub-markers i.is-done { border-color: #1a604c; background: #43825b; }
.sub-prompt { text-align: center; font-size: clamp(23px, 6.8vw, 27px); line-height: 1.2; }

.sub-equation {
  color: #254849;
  font-family: 'Fredoka', 'Noto Sans TC', sans-serif;
  font-size: clamp(30px, 10vw, 43px);
  font-weight: 700;
  text-align: center;
  line-height: 1.15;
}

.sub-equation strong {
  display: inline-block;
  min-width: .85em;
  border-bottom: 3px solid #6f9886;
  color: #174c40;
}

.sub-board {
  display: grid;
  gap: 7px;
  padding: 7px 8px 9px;
  border: 1px solid #b9a982;
  border-bottom-width: 4px;
  border-radius: 13px;
  background: #fff9e9;
}

.sub-board-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 13px; }
.sub-moved-count { margin-left: 3px; font-variant-numeric: tabular-nums; }

#subtraction .sub-undo, #subtraction .sub-text-button {
  min-height: 44px;
  padding: 6px 10px;
  border: 1px solid #9eb8a9;
  border-radius: 8px;
  background: #f1f8ef;
  color: #234d43;
  font-weight: 800;
  font-size: 13px;
}

#subtraction .sub-undo:disabled { background: #f0eee4; border-color: #d4d2c5; color: #676b60; }
.sub-tenframe { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
#subtraction .sub-block {
  display: grid;
  place-items: center;
  min-height: 44px;
  min-width: 0;
  aspect-ratio: 1;
  padding: 1px;
  border: 1px solid #9bbcb9;
  border-radius: 8px;
  background: #e8f5ee;
}

#subtraction .sub-block[aria-pressed="true"] { border-style: dashed; border-color: #8b9a87; background: #f6f3e8; }
#subtraction .sub-block:disabled { opacity: 1; }
.sub-block svg { display: block; width: 100%; height: 100%; max-width: 56px; pointer-events: none; }
.sub-board-guide { min-height: 20px; color: #38595a; font-size: 13px; text-align: center; }

.sub-empty-board {
  grid-column: 1 / -1;
  min-height: 49px;
  display: grid;
  place-items: center;
  border: 1px dashed #b5b4a6;
  border-radius: 8px;
  color: var(--sub-muted);
  font-size: 15px;
}

.sub-choice-area { display: grid; gap: 8px; text-align: center; }
.sub-choice-area h2 { font-size: 19px; }
.sub-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
#subtraction .sub-answer {
  min-height: 53px;
  padding: 3px;
  border: 1px solid #82a895;
  border-bottom-width: 4px;
  border-radius: 10px;
  background: var(--sub-panel);
  color: #174b42;
  font-family: 'Fredoka', 'Noto Sans TC', sans-serif;
  font-size: 29px;
  font-weight: 700;
}

#subtraction button:active:enabled { translate: 0 1px; }
.sub-retry { padding: 5px 4px; border-radius: 8px; background: #fff0cb; color: #694815; font-size: 13px; }
.sub-celebrate h1 { font-size: clamp(23px, 7.3vw, 29px); }
.sub-building { display: grid; justify-items: center; gap: 3px; color: var(--sub-muted); font-size: 12px; }
.sub-building svg { display: block; width: 100%; max-width: 300px; height: clamp(100px, 31dvh, 190px); }

.sub-award {
  padding: 8px;
  border: 1px solid #d3b779;
  border-radius: 9px;
  background: #fff4d5;
  color: #654615;
  text-align: center;
  font-size: 14px;
}

.sub-award b { margin-right: 4px; font-family: 'Fredoka', sans-serif; font-size: 22px; }
.sub-error { display: grid; gap: 12px; padding: 16px 0; text-align: center; }
.sub-error h1 { font-size: 26px; }

@media (max-width: 350px) {
  .sub-page { padding: 10px 8px 15px; gap: 9px; }
  .sub-board { padding-inline: 6px; }
  .sub-tenframe { gap: 3px; }
  .sub-building svg { max-height: 155px; }
}

@media (prefers-reduced-motion: reduce) {
  #subtraction, #subtraction *, #subtraction *::before, #subtraction *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}

#openSubtraction .subtraction-ic {
  background: #1d7266;
  color: #fff5d7;
  border: 2px solid #124e49;
  box-shadow: inset 0 4px #4d9786;
  font-family: 'Fredoka', sans-serif;
  font-size: 30px;
}
