.hb-panel [hidden] { display: none; }
.hb-settings, .hb-actions { display: flex; gap: 8px; }
.hb-settings > button, .hb-actions > button { flex: 1; }
.hb-panel button { min-height: 44px; touch-action: manipulation; }
.hb-panel button:disabled { opacity: .5; cursor: default; }
.hb-panel :focus-visible { outline: 2px solid var(--play-accent); outline-offset: 2px; }
.hb-panel .btn--secondary { color: var(--play-text); background: var(--play-hud-bg); border: 1px solid var(--play-border); }
.hb-panel .btn--secondary:hover { background: var(--play-btn-hover); }
.hb-panel [aria-pressed="true"] { border-color: var(--play-accent); box-shadow: 0 0 0 2px var(--play-accent); }
.hb-settings > button[aria-pressed="true"] { background: color-mix(in srgb, var(--play-accent) 18%, var(--play-hud-bg)); color: var(--play-accent); box-shadow: none; }
.hb-play-area { grid-area: play; position: relative; min-width: 0; align-self: start; }
.hb-editor { border-radius: 8px; }
.hb-slots { display: flex; gap: 8px; }
.hb-slot { flex: 1; min-width: 0; min-height: 52px; border: 1px solid var(--play-border); border-radius: 8px; color: var(--play-text); background: var(--play-hud-bg); font: 700 1.8rem ui-monospace, monospace; cursor: pointer; }
.hb-validation { height: 3.2em; overflow-y: auto; margin: 8px 0; color: #f5dcb4; font-size: .8125rem; line-height: 1.6; }
.hb-pad { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.hb-key { border: 1px solid var(--play-border); border-radius: 8px; color: var(--play-text); background: var(--play-hud-bg); font: 600 1.35rem ui-monospace, monospace; cursor: pointer; }
.hb-key:hover:not(:disabled) { background: var(--play-btn-hover); }
.hb-input-actions > button { flex: 1; min-width: 0; padding-inline: 8px; gap: 4px; font-size: .75rem; white-space: nowrap; }
.hb-result { position: absolute; inset: 0; z-index: 2; height: fit-content; max-height: 100%; overflow-y: auto; margin: auto; padding: 14px; border: 1px solid var(--play-border); border-radius: 10px; background: var(--play-hud-bg); box-shadow: 0 12px 32px #0007; text-align: center; animation: hb-appear .2s ease-out; }
.hb-result h2 { font-size: 1.15rem; margin-top: 0; color: var(--play-text); }
.hb-result p { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.hb-history-section { grid-area: history; display: flex; flex-direction: column; min-height: 0; min-width: 0; height: 240px; margin: 0; padding: 8px; border: 1px solid var(--play-border); border-radius: var(--md-sys-shape-corner-medium); }
.hb-history-section h2 { flex: none; margin: 0 0 6px; font-size: .875rem; }
.hb-history-section > p { flex: none; margin: 4px 0; font-size: .8125rem; }
.hb-history-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.hb-table { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: .875rem; font-variant-numeric: tabular-nums; }
.hb-table th, .hb-table td { padding: 6px 2px; text-align: center; border-bottom: 1px solid var(--play-border); overflow-wrap: anywhere; }
.hb-table th { position: sticky; top: 0; z-index: 1; background: var(--play-hud-bg); font-size: .75rem; }
.hb-table th:nth-child(2), .hb-table td:nth-child(2) { width: 34%; white-space: nowrap; }
.hb-table td:nth-child(2) { font-family: ui-monospace, monospace; letter-spacing: .08em; }
.hb-table th:nth-child(3) { color: #8beaff; }
.hb-table th:nth-child(4) { color: #d5b5ff; }
.hb-table tbody tr:first-child { background: #203353; font-weight: 700; }
.hb-dialog { width: min(440px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 20px; border: 1px solid var(--play-border); border-radius: 16px; color: var(--play-text); background: var(--play-hud-bg); }
.hb-dialog h2 { font-size: 1.2rem; color: var(--play-text); }
.hb-dialog::backdrop { background: #08142bbb; }
.hb-sr-only, #hb-key-help { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
html.gs-playing .hb-panel { display: grid; grid-template-columns: 44px minmax(0, 506px); grid-template-rows: auto auto auto; grid-template-areas: "bar settings" "history history" "play play"; gap: 10px; justify-content: center; align-content: start; }
html.gs-playing .hb-panel > .gs-bar { grid-area: bar; margin: 0; }
/* 履歴は従来の高さを維持し、低い画面では外側のスクロールを許容する。 */
@media (max-width: 767px), (max-height: 599px) {
  html.gs-playing .hb-panel { overflow-y: auto; }
  .hb-slot { min-height: 48px; }
  .hb-validation { height: 3.2em; margin: 6px 0; }
  .hb-pad { gap: 6px; margin-bottom: 16px; }
  .hb-table th, .hb-table td { padding-block: 5px; }
}
/* PCもスマートフォンと同じ履歴→入力の1列配置にする。 */
@media (min-width: 768px) and (min-height: 600px) {
  html.gs-playing .hb-panel { grid-template-columns: 44px minmax(0, 580px); grid-template-rows: auto auto auto; grid-template-areas: "bar settings" "history history" "play play"; gap: 16px; align-content: start; padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top)); }
  .hb-settings, html.gs-playing .hb-panel > .gs-bar { margin-bottom: 12px; }
}
/* 横向きの低い画面では2列にし、入力をスクロールの外へ押し出さない。 */
@media (orientation: landscape) and (max-height: 500px) and (min-width: 568px) {
  html.gs-playing .hb-panel { grid-template-columns: 44px minmax(0, 266px) minmax(0, 314px); grid-template-rows: auto auto; grid-template-areas: "bar settings settings" "play play history"; gap: 8px; }
  .hb-history-section { height: 240px; }
}
@keyframes hb-appear { from { opacity: .5; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .hb-result { animation: none; } }

.hb-settings { grid-area: settings; margin: 0; }
.hb-extra-actions { margin-top: 16px; }
