#panel:has(.practice-story) {
  width: min(790px, 95vw);
  max-height: 94dvh;
  padding: clamp(14px, 3.5vw, 30px);
}
.practice-story { color: #294b3c; }
.practice-story header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding-right: 36px;
}
.practice-story #panel-title { margin: 0; font-size: clamp(22px, 4vw, 32px); }
.practice-element { font-size: 13px; font-weight: 700; color: #52694d; }
.practice-choices {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  margin: 14px 0;
}
.practice-choices button {
  min-height: 46px;
  padding: 5px 4px;
  background: #e6e9d4;
  border: 1px solid #afbea2;
  border-radius: 12px;
  color: #355341;
  font: inherit;
  font-weight: 700;
}
.practice-choices button[aria-pressed="true"] { background: #37604d; border-color: #254735; color: #fff9df; }
.practice-story button:focus-visible { outline: 3px solid #9a611d; outline-offset: 2px; }
.practice-workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  align-items: center;
  gap: 16px;
}
.practice-stage { position: relative; margin: 0; border: 1px solid #a0af8f; border-radius: 16px; overflow: hidden; background: #a6c49e; }
.practice-story .practice-stage canvas { width: 100%; height: auto; aspect-ratio: 760 / 382; object-fit: contain; display: block; }
.practice-stage .practice-replay {
  position: absolute;
  top: 4px;
  left: 4px;
  min-height: 44px;
  min-width: 64px;
  border: 0;
  border-radius: 12px;
  background: #f8f2dce8;
  color: #294837;
  font-weight: 700;
}
.practice-replay[hidden] { display: none; }
.practice-caption { display: block; color: #2b533f; font-size: 19px; }
.defense-options:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0,.85fr) minmax(0,1.15fr);
  gap: 5px;
  margin: 0 0 8px;
}
.defense-options button {
  min-width: 44px; min-height: 44px; padding: 5px 7px;
  border: 1px solid #8ba08b; border-radius: 10px;
  background: #faf5e2; color: #31503c; font: inherit; font-weight: 650;
}
.defense-options button[aria-pressed="true"] {
  background: #e0ebd3; box-shadow: inset 0 0 0 2px #507552;
}
.practice-story .practice-guide { margin: 5px 0 12px; color: #405b48; font-size: 16px; line-height: 1.55; }
.practice-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.practice-story .practice-actions button { min-height: 46px; margin: 0; padding: 8px 12px; font-size: 15px; }
.practice-story .practice-actions .primary { flex: 1 1 auto; }

@media (max-width: 600px) and (orientation: portrait) {
  .practice-workbench { grid-template-columns: 1fr; gap: 12px; }
  .practice-choices { margin: 11px 0; }
  .practice-stage { max-width: 480px; width: 100%; margin-inline: auto; }
  .practice-actions .primary { flex: 2; }
  .practice-actions .secondary { flex: 1; }
}
@media (orientation: landscape) and (max-height: 470px) {
  #panel:has(.practice-story) { width: min(760px, 96vw); padding: 12px 18px; max-height: 96dvh; }
  .practice-story #panel-title { font-size: 22px; }
  .practice-choices { margin: 6px 0 8px; }
  .practice-workbench { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; }
  .practice-stage { max-width: calc((96dvh - 118px) * 1.98); }
}

/* The result and its two touch targets share one stack. A longer result can
   wrap on a small phone without pushing an action on top of the HUD. */
#game-ui:has(#drill-choices:not([hidden])) {
  display: grid;
  grid-template-rows: max-content max-content;
  align-content: start;
  justify-items: center;
  row-gap: 6px;
}
#game-ui:has(#drill-choices:not([hidden])) #boss-hud {
  position: static;
  grid-row: 1;
  margin-top: max(10px, 3dvh);
}
#drill-choices:not([hidden]) {
  grid-row: 2;
  display: flex;
  gap: 7px;
  pointer-events: auto;
}
#drill-choices button {
  min-height: 44px;
  padding: 4px 14px;
  border: 1px solid #e4e2b1;
  border-radius: 12px;
  background: #285142;
  color: #faf3d7;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  touch-action: manipulation;
}
#drill-choices #drill-duel {
  background: #edcf8a;
  color: #254737;
}
#drill-choices button:focus-visible { outline-offset: 2px; }
#game-ui:has(#drill-choices:not([hidden])) #toast {
  /* The stopped round's same success sentence is already in #boss-counter. */
  display: none;
}
@media (orientation: portrait) {
  #game-ui:has(#drill-choices:not([hidden])) #boss-hud {
    width: 70%;
    justify-self: end;
    margin-right: 3%;
    margin-top: max(74px, 10dvh);
  }
  #drill-choices:not([hidden]) {
    width: 70%;
    justify-self: end;
    margin-right: 3%;
    justify-content: center;
  }
  #drill-choices button { padding-inline: 10px; }
}
@media (orientation: portrait) and (max-width: 360px) {
  #game-ui:has(#drill-choices:not([hidden])) #boss-hud,
  #drill-choices:not([hidden]) { width: calc(94% - 90px); }
  #game-ui:has(#drill-choices:not([hidden])) .auto-skill-panel { bottom: calc(3% + 110px); }
  #game-ui:has(#drill-choices:not([hidden])) #skill-selector small { display: none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  #game-ui:has(#drill-choices:not([hidden])) { row-gap: 4px; }
  #game-ui:has(#drill-choices:not([hidden])) #boss-hud { margin-top: max(48px, 12dvh); }
  #drill-choices button { padding-inline: 12px; }
}

