:root {
  --hyaku: #48c9b0;
  --hyaku-soft: #e8f9f5;
  --hyaku-warm: #fff0ec;
  --hyaku-blue: #eaf2ff;
}

.hyakumasu-screen { padding: clamp(12px, 2.6vw, 28px); }
.hyakumasu-screen[hidden] { display: none; }

.hyakumasu-frame,
.hyakumasu-frame button,
.hyakumasu-frame select {
  touch-action: manipulation;
}

.hyakumasu-frame button {
  -webkit-user-select: none;
  user-select: none;
}

.hyakumasu-goal {
  display: grid;
  gap: 2px;
  text-align: right;
}
.hyakumasu-goal span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.hyakumasu-goal strong {
  color: var(--ink);
  font-size: 18px;
  white-space: nowrap;
}

#homeScreen {
  display: grid;
  grid-template-columns: minmax(310px, .82fr) minmax(360px, 1fr);
  gap: clamp(18px, 4vw, 42px);
  align-items: start;
}
#homeScreen[hidden] { display: none; }

.hyakumasu-hero {
  display: grid;
  gap: 16px;
}
.hyakumasu-hero h1,
.result-screen h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(36px, 5.6vw, 68px);
  line-height: 1.04;
  letter-spacing: 0;
}
.hyakumasu-hero h1 em,
.result-screen h1 em {
  color: var(--coral);
  font-style: normal;
  white-space: nowrap;
}

.hyakumasu-hero-art {
  display: block;
  width: min(470px, 100%);
  height: auto;
  border: 2px solid var(--ink);
  border-radius: 20px 16px 22px 18px;
  background: white;
  box-shadow: 3px 4px 0 var(--ink);
}

.print-mode-entry {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: min(470px, 100%);
  min-height: 88px;
  padding: 15px 17px;
  border: 2px solid var(--ink);
  border-radius: 16px 13px 18px 14px;
  background: var(--hyaku-soft);
  box-shadow: 3px 4px 0 var(--ink);
  color: var(--ink);
  text-decoration: none;
  touch-action: manipulation;
  transition: transform .14s ease, box-shadow .14s ease;
}
.print-mode-entry > svg:first-child {
  color: var(--mint);
}
.print-mode-entry span {
  display: grid;
  gap: 3px;
  min-width: 0;
}
.print-mode-entry strong {
  font-size: 20px;
  line-height: 1.15;
}
.print-mode-entry small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.print-mode-entry:hover {
  transform: translateY(-2px);
  box-shadow: 4px 6px 0 var(--ink);
}
.print-entry-arrow {
  color: var(--coral);
}

.hyakumasu-panel,
.question-card,
.grid-card,
.keypad-card {
  border: 2px solid var(--ink);
  border-radius: 20px 16px 22px 18px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 3px 4px 0 var(--ink);
}

.home-control-stack {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.setup-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.section-heading span {
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}
.section-heading small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.compact-heading { margin-top: 4px; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.mode-button,
.pattern-button,
.fixed-select,
.hyakumasu-primary-button,
.hyakumasu-secondary-button,
.hyakumasu-quiet-button,
.keypad button {
  color: var(--ink);
  font: inherit;
}
.mode-button {
  display: grid;
  gap: 4px;
  min-height: 86px;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 16px 13px 18px 14px;
  background: var(--button-bg, var(--paper));
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
  text-align: left;
}
.mode-button:nth-child(1) { --button-bg: var(--hyaku-soft); }
.mode-button:nth-child(2) { --button-bg: var(--hyaku-warm); }
.mode-button:nth-child(3) { --button-bg: var(--yellow-soft); }
.mode-button:nth-child(4) { --button-bg: var(--hyaku-blue); }
.mode-button strong {
  font-size: 22px;
  line-height: 1;
  white-space: nowrap;
}
.mode-button small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.mode-button.is-selected {
  outline: 4px solid rgba(72, 201, 176, .28);
  transform: translateY(-2px);
  box-shadow: 3px 5px 0 var(--ink);
}

.pattern-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(148px, .72fr);
  gap: 10px;
}
.pattern-segment {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: white;
  box-shadow: 2px 3px 0 var(--ink);
}
.pattern-button,
.fixed-select {
  min-height: 52px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: white;
  font-weight: 900;
}
.pattern-button {
  display: grid;
  gap: 3px;
  align-content: center;
  padding: 7px 8px;
  cursor: pointer;
}
.pattern-button strong {
  font-size: 16px;
  line-height: 1;
}
.pattern-button small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  font-weight: 900;
}
.pattern-button.is-selected {
  background: var(--hyaku-soft);
  border-color: var(--ink);
  box-shadow: inset 0 -3px 0 rgba(32, 50, 77, .16);
}
.pattern-button:not(.is-selected) {
  color: var(--muted);
}
.pattern-button:not(.is-selected) small {
  color: #8d98a8;
}
.fixed-select {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  align-items: center;
  padding: 0 10px;
  border-color: #d5dde9;
  box-shadow: none;
  opacity: .45;
  pointer-events: none;
}
.fixed-select.is-active {
  border-color: var(--ink);
  box-shadow: 2px 3px 0 var(--ink);
  opacity: 1;
  pointer-events: auto;
}
.fixed-select span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.fixed-select select {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
}

