/* keyboard.css — Keyboard, special-keys, mouse, and history visuals. */

/* ---- Keyboard grid ---- */
/* The scroll wrapper is a query container, so keys size relative to the
   column they live in (narrow side-by-side column on desktop, full width on
   mobile) and the whole keyboard always fits without clipping. */
.keyboard-scroll {
  container-type: inline-size;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.keyboard {
  /* Fit the widest row (~15.75 units + inter-key gaps) into the container's
     inline size. Clamped so keys never get unusably small or oversized. */
  --key-unit: clamp(20px, calc((100cqi - 96px) / 16), 56px);
  --key-height: var(--key-unit);
  display: flex;
  flex-direction: column;
  gap: var(--key-gap);
  align-items: center;
  user-select: none;
}

.keyboard__row {
  display: flex;
  gap: var(--key-gap);
  justify-content: center;
  width: 100%;
}

/* A key. Width scales with its data-driven unit count via --w. */
.key {
  --w: 1;
  flex: 0 0 calc(var(--key-unit) * var(--w) + var(--key-gap) * (var(--w) - 1));
  min-width: 0;
  height: var(--key-height);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 2px 4px;
  background: var(--color-key-face);
  color: var(--color-key-text);
  border: 1px solid var(--color-key-border);
  border-radius: var(--radius-key);
  box-shadow: 0 1px 2px var(--color-key-shadow);
  font-size: clamp(0.62rem, 1.3vw, 0.82rem);
  line-height: 1.05;
  text-align: center;
  overflow: hidden;
  transition: transform var(--motion-release),
    background var(--motion-release), box-shadow var(--motion-release);
}

.key__label {
  font-weight: 500;
  white-space: nowrap;
}

.key__sub {
  font-size: 0.72em;
  color: var(--color-text-secondary);
}

.key--mod,
.key--fn,
.key--nav {
  font-size: clamp(0.55rem, 1.1vw, 0.72rem);
  color: var(--color-text-secondary);
}

/* Pressed state: scale-down + accent highlight + inset shadow. */
.key.is-pressed {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
  transform: scale(0.96);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform var(--motion-press), background var(--motion-press);
}

.key.is-pressed .key__sub {
  color: rgba(255, 255, 255, 0.85);
}

/* A momentary "flash" for keys that fire without a clean keyup (e.g. media). */
.key.is-flash {
  animation: keyflash 240ms ease-out;
}

@keyframes keyflash {
  0% {
    background: var(--color-accent);
    color: #fff;
  }
  100% {
    background: var(--color-key-face);
    color: var(--color-key-text);
  }
}

/* ---- Special & extended keys panel (de-emphasized) ---- */
.special-keys {
  margin-top: var(--space-2);
}

.special-keys__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--key-gap);
}

.special-keys__group-title {
  grid-column: 1 / -1;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin: var(--space-2) 0 4px;
}

.special-keys .key {
  --w: 1;
  flex: none;
  width: 100%;
  height: calc(var(--key-height) * 0.86);
  font-size: 0.68rem;
}

/* Overflow area for unrecognized/extended codes (e.g. F25+). */
.special-keys__overflow:empty {
  display: none;
}

/* ---- Mouse diagram ---- */
.mouse {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.mouse__svg {
  width: clamp(120px, 18vw, 160px);
  height: auto;
}

.mouse__zone {
  fill: var(--color-key-face);
  stroke: var(--color-key-border);
  stroke-width: 2;
  transition: fill var(--motion-release);
}

.mouse__zone.is-active {
  fill: var(--color-accent);
}

.mouse__body {
  fill: none;
  stroke: var(--color-text-secondary);
  stroke-width: 3;
}

/* Click ripple */
.ripple-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  overflow: hidden;
}

.ripple {
  position: absolute;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--color-accent) 60%, transparent);
  animation: ripple 500ms ease-out forwards;
}

@keyframes ripple {
  to {
    transform: scale(6);
    opacity: 0;
  }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
