:root {
  --app-accent: #49c7b5;
  --app-accent-soft: #e8f9f5;
  --hb-navy: var(--ink);
  --hb-coral: var(--coral);
  --hb-yellow: var(--yellow);
  --hb-teal: var(--app-accent);
  --hb-purple: var(--purple);
  --hb-paper: var(--paper);
  --hb-muted: var(--muted);
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hb-frame {
  background:
    radial-gradient(circle at 7% 10%, rgba(255, 201, 79, .3), transparent 25%),
    radial-gradient(circle at 92% 85%, rgba(73, 199, 181, .25), transparent 28%),
    #edf2f7;
}

.hb-frame .notebook { min-height: min(900px, calc(100vh - 28px)); }
.hb-header { gap: 18px; }
.hb-header .brand { min-width: 0; }
.hb-header .brand > span:last-child { min-width: 0; }
.hb-header .brand strong,
.hb-header .brand small,
.hb-frame h1,
.hb-frame h2,
.tray-heading span,
.hb-frame button { white-space: nowrap; }
.hb-frame h1,
.hb-frame h2 { max-width: none; }
.hb-frame p { line-break: strict; word-break: normal; }
.hb-brand-mark { background: var(--hb-teal); font-size: 28px; }
.hb-small-button,
.hb-primary-button,
.hb-secondary-button {
  min-height: 48px;
  border: 3px solid var(--hb-navy);
  border-radius: 14px;
  color: var(--hb-navy);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}

.hb-small-button {
  padding: 8px 18px;
  background: #fff;
  box-shadow: 3px 4px 0 var(--hb-navy);
}

.hb-primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-width: 250px;
  padding: 13px 24px;
  background: var(--hb-yellow);
  box-shadow: 5px 6px 0 var(--hb-navy);
  font-size: 18px;
}

.hb-secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  background: #fff;
  box-shadow: 3px 4px 0 var(--hb-navy);
  text-decoration: none;
}

.hb-small-button:hover,
.hb-primary-button:hover,
.hb-secondary-button:hover { transform: translateY(-2px); }
.hb-small-button:active,
.hb-primary-button:active,
.hb-secondary-button:active { transform: translate(2px, 3px); box-shadow: 1px 2px 0 var(--hb-navy); }
.hb-small-button:focus-visible,
.hb-primary-button:focus-visible,
.hb-secondary-button:focus-visible { outline: 4px solid rgba(73, 199, 181, .35); outline-offset: 4px; }

.hb-screen { padding: clamp(20px, 4vw, 42px); }
.intro-screen { text-align: center; }
.hb-hero {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: start;
  min-height: 0;
  margin-bottom: 18px;
  padding-right: 0;
  text-align: left;
}

.hb-hero h1 {
  margin: 4px 0 12px;
  color: var(--hb-navy);
  font-size: clamp(30px, 4.4vw, 54px);
  line-height: 1.08;
  letter-spacing: .02em;
}
.hb-hero h1,
.hb-hero p:last-child { max-width: 640px; }
.hb-hero h1 em { margin-left: .18em; color: var(--hb-coral); font-style: normal; }
.hb-hero p:last-child { max-width: 560px; margin: 0; color: var(--hb-muted); line-height: 1.75; }

