/* =====================================================================
   TECLADO VIRTUAL DEL DICTADO
   Cada tema = una clase .kb-theme-<id> que solo define variables.
   Para añadir otro tema: copiar un bloque de variables y registrarlo en THEMES (keyboard.js).
   ===================================================================== */

/* ---------- variables por defecto (= gaming) */
.vkb, .kbt {
  --plate-bg: #050507; --plate-border: rgba(255, 255, 255, .06); --plate-shadow: 0 20px 50px rgba(0, 0, 0, .6);
  --key-bg: linear-gradient(180deg, #1c1c22, #0f0f13); --key-fn-bg: linear-gradient(180deg, #24242c, #15151b);
  --key-border: rgba(255, 255, 255, .08); --key-side: #000; --key-text: #f4f4f8; --key-sub: rgba(255, 255, 255, .45);
  --key-glow: rgba(255, 255, 255, .55); --key-flash: rgba(255, 255, 255, .55); --key-shadow: rgba(0, 0, 0, .7);
  --key-depth: 4px; --key-radius: 7px; --key-font: var(--sans, Inter, system-ui, sans-serif); --key-weight: 700; --key-text-glow: none;
  --led: linear-gradient(90deg, #ff004c, #ff8a00, #ffe600, #29ff6a, #00e5ff, #2f6bff, #b400ff, #ff004c, #ff8a00, #ffe600, #29ff6a, #00e5ff, #2f6bff, #b400ff, #ff004c);
  --led-speed: 6s; --led-opacity: .5;
}
.kb-theme-gaming { --led-opacity: .5; }
/* gaming: la luz solo se escapa por los huecos entre teclas, el marco queda oscuro */
.kb-theme-gaming .kb-plate::before { content: ""; position: absolute; inset: 0; z-index: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 clamp(5px, .9vw, 9px) #050507, inset 0 0 26px 10px rgba(5, 5, 7, .9); }
.kb-theme-gaming .kc { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 0 0 1px rgba(0, 0, 0, .8); }
.kb-theme-retro {
  --plate-bg: linear-gradient(180deg, #d6cdb6, #b9ae94); --plate-border: rgba(0, 0, 0, .25); --plate-shadow: 0 20px 50px rgba(0, 0, 0, .65), inset 0 1px 0 rgba(255, 255, 255, .5);
  --key-bg: linear-gradient(180deg, #f6f0e0, #e3d9c1); --key-fn-bg: linear-gradient(180deg, #a9a08b, #8f8672);
  --key-border: rgba(60, 50, 30, .25); --key-side: #9a9079; --key-text: #2a251c; --key-sub: rgba(42, 37, 28, .55);
  --key-glow: rgba(255, 246, 220, .0); --key-flash: rgba(255, 255, 255, .7); --key-shadow: rgba(40, 30, 10, .5);
  --key-depth: 6px; --key-radius: 5px; --key-font: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace; --key-weight: 700;
  --led-opacity: 0;
}
.kb-theme-retro .fn .kc { color: #f3eee0; }
.kb-theme-cyber {
  --plate-bg: linear-gradient(rgba(255, 43, 214, .06) 1px, transparent 1px) 0 0 / 100% 14px, linear-gradient(90deg, rgba(25, 240, 255, .05) 1px, transparent 1px) 0 0 / 14px 100%, #07030d;
  --plate-border: rgba(255, 43, 214, .45); --plate-shadow: 0 0 40px rgba(255, 43, 214, .22), 0 0 80px rgba(25, 240, 255, .1), 0 20px 50px rgba(0, 0, 0, .7);
  --key-bg: linear-gradient(180deg, #120a1e, #0a0612); --key-fn-bg: linear-gradient(180deg, #071a22, #050d12);
  --key-border: #ff2bd6; --key-side: #2b0730; --key-text: #ffd9f7; --key-sub: rgba(127, 246, 255, .75);
  --key-glow: #ff2bd6; --key-flash: rgba(25, 240, 255, .8); --key-shadow: rgba(255, 43, 214, .25);
  --key-depth: 3px; --key-radius: 4px; --key-text-glow: 0 0 8px rgba(255, 43, 214, .9);
  --led: linear-gradient(90deg, #ff2bd6, #19f0ff, #ff2bd6, #19f0ff, #ff2bd6); --led-speed: 9s; --led-opacity: .5;
}
.kb-theme-cyber .fn .kc { border-color: #19f0ff; color: #c9fbff; text-shadow: 0 0 8px rgba(25, 240, 255, .9); }
.kb-theme-cyber .fn { --key-glow: #19f0ff; }
.kb-theme-glass {
  --plate-bg: linear-gradient(145deg, rgba(255, 255, 255, .09), rgba(255, 255, 255, .02)); --plate-border: rgba(255, 255, 255, .16);
  --plate-shadow: inset 0 1px 0 rgba(255, 255, 255, .2), 0 20px 50px rgba(0, 0, 0, .45);
  --key-bg: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, .05)); --key-fn-bg: linear-gradient(180deg, rgba(255, 93, 122, .26), rgba(255, 93, 122, .08));
  --key-border: rgba(255, 255, 255, .24); --key-side: rgba(255, 255, 255, .05); --key-text: #fff; --key-sub: rgba(255, 255, 255, .5);
  --key-glow: rgba(255, 255, 255, .7); --key-flash: rgba(255, 255, 255, .6); --key-shadow: rgba(0, 0, 0, .3);
  --key-depth: 3px; --key-radius: 11px; --key-weight: 600; --led-opacity: 0;
}

/* ---------- placa */
.vkb { max-width: 900px; margin: clamp(6px, 1.2vh, 14px) auto 0; }
.kb-plate { position: relative; overflow: hidden; isolation: isolate; padding: clamp(8px, 1.2vh, 12px) clamp(8px, 1.1vw, 12px); border-radius: 16px;
  background: var(--plate-bg); border: 1px solid var(--plate-border); box-shadow: var(--plate-shadow); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.kb-theme-glass .kb-plate { -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4); }
/* luces LED: capa arcoiris que se desliza (solo transform) y se ve entre las teclas */
.kb-led { position: absolute; z-index: -1; top: -10%; bottom: -10%; left: 0; width: 300%; background: var(--led); opacity: var(--led-opacity);
  filter: blur(7px); animation: kbLed var(--led-speed) linear infinite; will-change: transform; transition: opacity .5s; }
@keyframes kbLed { to { transform: translateX(-50%); } }
.kb-keys { position: relative; z-index: 1; container-type: inline-size; display: flex; flex-direction: column; gap: calc(var(--gap, 5px) + 2px); }
.kb-row { --gap: clamp(3px, .5vw, 6px); --u: calc((100cqw - 12 * var(--gap)) / 13); --kh: min(calc(var(--u) * .92), clamp(26px, 5.2vh, 46px));
  display: flex; justify-content: center; gap: var(--gap); padding-top: var(--key-depth); }

/* ---------- tecla: base (lado) + keycap que se hunde (solo transform) */
.k { position: relative; flex: 0 0 calc(var(--u) * var(--w) + var(--gap) * (var(--w) - 1)); height: var(--kh); border-radius: var(--key-radius);
  background: var(--key-side); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.k::before { content: ""; position: absolute; z-index: -1; left: 6%; right: 6%; top: 30%; bottom: -5px; border-radius: inherit; background: var(--key-shadow);
  filter: blur(5px); transition: opacity 110ms ease-out; }
.kc { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 4px; overflow: hidden; border-radius: inherit;
  background: var(--key-bg); border: 1px solid var(--key-border); color: var(--key-text); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
  font: var(--key-weight) calc(var(--kh) * .36)/1 var(--key-font); text-shadow: var(--key-text-glow);
  transform: translateY(calc(-1 * var(--key-depth))); transition: transform 100ms cubic-bezier(.2, .9, .3, 1); }
.fn .kc { background: var(--key-fn-bg); font-size: calc(var(--kh) * .3); letter-spacing: .02em; }
.kc i { position: absolute; top: 12%; left: 14%; font: 600 calc(var(--kh) * .24)/1 var(--key-font); font-style: normal; color: var(--key-sub); }
.kc b { font-weight: inherit; }
/* brillo al pulsar (pre-pintado, solo opacity) */
.kc::before { content: ""; position: absolute; inset: 0; border-radius: inherit; opacity: 0; pointer-events: none; transition: opacity 120ms ease-out;
  box-shadow: inset 0 0 0 1px var(--key-glow), inset 0 0 14px var(--key-glow); }
/* destello / ripple */
.kc::after { content: ""; position: absolute; left: 50%; top: 50%; width: 140%; aspect-ratio: 1; margin: -70% 0 0 -70%; border-radius: 50%; pointer-events: none; opacity: 0;
  background: radial-gradient(circle, var(--key-flash) 0%, transparent 60%); transform: scale(.3); }
.k.flash .kc::after { animation: kbFlash 380ms cubic-bezier(.2, .8, .3, 1); }
@keyframes kbFlash { 0% { opacity: .9; transform: scale(.3); } 100% { opacity: 0; transform: scale(1.15); } }
.k.pressed .kc { transform: translateY(calc(-.15 * var(--key-depth))); transition-duration: 70ms; }
.k.pressed::before { opacity: .35; }
.k.pressed .kc::before { opacity: 1; }
.k:hover .kc { filter: brightness(1.15); }
.space .kc b::before { content: "space"; font-size: calc(var(--kh) * .26); letter-spacing: .3em; text-transform: uppercase; opacity: .45; }
/* shift: letras en mayuscula */
.shifted .k[data-code^="Key"] .kc b { text-transform: uppercase; }
.shifted .shift .kc::before { opacity: .8; }
.vkb:not(.shifted) .k[data-code^="Key"] .kc b { text-transform: lowercase; }

/* ---------- feedback acierto / error: ola de luz por las teclas */
.kb-good { --fb: #39e58c; } .kb-bad { --fb: #ff3b55; }
.kb-good .kc::before, .kb-bad .kc::before { box-shadow: inset 0 0 0 1px var(--fb), inset 0 0 16px var(--fb); animation: kbPulse 900ms ease-out both; animation-delay: calc(var(--n) * 7ms); }
@keyframes kbPulse { 0% { opacity: 0; } 25% { opacity: 1; } 100% { opacity: 0; } }
.kb-good .kb-plate { box-shadow: var(--plate-shadow), 0 0 0 1px rgba(57, 229, 140, .5), 0 0 40px rgba(57, 229, 140, .25); }
.kb-bad .kb-plate { box-shadow: var(--plate-shadow), 0 0 0 1px rgba(255, 59, 85, .5), 0 0 40px rgba(255, 59, 85, .22); }

/* ---------- barra de herramientas (en la cabecera del dictado) */
.kb-tools { display: flex; align-items: center; gap: 8px; order: 3; }
.dgame .dg-hud .dg-stats { margin-left: auto; order: 2; }
.kb-themes { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .08); }
.kbt { position: relative; display: flex; align-items: flex-end; justify-content: center; gap: 2px; width: 38px; height: 28px; padding: 0 0 5px; border-radius: 8px; cursor: pointer; overflow: hidden;
  background: var(--plate-bg); border: 1px solid var(--plate-border); opacity: .6; transition: opacity .2s, transform .2s, box-shadow .2s; }
.kbt i { width: 8px; height: 8px; border-radius: 2px; background: var(--key-bg); border: 1px solid var(--key-border); box-shadow: 0 2px 0 var(--key-side); }
.kbt.kb-theme-gaming::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--led); }
.kbt:hover { opacity: .9; transform: translateY(-1px); }
.kbt.on { opacity: 1; box-shadow: 0 0 0 2px #fff; }
.kbt:focus-visible, .kb-ibtn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.kb-ibtn { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border-radius: 10px; cursor: pointer; font-size: 16px; color: #fff;
  background: rgba(255, 255, 255, .06); border: 1px solid rgba(255, 255, 255, .1); transition: background .2s; }
.kb-ibtn:hover { background: rgba(255, 255, 255, .14); }
.kb-ibtn.on { background: rgba(255, 255, 255, .16); border-color: rgba(255, 255, 255, .35); }
.kb-show { display: none; }
.vkb.collapsed .kb-plate { display: none; }

/* =====================================================================
   DICTADO EN UNA SOLA PANTALLA (sin la tarjeta "La frase")
   ===================================================================== */
#player:has(.stage.dict) .study { display: none; }
#player:has(.stage.dict) .cinema { height: calc(100vh - var(--hdr, 67px)); height: calc(100dvh - var(--hdr, 67px)); min-height: 0; }
#player:has(.stage.dict) .stage { min-height: 110px; }
.cinema-view .dictbox.dgame { padding: clamp(8px, 1.4vh, 14px) clamp(16px, 4vw, 48px) clamp(8px, 1.6vh, 16px); }
.dgame .dg-hud { margin-bottom: clamp(4px, 1vh, 10px); }
.dgame .dg-bar { margin-bottom: clamp(6px, 1.3vh, 14px); }
.dgame .dg-slots { margin-bottom: clamp(6px, 1.3vh, 14px); min-height: 0; }
.dg-slot { height: clamp(28px, 4.2vh, 40px); }
.dictbox.dgame form { max-width: 900px; }
.dictbox.dgame .dictbtn, .dictbox.dgame input, .dictbox.dgame .dictgo { height: clamp(38px, 5.4vh, 48px); }
.dgame .dictbtn.dg-play { width: clamp(38px, 5.4vh, 48px); }
.dgame .dictres { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px 12px; margin-top: 6px; font-size: 14px; }
.dgame .dictres:empty { display: none; }
.dgame .dictres .dg-legend { margin-top: 0; }

@media (max-width: 760px), (pointer: coarse) {
  .kb-show { display: grid; }
  .kb-themes .kbt { width: 30px; height: 24px; }
  .kb-row { --kh: min(calc(var(--u) * 1.25), clamp(30px, 5.6vh, 44px)); }
  .kc i { display: none; }
}
@media (max-width: 760px) {
  .dgame .dg-hud { gap: 8px; }
  .kb-tools { width: 100%; justify-content: flex-end; }
  .kb-plate { padding: 6px 4px; border-radius: 12px; }
  .kb-row { --gap: 3px; }
}
@media (prefers-reduced-motion: reduce) {
  .kb-led { animation: none; }
  .k.flash .kc::after, .kb-good .kc::before, .kb-bad .kc::before { animation: none; }
  .kc { transition-duration: 1ms; }
}
