* { box-sizing: border-box; }
:root { color-scheme: light; --primary: #FF8A3D; --ink: #2A4936; }
html, body { margin: 0; min-height: 100%; background: #fff6eb; color: var(--ink); font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; }
button, select, input { font: inherit; }
button, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .4; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid #0BB747; outline-offset: 2px; }
.page { max-width: 480px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom)); }
.controls { display: flex; align-items: end; gap: 10px; }
.controls label { flex: 1; min-width: 0; font-size: 12px; color: #56856A; }
select { display: block; width: 100%; margin-top: 6px; min-height: 44px; border: 1px solid #B6E8CC; border-radius: 12px; background: #fffdf8; padding: 0 8px; color: var(--ink); font-weight: 600; }
.primary { min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--primary); color: #0E3F22; font-weight: 700; }
.status { display: flex; gap: 28px; align-items: center; padding: 20px 4px 16px; }
.status > div { display: flex; flex-direction: column; gap: 4px; }
.status > div > span { color: #5C9473; font-size: 12px; }
.status strong { font-size: 23px; font-variant-numeric: tabular-nums; }
.candidate-toggle { margin-left: auto; display: flex; gap: 7px; align-items: center; min-height: 44px; font-size: 13px; cursor: pointer; }
.candidate-toggle input { width: 19px; height: 19px; accent-color: #21DF64; }
.board { display: grid; aspect-ratio: 1; border: 2px solid #488860; border-radius: 8px; overflow: hidden; background: #488860; }
.cell { position: relative; min-width: 0; min-height: 0; padding: 0; background: #fffdfa; border: 0; border-right: 1px solid #dfcebc; border-bottom: 1px solid #dfcebc; color: #18C453; font-size: clamp(20px, 6vw, 29px); font-weight: 600; display: flex; align-items: center; justify-content: center; }
.cell.fixed { background: #f5ebdf; color: #2A4936; font-weight: 700; }
.cell.box-right { border-right: 2px solid #488860; }
.cell.box-bottom { border-bottom: 2px solid #488860; }
.cell.selected { background: #ffe0ba; box-shadow: inset 0 0 0 2px var(--primary); z-index: 1; }
.cell.invalid { background: #ffe1df; color: #39B72F; }
.cell.invalid.selected { box-shadow: inset 0 0 0 2px #3FC940; }
.candidates { position: absolute; inset: 3px; display: grid; grid-auto-rows: 1fr; font-size: clamp(9px, 2.5vw, 12px); color: #78A28A; font-weight: 400; line-height: 1; pointer-events: none; }
.candidates span { display: flex; align-items: center; justify-content: center; }
.message { min-height: 22px; margin: 14px 0; text-align: center; font-size: 13px; color: #488661; line-height: 1.6; }
.number-pad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.number-pad button { min-height: 49px; background: #fffdf8; border: 1px solid #ACE6C6; border-radius: 12px; color: #15B74A; font-size: 24px; font-weight: 600; }
.number-pad button:active:not(:disabled), .actions button:active:not(:disabled) { background: #ffe0ba; }
.actions { display: flex; gap: 10px; margin-top: 12px; }
.actions button { flex: 1; min-height: 46px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid #ACE6C6; border-radius: 12px; background: #ffedda; color: #2E6945; font-size: 15px; }
.actions .mp-icon { font-size: 20px; }
.help { margin: 16px 0 0; text-align: center; color: #699A7E; font-size: 12px; line-height: 1.7; }
@media (max-width: 350px) { .page { padding-left: 10px; padding-right: 10px; } .status { gap: 18px; } .controls { gap: 6px; } }

/* Only the two existing action areas gain compact rewarded-video entries. */
.action-group { display: flex; flex: 1; align-items: center; gap: 4px; min-width: 0; }
.actions .action-group > button:not(.ad-entry) { min-width: 0; gap: 3px; }
.actions .ad-entry { flex: 0 1 44%; min-width: 0; min-height: 44px; padding: 3px 4px; gap: 1px; border: 1px solid var(--primary); border-radius: 22px; background: #fff5e9; color: #13A345; font-size: 10px; line-height: 1.25; }
.actions .ad-entry .mp-icon { flex-shrink: 0; font-size: 15px; }
.ad-label { display: block; text-align: center; }
.ad-label small { display: block; margin-top: 2px; font-size: 9px; font-variant-numeric: tabular-nums; }
.actions .ad-entry[data-state="disabled"] { background: #eee9e3; border-color: #d4cec7; color: #999087; }
.actions .ad-entry[data-state="loading"] { opacity: .6; }
.actions .ad-entry[data-state="loading"] .mp-icon { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: ad-spin .8s linear infinite; background: none; mask: none; -webkit-mask: none; }
.actions .ad-entry[data-state="loading"] .mp-icon::before { content: none; }
.ad-credit { padding: 1px 3px; border-radius: 6px; background: #ffe0ba; color: #13A345; font-size: 10px; }
.ad-credit[hidden], .ad-toast[hidden] { display: none; }
.ad-toast { position: fixed; z-index: 20; left: 50%; bottom: max(28px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: #2A4936; color: #fff; font-size: 14px; line-height: 1.5; text-align: center; pointer-events: none; }
@keyframes ad-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .actions .ad-entry[data-state="loading"] .mp-icon { animation: none; } }

.bgm-toggle { flex: 0 0 44px; width: 44px; height: 44px; min-height: 44px; padding: 0; border: 1px solid #B6E8CC; border-radius: 12px; background: #fffdf8; color: var(--primary); display: flex; align-items: center; justify-content: center; }
.bgm-toggle .mp-off { display: none; }
.bgm-toggle.is-muted { color: #7E9A88; }
.bgm-toggle.is-muted .mp-on { display: none; }
.bgm-toggle.is-muted .mp-off { display: inline-block; }
#bgm { position: absolute; width: 0; height: 0; opacity: 0; pointer-events: none; }

/* Keep the full number pad directly below the board on short screens. */
.board { grid-auto-rows: minmax(0, 1fr); }
.number-pad { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; margin-top: 8px; }
.number-pad button { min-width: 0; min-height: 44px; padding: 0; border-radius: 8px; font-size: 20px; }
.message { min-height: 21px; margin: 4px 0; }
.actions { margin-top: 4px; }

@media (max-height: 700px) {
  .page { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .status { padding-top: 4px; padding-bottom: 4px; }
  .status strong { font-size: 19px; }
  .board { width: clamp(200px, calc(100vh - 245px), 100%); width: clamp(200px, calc(100svh - 245px), 100%); max-width: 100%; margin-inline: auto; }
  .cell { font-size: 18px; }
  .candidates { inset: 1px; font-size: 8px; }
}

@media (max-width: 350px) {
  .actions { gap: 6px; }
  .actions .action-group > button:not(.ad-entry) { padding-inline: 3px; font-size: 13px; }
  .actions .ad-entry .mp-icon { display: none; }
}