.mystery-digits {
  position: static;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 12px 0 0;
  transform: rotate(1.2deg) scale(.72);
  transform-origin: left center;
}
.hb-mini-doodle { position: absolute; top: -36px; left: -38px; width: 70px; transform: rotate(-7deg); }
.mystery-digits span,
.answer-digits span {
  display: grid;
  place-items: center;
  width: clamp(68px, 9vw, 92px);
  aspect-ratio: .78;
  border: 3px solid var(--hb-navy);
  border-radius: 18px;
  color: var(--hb-navy);
  box-shadow: 5px 7px 0 var(--hb-navy);
  font-size: clamp(38px, 6vw, 58px);
  font-weight: 900;
}
.mystery-digits span:nth-of-type(1), .answer-digits span:nth-child(1) { background: #ffeba6; }
.mystery-digits span:nth-of-type(2), .answer-digits span:nth-child(2) { background: #bdebdc; }
.mystery-digits span:nth-of-type(3), .answer-digits span:nth-child(3) { background: #ffd0c4; }

.rule-sheet,
.guess-sheet,
.history-sheet {
  border: 2px solid var(--hb-navy);
  border-radius: 20px;
  background: rgba(255, 253, 248, .92);
  box-shadow: 4px 5px 0 rgba(32, 50, 77, .15);
}
.rule-sheet { margin-bottom: 22px; padding: 20px; text-align: left; }
.rule-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.rule-grid article {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 5px 12px;
  min-height: 110px;
  padding: 15px;
  border-radius: 15px;
  background: #fff;
}
.rule-grid article p { grid-column: 2; margin: 0; color: var(--hb-muted); font-size: 13px; line-height: 1.5; }
.rule-icon {
  grid-row: 1 / 3;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 2px solid var(--hb-navy);
  border-radius: 13px;
  color: var(--hb-navy);
  font-size: 20px;
}
.hit-icon { background: var(--hb-teal); }
.blow-icon { background: var(--hb-yellow); }
.digit-icon { background: #ddd2f7; font-size: 14px; }

.hb-frame .game-screen { padding: clamp(18px, 4vw, 38px); }
.hb-topline { align-items: flex-end; margin-bottom: 22px; }
.hb-topline h1 { margin: 3px 0 0; font-size: clamp(25px, 4vw, 38px); }
.attempt-counter {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 110px;
  padding: 10px 14px;
  border: 2px solid var(--hb-navy);
  border-radius: 14px;
  background: #fff0ad;
  color: var(--hb-navy);
}
.attempt-counter small { font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.attempt-counter strong { font-size: 30px; }
.attempt-counter span { font-size: 13px; font-weight: 800; }

.guess-sheet { padding: clamp(20px, 4vw, 30px); text-align: center; }
.guess-prompt h2 { margin: 0; font-size: 25px; }
.guess-prompt p { margin: 5px 0 20px; color: var(--hb-muted); }
.guess-digits {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 20px;
}
.guess-digits span {
  display: grid;
  place-items: center;
  width: clamp(68px, 10vw, 84px);
  height: clamp(76px, 11vw, 92px);
  border: 3px solid var(--hb-navy);
  border-radius: 16px;
  background: #fffdf8;
  color: var(--hb-navy);
  box-shadow: 4px 5px 0 var(--hb-navy);
  font-size: clamp(36px, 6vw, 48px);
  font-weight: 900;
}
.guess-digits span:nth-child(1) { background: #ffeba6; }
.guess-digits span:nth-child(2) { background: #bdebdc; }
.guess-digits span:nth-child(3) { background: #ffd0c4; }
.guess-digits span.is-empty { color: #9aa4b4; background: #fff; box-shadow: 2px 3px 0 var(--hb-navy); }
.number-pad {
  display: grid;
  grid-template-columns: repeat(5, minmax(52px, 68px));
  justify-content: center;
  gap: 10px;
  margin: 0 auto 18px;
}
.number-pad button {
  min-width: 52px;
  min-height: 58px;
  border: 3px solid var(--hb-navy);
  border-radius: 14px;
  background: #fff;
  color: var(--hb-navy);
  box-shadow: 3px 4px 0 var(--hb-navy);
  font: 900 25px / 1 "Yu Gothic", system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
.number-pad button:nth-child(3n + 1) { background: #fff0ad; }
.number-pad button:nth-child(3n + 2) { background: #c8f2e8; }
.number-pad button:nth-child(3n) { background: #ffd8d0; }
.number-pad button:active { transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--hb-navy); }
.number-pad button.is-selected,
.number-pad button:disabled { cursor: default; opacity: .28; transform: translate(2px, 3px); box-shadow: 1px 1px 0 var(--hb-navy); }
.number-pad button:focus-visible { outline: 4px solid rgba(73, 199, 181, .35); outline-offset: 3px; }
.guess-actions { display: flex; align-items: center; justify-content: center; gap: 12px; }
.compact-button { min-width: 116px; background: #fff; }
.judge-button { min-width: 180px; box-shadow: 4px 5px 0 var(--hb-navy); }
.guess-actions button[disabled] { cursor: not-allowed; opacity: .38; box-shadow: 1px 2px 0 var(--hb-navy); transform: none; }
.input-help { margin: 14px 0 0; color: var(--hb-muted); font-size: 13px; }
.input-error { min-height: 24px; margin: 7px 0 0; color: #d94435; font-weight: 800; }
.guess-sheet.has-error { animation: hb-shake .25s linear 1; border-color: #d94435; }
@keyframes hb-shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.history-sheet { margin-top: 22px; padding: 22px; }
.empty-history { display: flex; align-items: center; justify-content: center; gap: 12px; min-height: 90px; color: var(--hb-muted); }
.empty-history span { font-size: 28px; }
.empty-history p { margin: 0; }
.history-table-wrap { overflow-x: auto; }
.history-table-wrap table { width: 100%; border-collapse: separate; border-spacing: 0 8px; }
.history-table-wrap th { padding: 4px 10px; color: var(--hb-muted); font-size: 12px; text-align: center; }
.history-table-wrap th,
.history-table-wrap td { white-space: nowrap; }
.history-table-wrap td { padding: 10px; background: #fff; text-align: center; }
.history-table-wrap td:first-child { border-radius: 12px 0 0 12px; color: var(--hb-muted); font-weight: 800; }
.history-table-wrap td:last-child { border-radius: 0 12px 12px 0; }
.history-number { font-size: 24px; font-weight: 900; letter-spacing: .16em; }
.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 62px;
  min-height: 38px;
  border: 2px solid var(--hb-navy);
  border-radius: 12px;
  color: var(--hb-navy);
  font-weight: 900;
}
.hit-pill { background: #bdebdc; }
.blow-pill { background: #ffeba6; }
.history-row-new { animation: hb-row-in .25s ease-out; }
@keyframes hb-row-in { from { opacity: 0; transform: translateY(-8px); } }

@media (min-width: 860px) {
  .hb-frame .game-screen:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, .72fr);
    gap: 16px 20px;
    align-items: start;
  }
  .hb-frame .game-screen .hb-topline {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }
  .hb-frame .game-screen .guess-sheet {
    min-height: 100%;
  }
  .hb-frame .game-screen .history-sheet {
    align-self: stretch;
    margin-top: 0;
    max-height: min(570px, calc(100dvh - 190px));
    overflow: auto;
  }
  .history-table-wrap table { border-spacing: 0 6px; }
  .history-table-wrap td { padding: 8px 6px; }
  .history-number { font-size: 21px; }
}

.success-screen { padding: clamp(40px, 8vw, 90px) 24px; text-align: center; }
.success-screen::before,
.success-screen::after { content: "✦  ✧  ✦"; display: block; color: var(--hb-yellow); font-size: 34px; letter-spacing: .4em; }
.success-screen h1 { margin: 8px 0; color: var(--hb-coral); font-size: clamp(44px, 8vw, 72px); }
.success-screen > p:not(.eyebrow):not(.success-count) { color: var(--hb-muted); }
.answer-digits { display: flex; justify-content: center; gap: 13px; margin: 28px 0; }
.success-count { margin: 16px 0 28px; color: var(--hb-navy); font-size: 22px; font-weight: 800; }
.success-count strong { color: var(--hb-coral); font-size: 42px; }
.success-actions { display: flex; justify-content: center; gap: 16px; }

.rules-dialog {
  width: min(520px, calc(100% - 30px));
  border: 3px solid var(--hb-navy);
  border-radius: 22px;
  color: var(--hb-navy);
  box-shadow: 8px 10px 0 var(--hb-navy);
}
.rules-dialog::backdrop { background: rgba(32, 50, 77, .6); backdrop-filter: blur(2px); }
.rules-dialog form { position: relative; padding: 15px; }
.rules-dialog h2 { margin: 4px 0 18px; }
.rules-dialog ol { padding-left: 24px; line-height: 1.8; }
.dialog-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: #edf2f7;
  color: var(--hb-navy);
  font-size: 24px;
  cursor: pointer;
}
.rule-example { display: grid; gap: 5px; padding: 14px; border-radius: 14px; background: #fff0ad; }

@media (max-width: 720px) {
  .hb-frame .notebook { min-height: calc(100vh - 12px); }
  .hb-header .brand strong { font-size: clamp(11px, 3.2vw, 14px); }
  .hb-header .brand small { font-size: 9px; }
  .hb-small-button { min-height: 44px; padding: 7px 12px; }
  .intro-screen { text-align: left; }
  .hb-hero {
    display: grid;
    min-height: 0;
    margin-bottom: 12px;
    padding-right: 0;
    text-align: left;
  }
  .hb-hero p:last-child { margin-inline: 0; }
  .mystery-digits {
    gap: 5px;
    margin-right: 0;
    transform: rotate(1.2deg) scale(.58);
    transform-origin: left center;
  }
  .hb-mini-doodle { top: -42px; left: -30px; width: 68px; }
  .rule-grid { grid-template-columns: 1fr; }
  .rule-grid article { min-height: 82px; }
  .guess-actions { flex-wrap: wrap; }
  .judge-button { order: -1; width: min(330px, 100%); }
  .hb-topline { align-items: center; }
  .attempt-counter { min-width: 88px; }
  .success-actions { flex-direction: column; align-items: stretch; width: min(320px, 100%); margin: 0 auto; }
  .success-actions .hb-primary-button { min-width: 0; }
}

@media (max-width: 430px) {
  .hb-screen, .hb-frame .game-screen { padding: 8px 12px 14px; }
  .hb-header { gap: 8px; }
  .hb-header .brand-mark { width: 46px; height: 46px; font-size: 23px; }
  .hb-header .brand strong { font-size: 11px; }
  .hb-header .brand small { font-size: 7px; letter-spacing: .1em; }
  .intro-screen { padding-top: 8px; }
  .hb-hero { min-height: 0; margin-bottom: 8px; padding-right: 0; }
  .hb-hero h1 { margin-bottom: 6px; font-size: clamp(24px, 6.4vw, 30px); }
  .hb-hero p:last-child { font-size: 12px; line-height: 1.55; }
  .mystery-digits { transform: rotate(1.2deg) scale(.44); width: 112px; margin-top: 5px; }
  .mystery-digits span { width: 56px; border-radius: 14px; }
  .hb-mini-doodle { display: none; }
  .rule-sheet, .history-sheet { padding: 10px; }
  .rule-sheet { margin-bottom: 14px; }
  .rule-sheet .tray-heading { margin-top: 0; }
  .rule-sheet .tray-heading small { display: none; }
  .rule-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .rule-grid article {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 5px;
    min-height: 0;
    padding: 9px 5px;
    text-align: center;
  }
  .rule-grid article p { display: none; }
  .rule-icon {
    grid-row: auto;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    font-size: 17px;
  }
  .digit-icon { font-size: 12px; }
  .intro-screen > .hb-primary-button {
    display: flex;
    width: min(280px, 100%);
    min-width: 0;
    min-height: 48px;
    margin: 0 auto;
    padding: 10px 18px;
    font-size: 16px;
  }
  .hb-topline { margin-bottom: 6px; }
  .hb-topline .eyebrow { margin-bottom: 1px; font-size: 9px; }
  .hb-topline h1 { font-size: 19px; }
  .attempt-counter { min-width: 66px; padding: 5px 8px; border-radius: 12px; }
  .attempt-counter small { font-size: 9px; }
  .attempt-counter strong { font-size: 20px; }
  .attempt-counter span { font-size: 11px; }
  .guess-sheet { padding: 8px 9px 7px; }
  .guess-prompt h2 { font-size: 18px; }
  .guess-prompt p { display: none; }
  .guess-digits { gap: 7px; margin-bottom: 8px; }
  .guess-digits span {
    width: 50px;
    height: 55px;
    border-radius: 13px;
    box-shadow: 2px 3px 0 var(--hb-navy);
    font-size: 30px;
  }
  .history-sheet { margin-top: 4px; }
  .history-sheet .tray-heading { margin-top: 0; margin-bottom: 4px; }
  .empty-history { min-height: 30px; font-size: 11px; }
  .empty-history span { font-size: 18px; }
  .history-table-wrap { overflow-x: auto; }
  .number-pad { grid-template-columns: repeat(5, minmax(40px, 1fr)); gap: 5px; margin-bottom: 7px; }
  .number-pad button { min-width: 0; min-height: 39px; border-width: 2px; border-radius: 11px; font-size: 19px; box-shadow: 2px 2px 0 var(--hb-navy); }
  .guess-actions { gap: 6px; }
  .judge-button { min-height: 40px; }
  .compact-button { min-width: 92px; min-height: 36px; padding-inline: 8px; border-width: 2px; font-size: 12px; }
  .input-help { margin-top: 5px; font-size: 11px; }
  .input-error { min-height: 14px; margin-top: 1px; font-size: 11px; }
  .history-table-wrap th, .history-table-wrap td { padding: 6px 4px; }
  .history-number { font-size: 21px; }
  .score-pill { min-width: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
