/* The keyboard extension, in the DOM. Tokens and geometry from KeyboardPreviewView. */

.kb {
  --kw: 30px;
  --kh: 40px;
  --kgap: 4px;
  --krow: 8px;
  position: relative;
  padding: 7px;
  background: var(--kb-tray);
  border-radius: 18px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
  font-family: var(--font-text);
  color: var(--kb-ink);
}

.kb-strip { display: flex; align-items: center; gap: 5px; height: 32px; margin-bottom: var(--krow); padding-inline: 2px; }
.kb-pill {
  flex: none;
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 26px;
  border-radius: 9px;
  font-size: 13px;
  transition: transform var(--press);
  touch-action: manipulation;
}
.kb-pill:active, .kb-pill.is-down { transform: scale(0.92); }
.kb-pill-ink { background: var(--kb-ink); color: #fff; }
.kb-pill-white { background: #fff; color: var(--kb-ink); box-shadow: 0 1px 0 rgb(var(--shadow-ink) / 0.2); }
.kb-sep { flex: none; width: 1px; height: 20px; background: rgb(var(--shadow-ink) / 0.12); }
.kb-mid { position: relative; flex: 1; min-width: 0; height: 100%; overflow: hidden; }

.kb-preds { position: absolute; inset: 0; display: flex; align-items: center; font-size: 13px; transition: transform 380ms var(--spring-soft), opacity 180ms; }
.kb-preds span { flex: 1; min-width: 0; text-align: center; overflow: hidden; white-space: nowrap; }
.kb-preds span.is-first { font-weight: 600; }
.kb-preds i { flex: none; width: 1px; height: 18px; background: rgb(var(--shadow-ink) / 0.12); }
.kb-preds.is-empty span { visibility: hidden; }

.kb-tools { position: absolute; inset: 0; display: flex; align-items: center; gap: 3px; transform: translateX(-16px); opacity: 0; pointer-events: none; transition: transform 380ms var(--spring-soft), opacity 180ms; }
.kb-tool { display: inline-flex; align-items: center; justify-content: center; gap: 3px; flex: 1 1 auto; min-width: 0; height: 26px; padding: 0 5px; border-radius: 9px; background: rgb(255 255 255 / 0.62); font-size: 11.5px; font-weight: 500; white-space: nowrap; transition: transform var(--press), background 180ms; touch-action: manipulation; }
.kb-tool .icon { font-size: 11px; }
.kb-tool:active, .kb-tool.is-down { transform: scale(0.95); background: #fff; }
.tray-open .kb-preds { transform: translateX(16px); opacity: 0; pointer-events: none; }
.tray-open .kb-tools { transform: none; opacity: 1; pointer-events: auto; }
.kb-tool.is-hint { background: #fff; box-shadow: 0 0 0 1.5px var(--voice-deep); }

.kb-row { display: flex; justify-content: center; gap: var(--kgap); margin-bottom: var(--krow); }
.kb-row:last-child { margin-bottom: 0; }
.kb-spacer { flex: 1 1 0; max-width: 8px; min-width: 2px; }

.key {
  flex: none;
  display: grid;
  place-items: center;
  width: var(--kw);
  height: var(--kh);
  border-radius: max(calc(var(--kw) * 0.18), 4px);
  background: var(--kb-key);
  /* The system keyboard's key: a flat face with a one-point darker bottom edge. */
  box-shadow: 0 1px 0 rgb(var(--shadow-ink) / 0.3);
  color: var(--kb-ink);
  font-size: calc(var(--kh) * 0.5);
  line-height: 1;
  touch-action: pan-y;
  transition: background 80ms, transform 80ms;
  will-change: auto;
}
.key.is-down { background: var(--kb-pressed); }
.key-fn { width: calc(var(--kw) * 1.3); background: var(--kb-key-2); font-size: calc(var(--kh) * 0.36); }
.key-fn .icon { font-size: calc(var(--kh) * 0.46); }
.key-fn.is-down { background: #fff; }
.key-text { font-size: calc(var(--kh) * 0.34); }
.kb-row-bottom .key-return { width: calc(var(--kw) * 2.3); }
.key-return.is-send { background: var(--keyboard-deep); color: #fff; }
.key-space { flex: 1 1 auto; width: auto; min-width: 0; position: relative; background: var(--kb-key); color: rgb(17 17 20 / 0.7); font-size: calc(var(--kh) * 0.32); overflow: hidden; touch-action: none; cursor: grab; }
.key-space:active { cursor: grabbing; }
.key-space.is-down { background: var(--kb-pressed); }
.key-space small { position: absolute; top: 3px; inset-inline-end: 6px; font-size: calc(var(--kh) * 0.2); opacity: 0.55; }
.key-space-label { display: block; transition: transform 180ms var(--out); white-space: nowrap; }

/* The pop-up balloon that grows out of a pressed key */
.kb-balloon {
  --bx: 0px;
  --by: 0px;
  position: absolute;
  left: var(--bx);
  top: var(--by);
  z-index: 5;
  width: calc(var(--kw) * 1.52);
  height: calc(var(--kh) * 1.16);
  margin-left: calc(var(--kw) * -0.76);
  margin-top: calc(var(--kh) * -1.02);
  border-radius: calc(var(--kw) * 0.3);
  background: #fff;
  display: grid;
  place-items: center;
  font-size: calc(var(--kh) * 0.84);
  line-height: 1;
  pointer-events: none;
  opacity: 0;
  transform-origin: 50% 100%;
  filter: drop-shadow(0 2px 5px rgb(var(--shadow-ink) / 0.3));
  transform: scale(0.7);
}
.kb-balloon::after {
  content: "";
  position: absolute;
  left: calc(var(--kw) * 0.26);
  right: calc(var(--kw) * 0.26);
  top: calc(100% - 6px);
  height: calc(var(--kh) * 1.02);
  background: #fff;
  border-radius: 0 0 max(calc(var(--kw) * 0.18), 4px) max(calc(var(--kw) * 0.18), 4px);
}
.kb-balloon.is-on { opacity: 1; transform: none; transition: transform 90ms var(--out); }

/* Panels that take over from the keys, as "Translate To" and "Choose Tone" do */
.kb-panel { position: absolute; inset: 47px 7px 7px; z-index: 3; display: flex; flex-direction: column; background: #fff; border-radius: 14px; padding: 12px; box-shadow: 0 1px 0 rgb(var(--shadow-ink) / 0.14); overflow: hidden; }
.panel-open .kb-keys { visibility: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel-head b { font-family: var(--font-display); font-size: 14.5px; font-weight: 700; letter-spacing: -0.01em; }
.panel-close { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: #8d93a0; color: #fff; font-size: 11px; flex: none; transition: transform var(--press); }
.panel-close:active { transform: scale(0.9); }
.panel-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 6px; align-content: start; overflow-y: auto; scrollbar-width: none; }
.panel-grid::-webkit-scrollbar { display: none; }
.panel-opt { display: flex; align-items: center; gap: 6px; min-height: 29px; padding: 0 8px; border-radius: 9px; font-size: 12.5px; font-weight: 500; text-align: start; white-space: nowrap; overflow: hidden; transition: background 140ms, transform var(--press); touch-action: manipulation; }
.panel-opt:active { transform: scale(0.97); }
.panel-opt.is-on { background: var(--well); font-weight: 650; }
.panel-opt .icon { margin-inline-start: auto; font-size: 11px; opacity: 0; }
.panel-opt.is-on .icon { opacity: 1; }
.panel-cta { margin-top: 8px; min-height: 40px; border-radius: 12px; background: var(--kb-ink); color: #fff; font-family: var(--font-display); font-size: 14.5px; font-weight: 650; flex: none; transition: transform var(--press), opacity var(--press); touch-action: manipulation; }
.panel-cta:active { transform: scale(0.98); opacity: 0.9; }
.panel-result { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; font-size: 14px; line-height: 1.36; position: relative; padding-right: 22px; }
.panel-result::-webkit-scrollbar { display: none; }
.panel-status { font-family: var(--font-display); font-size: 14px; font-weight: 650; }
.panel-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; flex: none; }
.panel-actions button { display: inline-flex; align-items: center; gap: 5px; min-height: 36px; padding: 0 13px; border-radius: 11px; font-family: var(--font-display); font-size: 13.5px; font-weight: 650; transition: transform var(--press); touch-action: manipulation; }
.panel-actions button:active { transform: scale(0.97); }
.panel-copy { background: var(--well); }
.panel-replace { background: var(--kb-ink); color: #fff; }
.panel-actions .icon { font-size: 13px; }
/* A short window means a short keyboard. Tighter margins leave room for three lines of result. */
@media (max-height: 760px) and (min-width: 721px) {
  .kb-panel { padding: 8px 10px; }
  .panel-head { margin-bottom: 3px; }
  .panel-actions { margin-top: 4px; }
  .panel-actions button { min-height: 32px; }
}

/* The real keys come up under the 3D ones as they land, and go at once when they leave */
.kb-keys, .kb-strip { transition: opacity 90ms linear; }
.keys-hidden .kb-keys, .keys-hidden .kb-strip { opacity: 0; pointer-events: none; transition: none; }
.keys-hidden .kb-panel { opacity: 0; pointer-events: none; transition: opacity 180ms linear; }