.home-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.home-summary div {
  padding: 10px;
  border: 1.5px solid #d9e0ea;
  border-radius: 14px;
  background: #fbfcff;
}
.home-summary small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.home-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  white-space: nowrap;
}

.ranking-panel {
  display: grid;
  gap: 9px;
  min-width: 0;
  padding-top: 12px;
  border-top: 1.5px solid #d9e0ea;
  text-align: left;
}
.home-ranking-panel {
  padding: 14px;
  border-top: 2px solid var(--ink);
}
.result-ranking-panel {
  margin-top: 16px;
  padding: 14px;
  border-top: 2px solid var(--ink);
}
.ranking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ranking-head span {
  display: block;
  color: var(--ink);
  font-size: 17px;
  font-weight: 900;
}
.ranking-head small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.ranking-refresh-button,
.ranking-delete-button {
  min-height: 34px;
  border: 1.5px solid var(--ink);
  border-radius: 11px;
  background: white;
  box-shadow: 1.5px 2px 0 var(--ink);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
}
.ranking-refresh-button {
  min-width: 54px;
}
.ranking-delete-button {
  min-height: 30px;
  padding: 3px 8px;
}
.ranking-status {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
.ranking-list {
  display: grid;
  gap: 5px;
}
.ranking-row {
  display: grid;
  grid-template-columns: 34px minmax(78px, 1fr) auto auto;
  gap: 7px;
  align-items: center;
  min-width: 0;
  padding: 7px 8px;
  border: 1.5px solid #d9e0ea;
  border-radius: 12px;
  background: #fbfcff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}
.ranking-row.is-mine {
  border-color: var(--ink);
  background: var(--yellow-soft);
  box-shadow: 1.5px 2px 0 var(--ink);
}
.ranking-row b,
.ranking-row span,
.ranking-row time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ranking-row em {
  color: var(--coral);
  font-style: normal;
}
.ranking-row .ranking-delete-button {
  grid-column: 1 / -1;
  justify-self: end;
}

.hyakumasu-primary-button,
.hyakumasu-secondary-button {
  display: grid;
  place-items: center;
  min-height: 52px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  box-shadow: 3px 4px 0 var(--ink);
  cursor: pointer;
  font-weight: 900;
}
.hyakumasu-primary-button { background: var(--yellow); }
.hyakumasu-secondary-button { background: white; }

.game-topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
}
.game-meter { display: grid; gap: 7px; }
.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e7ed;
}
.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--hyaku);
  transition: width .16s ease;
}
.timer-card {
  min-width: 118px;
  padding: 8px 12px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  background: var(--hyaku-soft);
  box-shadow: 2px 3px 0 var(--ink);
  text-align: center;
}
.timer-card small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
}
.timer-card strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
  white-space: nowrap;
}
.hyakumasu-quiet-button {
  min-height: 44px;
  padding: 8px 14px;
  border: 1.5px solid #cbd3df;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  font-weight: 900;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(246px, 300px);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}
.question-card {
  grid-column: 1 / 3;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 110px;
  padding: 14px 18px;
}
.question-card p {
  margin: 0;
}
#questionIndex {
  display: grid;
  place-items: center;
  min-width: 76px;
  min-height: 42px;
  border-radius: 999px;
  background: var(--hyaku-blue);
  font-weight: 900;
}
.question-card h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .26em;
  margin: 0;
  font-size: clamp(36px, 5.8vw, 64px);
  line-height: 1;
  letter-spacing: 0;
}
.question-card h2 i {
  color: var(--coral);
  font-style: normal;
}
.question-card h2 em {
  min-width: 1.3em;
  color: var(--ink);
  font-style: normal;
}
.feedback-text {
  min-width: 132px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 900;
  text-align: right;
}
.feedback-text.is-bad { color: #d84b35; }
.feedback-text.is-good { color: #16826d; }

.grid-card {
  padding: 12px;
}
.grid-shell {
  display: grid;
  gap: 3px;
  width: 100%;
}
.grid-shell.with-headers {
  grid-template-columns: 34px repeat(10, minmax(0, 1fr));
}
.grid-shell.no-headers {
  grid-template-columns: repeat(10, minmax(0, 1fr));
}
.grid-cell,
.grid-head,
.grid-corner {
  display: grid;
  place-items: center;
  min-height: 36px;
  border-radius: 8px;
  font-weight: 900;
}
.grid-head,
.grid-corner {
  background: var(--hyaku-blue);
  color: var(--ink);
  font-size: 13px;
}
.grid-corner { color: var(--coral); }
.grid-cell {
  border: 1.5px solid #d2dbea;
  background: white;
  color: var(--ink);
  font-size: 14px;
}
.grid-cell.is-current {
  border-color: var(--ink);
  background: var(--yellow-soft);
  box-shadow: inset 0 0 0 2px var(--yellow);
}
.grid-cell.is-done {
  background: var(--hyaku-soft);
  border-color: #b6e9df;
}
.grid-cell.had-miss {
  background: var(--hyaku-warm);
  border-color: #f5b4a7;
}

.keypad-card {
  padding: 12px;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 9px;
}
.keypad button {
  grid-column: span 2;
  min-height: 62px;
  border: 2px solid var(--ink);
  border-radius: 15px 12px 16px 13px;
  background: var(--paper);
  box-shadow: 2px 3px 0 var(--ink);
  cursor: pointer;
  font-size: 26px;
  font-weight: 900;
}
.keypad button:nth-child(3n+1) { background: var(--hyaku-soft); }
.keypad button:nth-child(3n+2) { background: var(--yellow-soft); }
.keypad button:nth-child(3n+3) { background: var(--hyaku-blue); }
.keypad button[data-action] {
  background: white;
  font-size: 18px;
}
.keypad .wide-key {
  grid-column: span 3;
  min-height: 66px;
}
.keypad button:active {
  transform: translateY(2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.result-screen {
  text-align: center;
}
.rank-stamp {
  display: inline-grid;
  place-items: center;
  min-width: 128px;
  min-height: 64px;
  margin: 12px auto;
  padding: 0 18px;
  border: 3px solid var(--ink);
  border-radius: 20px 14px 22px 16px;
  background: var(--yellow);
  box-shadow: 4px 5px 0 var(--ink);
  color: var(--ink);
  font-size: 30px;
  font-weight: 900;
  transform: rotate(-2deg);
}
.rank-stamp.secret {
  background: var(--hyaku-warm);
  color: var(--coral);
}
.result-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 14px auto;
}
.result-stats div {
  padding: 12px 8px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  background: white;
  box-shadow: 2px 3px 0 var(--ink);
}
.result-stats small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.result-stats strong {
  display: block;
  margin-top: 5px;
  font-size: 21px;
  white-space: nowrap;
}
.result-message {
  min-height: 24px;
  color: var(--muted);
  font-weight: 900;
}
.history-panel {
  margin-top: 16px;
  padding: 14px;
  text-align: left;
}
.chart-wrap {
  margin: 10px 0 12px;
  padding: 10px;
  border: 1.5px solid #d9e0ea;
  border-radius: 14px;
  background: #fbfcff;
}
.chart-wrap svg {
  display: block;
  width: 100%;
  height: auto;
}
.history-table-wrap {
  overflow-x: auto;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table th,
.history-table td {
  padding: 8px 7px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.history-table th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}
.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: min(520px, 100%);
  margin: 16px auto 0;
}

.mode-button:focus-visible,
.pattern-button:focus-visible,
.fixed-select select:focus-visible,
.hyakumasu-primary-button:focus-visible,
.hyakumasu-secondary-button:focus-visible,
.hyakumasu-quiet-button:focus-visible,
.ranking-refresh-button:focus-visible,
.ranking-delete-button:focus-visible,
.print-mode-entry:focus-visible,
.keypad button:focus-visible {
  outline: 5px solid rgba(72, 136, 229, .3);
  outline-offset: 4px;
}

@media (max-width: 940px) {
  #homeScreen {
    display: block;
  }
  .hyakumasu-hero {
    grid-template-columns: 1fr minmax(240px, 390px);
    align-items: end;
  }
  .hyakumasu-hero > div {
    grid-column: 1;
    grid-row: 1;
  }
  .hyakumasu-hero-art {
    grid-column: 2;
    grid-row: 1 / span 2;
    width: 100%;
  }
  .print-mode-entry {
    grid-column: 1;
    grid-row: 2;
  }
  .setup-panel {
    margin-top: 16px;
  }
  .play-layout {
    grid-template-columns: 1fr;
  }
  .question-card {
    grid-column: auto;
  }
}

@media (max-width: 720px) {
  .hyakumasu-frame .app-header {
    padding-bottom: 8px;
  }
  .hyakumasu-screen {
    padding: 8px 6px 12px;
  }
  .hyakumasu-goal span { display: none; }
  .hyakumasu-goal strong { font-size: 13px; }
  .hyakumasu-hero {
    display: block;
  }
  .hyakumasu-hero h1 {
    font-size: clamp(30px, 9vw, 42px);
  }
  .hyakumasu-hero h1 br {
    display: none;
  }
  .hyakumasu-hero-art {
    display: none;
  }
  .print-mode-entry {
    display: grid;
    width: 100%;
    min-height: 64px;
    margin-top: 9px;
    padding: 9px 12px;
  }
  .print-mode-entry > svg:first-child { width: 27px; height: 27px; }
  .print-mode-entry strong { font-size: 16px; }
  .setup-panel {
    gap: 10px;
    margin-top: 10px;
    padding: 10px;
  }
  .mode-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }
  .mode-button {
    min-height: 58px;
    padding: 7px 5px;
    text-align: center;
    place-items: center;
  }
  .mode-button strong {
    font-size: 15px;
  }
  .mode-button small {
    display: none;
  }
  .pattern-row {
    grid-template-columns: 1fr;
    gap: 7px;
  }
  .pattern-segment { min-height: 46px; }
  .pattern-button,
  .fixed-select {
    min-height: 46px;
  }
  .home-summary strong {
    font-size: 15px;
  }
  .ranking-panel {
    gap: 7px;
    padding-top: 9px;
  }
  .ranking-row {
    grid-template-columns: 30px minmax(66px, 1fr) auto;
    gap: 5px;
    padding: 6px;
    font-size: 11px;
  }
  .ranking-row em {
    display: none;
  }
  .game-topbar {
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
  }
  .hyakumasu-quiet-button {
    min-height: 38px;
    padding-inline: 9px;
  }
  .timer-card {
    min-width: 86px;
    padding: 5px 7px;
  }
  .timer-card small { font-size: 9px; }
  .timer-card strong {
    font-size: 16px;
  }
  .play-layout {
    gap: 8px;
    margin-top: 8px;
  }
  .question-card {
    grid-template-columns: 1fr;
    gap: 4px;
    min-height: 0;
    padding: 8px;
    text-align: center;
  }
  #questionIndex {
    justify-self: center;
    min-width: 70px;
    min-height: 32px;
    font-size: 13px;
  }
  .question-card h2 {
    font-size: clamp(30px, 10vw, 42px);
  }
  .feedback-text {
    min-width: 0;
    min-height: 18px;
    font-size: 13px;
    text-align: center;
  }
  .grid-card {
    padding: 6px;
  }
  .grid-shell {
    gap: 2px;
  }
  .grid-shell.with-headers {
    grid-template-columns: 18px repeat(10, minmax(0, 1fr));
  }
  .grid-cell,
  .grid-head,
  .grid-corner {
    min-height: 16px;
    border-radius: 5px;
    font-size: 7px;
  }
  .grid-cell {
    font-size: 8px;
  }
  .grid-shell.no-headers .grid-cell {
    min-height: 18px;
  }
  .keypad-card {
    padding: 7px;
  }
  .keypad {
    gap: 5px;
  }
  .keypad button {
    min-height: 50px;
    font-size: 24px;
  }
  .keypad button[data-action] {
    font-size: 17px;
  }
  .keypad .wide-key { min-height: 56px; }
  .result-screen h1 {
    font-size: 36px;
  }
  .rank-stamp {
    min-height: 52px;
    font-size: 24px;
  }
  .result-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .history-panel {
    padding: 10px;
  }
  .result-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-height: 760px) and (min-width: 721px) {
  .hyakumasu-frame .app-header { padding-bottom: 8px; }
  .hyakumasu-frame .brand-logo.compact { width: 156px; }
  .hyakumasu-screen { padding: 10px 16px 12px; }
  .hyakumasu-hero-art { display: none; }
  .hyakumasu-hero h1 { font-size: clamp(34px, 5vw, 50px); }
  .setup-panel { padding: 12px; }
  .mode-button { min-height: 66px; }
  .question-card { min-height: 86px; }
  .grid-cell,
  .grid-head,
  .grid-corner { min-height: 30px; }
  .keypad button { min-height: 52px; }
}

