/* The same keyboard shell serves every skill; fields choose text or math keys. */
#on-screen-keyboard-toggle {
  position: fixed;
  z-index: 61;
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(var(--site-keyboard-reserve, 0px) + 12px);
  min-height: 42px;
  padding: 7px 13px;
  border: 1px solid #a8c5d7;
  border-radius: 999px;
  background: #f2f8fc;
  color: #17354b;
  box-shadow: 0 5px 16px rgba(18, 53, 74, .16);
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
}
#on-screen-keyboard-toggle[aria-pressed="true"] { background: #dceefa; border-color: #85b3cd; }
#on-screen-keyboard-toggle:focus-visible,
#on-screen-keyboard .site-keyboard-key:focus-visible { outline: 3px solid #387da6; outline-offset: 2px; }

#on-screen-keyboard {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(8px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(100%, 1080px);
  padding: 12px 14px 10px;
  border: 1px solid #c8dce9;
  border-radius: 16px;
  background: #f2f8fc;
  color: #17354b;
  box-shadow: 0 -8px 24px rgba(18, 53, 74, .12);
  touch-action: manipulation;
}
.site-keyboard-controlled { caret-color: transparent; }
#site-keyboard-caret-mirror {
  position: fixed;
  z-index: 59;
  box-sizing: border-box;
  overflow: hidden;
  border-style: solid;
  border-color: transparent;
  background: transparent;
  color: transparent;
  pointer-events: none;
  transform-origin: top left;
}
#site-keyboard-caret-mirror[hidden] { display: none; }
#site-keyboard-caret-mirror .site-keyboard-caret-mark {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  vertical-align: -0.18em;
  animation: site-keyboard-caret-blink 1s steps(1, end) infinite;
}
@keyframes site-keyboard-caret-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #site-keyboard-caret-mirror .site-keyboard-caret-mark { animation: none; }
}
#on-screen-keyboard .site-keyboard-keys { display: grid; gap: 5px; }
#on-screen-keyboard .site-keyboard-row { display: flex; gap: 5px; }
#on-screen-keyboard[data-layout="text"] .site-keyboard-middle { padding-inline: 4.8%; }
#on-screen-keyboard .site-keyboard-key {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 2px;
  border: 1px solid #c8dce9;
  border-radius: 7px;
  background: #fff;
  color: #17354b;
  box-shadow: 0 2px 0 #b4ccda;
  font-size: 1rem;
  font-weight: 550;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#on-screen-keyboard .site-keyboard-key:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
#on-screen-keyboard .site-keyboard-action { background: #dceefa; }
#on-screen-keyboard .site-keyboard-wide { flex: 1.35 1 0; }
#on-screen-keyboard[data-layout="text"] .site-keyboard-space { flex: 4 1 0; }
#on-screen-keyboard .site-keyboard-key:disabled { opacity: .38; cursor: default; box-shadow: none; }

#on-screen-keyboard[data-layout="math"] .site-keyboard-row {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 6px;
}
#on-screen-keyboard[data-layout="math"] .site-keyboard-key { width: 100%; font-size: 1.0625rem; }
#on-screen-keyboard[data-layout="math"] .site-keyboard-key[data-key="Space"],
#on-screen-keyboard[data-layout="math"] .site-keyboard-key[data-key="Enter"] { font-size: .75rem; }
#on-screen-keyboard .site-keyboard-labeled {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}
#on-screen-keyboard .site-keyboard-symbol { font-size: 1.375rem; line-height: .9; }
#on-screen-keyboard .site-keyboard-caption { font-size: .6875rem; line-height: 1; font-weight: 400; }

/* Reserve the dock height in both the ordinary and centered practice frames. */
body.site-keyboard-open:not(:has(.equations-practice-view:not([hidden]))) .app-shell {
  padding-bottom: calc(var(--site-keyboard-reserve, 0px) + 24px);
}
body.site-keyboard-open #practice-view { padding-top: 8px; }
body.site-keyboard-open #practice-view .problem-card {
  min-height: min(430px, max(190px, calc(var(--allowable-space-height, 100vh) - 140px)));
}
body.site-keyboard-open .equations-work-panel {
  max-height: calc(100dvh - var(--site-keyboard-reserve, 0px) - 24px);
}

@media (max-width: 620px) {
  #on-screen-keyboard { padding: 9px 9px 8px; }
  #on-screen-keyboard[data-layout="math"] .site-keyboard-row {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
  #on-screen-keyboard .site-keyboard-row { gap: 3px; }
}
@media (max-width: 390px) {
  #on-screen-keyboard[data-layout="math"] .site-keyboard-row {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  #on-screen-keyboard[data-layout="text"] .site-keyboard-key { font-size: .8125rem; }
}