.signal-entry { margin: 4px 0 12px; }
#panel:has(.signal-game) { width: min(790px,95vw); max-height:94dvh; padding:clamp(13px,3vw,24px); }
.signal-game { color:#294b3c; display:grid; grid-template-columns:minmax(0,1.45fr) minmax(165px,1fr); gap:8px 16px; }
.signal-game h2 { grid-column:1/-1; margin:0; padding-right:36px; font-size:clamp(23px,3vw,30px); }
.signal-game .signal-question { grid-column:1/-1; margin:0 0 4px; line-height:1.4; }
.signal-scene { grid-column:1; grid-row:3/6; width:100%; height:auto; aspect-ratio:760/382; align-self:center; border:1px solid #a8bda0; border-radius:12px; }
.signal-options { grid-column:2; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:7px; }
.signal-option { display:grid; grid-template-rows:1fr auto; justify-items:center; align-items:center; min-height:70px; padding:5px; color:#315242; background:#f1edcf; border:2px solid #aec49d; border-radius:12px; font:inherit; }
.signal-option canvas { width:min(100%,100px); height:auto; aspect-ratio:120/50; }
.signal-option b { font-size:clamp(12px,2vw,15px); }
.signal-option:disabled { cursor:default; opacity:.8; }
.signal-option.correct { border-color:#387e60; background:#d4e7be; opacity:1; }
.signal-game #signal-result { grid-column:2; margin:0; color:#345943; font-weight:650; line-height:1.35; min-height:1.35em; }
.signal-actions { grid-column:2; display:flex; gap:6px; flex-wrap:wrap; align-items:start; }
.signal-actions button { min-height:44px; margin:0; padding:6px 10px; font-size:13px; }
.signal-game button:focus-visible { outline:3px solid #915d26; outline-offset:2px; }
@media (orientation:portrait), (max-width:580px) {
  .signal-game { display:flex; flex-direction:column; gap:7px; }
  .signal-question { padding-right:6px; }
  .signal-scene { max-height:24dvh; object-fit:contain; background:#dce7cf; }
  .signal-option { min-height:64px; }
}
@media (orientation:landscape) and (max-height:480px) {
  .signal-game { gap:4px 12px; }
  .signal-scene { max-height:45dvh; object-fit:contain; }
  .signal-option { min-height:56px; }
}