@media (max-width: 720px) and (max-height: 720px) {
  .hyakumasu-frame .app-header { padding-bottom: 5px; }
  .hyakumasu-frame .brand-logo.compact { width: min(124px, 36vw); }
  .hyakumasu-screen { padding: 5px 6px 8px; }
  .game-topbar { gap: 6px; }
  .progress-track { height: 8px; }
  .timer-card {
    min-width: 78px;
    padding: 4px 6px;
    border-width: 1.5px;
  }
  .timer-card strong { font-size: 14px; }
  .hyakumasu-quiet-button {
    min-height: 32px;
    padding-inline: 8px;
    font-size: 14px;
  }
  .play-layout {
    gap: 6px;
    margin-top: 6px;
  }
  .question-card {
    padding: 6px;
    border-radius: 16px 13px 18px 14px;
  }
  #questionIndex {
    min-width: 58px;
    min-height: 24px;
    font-size: 12px;
  }
  .question-card h2 {
    font-size: clamp(27px, 9vw, 36px);
  }
  .grid-card,
  .keypad-card {
    padding: 5px;
    border-radius: 16px 13px 18px 14px;
  }
  .grid-shell { gap: 1.5px; }
  .grid-shell.with-headers {
    grid-template-columns: 16px repeat(10, minmax(0, 1fr));
  }
  .grid-cell,
  .grid-head,
  .grid-corner {
    min-height: 13px;
    border-radius: 4px;
    font-size: 6px;
  }
  .grid-cell {
    border-width: 1px;
    font-size: 7px;
  }
  .grid-shell.no-headers .grid-cell { min-height: 15px; }
  .keypad { gap: 4px; }
  .keypad button {
    min-height: 42px;
    border-width: 1.5px;
    border-radius: 11px 9px 12px 10px;
    box-shadow: 1.5px 2px 0 var(--ink);
    font-size: 22px;
  }
  .keypad button[data-action] { font-size: 15px; }
  .keypad .wide-key { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
