/* ── Base keycap ────────────────────────────────────────── */
.keycap {
  position: relative;
  width: var(--key-size);
  height: var(--key-size);
  border: none;
  border-radius: var(--key-radius);
  background: linear-gradient(to bottom, var(--key-body) 0%, var(--key-wall-front) 100%);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  contain: layout style;
  will-change: transform, box-shadow;

  /* 3D depth: tall bottom wall + layered shadows + inset concavity */
  box-shadow:
    /* primary bottom wall — the visible "stem" of the keycap */
    0 var(--key-depth) 0 0 var(--key-wall),
    /* secondary wall highlight (slight bevel at wall bottom) */
    0 var(--key-depth) 0 1px rgba(0, 0, 0, 0.4),
    /* ground shadow beneath wall */
    0 calc(var(--key-depth) + 5px) 14px rgba(0, 0, 0, 0.45),
    /* soft ambient shadow */
    0 calc(var(--key-depth) + 2px) 4px rgba(0, 0, 0, 0.25),
    /* top-edge highlight (concave dish illusion — light catching the rim) */
    inset 0 1px 1px rgba(255, 255, 255, 0.1),
    /* side edges — subtle left/right wall visibility */
    inset 1px 0 0 rgba(255, 255, 255, 0.03),
    inset -1px 0 0 rgba(0, 0, 0, 0.15),
    /* bottom-edge inner shadow (concavity of the dish) */
    inset 0 -2px 4px rgba(0, 0, 0, 0.35);

  /* Visible front face — border creates the "wall" you see from the tilted angle */
  border-bottom: 3px solid var(--key-wall-front);

  transform: translateY(0);
  transition:
    transform var(--release-duration) var(--release-easing),
    box-shadow var(--release-duration) var(--release-easing),
    border-bottom-width var(--release-duration) var(--release-easing);
}

/* Small variant (title row) */
.keycap--sm {
  width: var(--key-size-sm);
  height: var(--key-size-sm);
}

/* Spacer keys */
.keycap--spacer {
  cursor: pointer;
}

/* ── Legend (top surface) ──────────────────────────────── */
.keycap__legend {
  position: absolute;
  inset: var(--key-inset);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--key-radius) - 2px);
  /* Concave dish: lighter center fading to darker edges */
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.09) 0%, transparent 60%),
    linear-gradient(to bottom, var(--key-top) 0%, #433f3a 100%);
  color: var(--key-legend);
  font-family: var(--font-family);
  font-weight: 700;
  font-size: var(--legend-size);
  line-height: 1;
  pointer-events: none;
  /* Top surface sits above the walls */
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.05),
    inset 0 1px 2px rgba(255, 255, 255, 0.06),
    inset 0 -1px 2px rgba(0, 0, 0, 0.2);
}

.keycap--sm .keycap__legend {
  font-size: var(--legend-size-sm);
}

/* ── Glow pseudo-element ──────────────────────────────── */
.keycap::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: calc(var(--key-radius) + 4px);
  background: radial-gradient(circle, rgba(212, 207, 200, 0.3) 0%, transparent 70%);
  filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--release-duration) var(--release-easing);
}

/* ── Hover hit area extension (prevents jitter from below) */
.keycap::before {
  content: '';
  position: absolute;
  bottom: -12px;
  left: 0;
  right: 0;
  height: 12px;
}

/* ── Hover half-press (hint that keys are physical) ───── */
.keycap[data-letter]:hover:not(.keycap--pressed) {
  transform: translateY(1px);
  box-shadow:
    0 9px 0 0 var(--key-wall),
    0 9px 0 1px rgba(0, 0, 0, 0.4),
    0 14px 13px rgba(0, 0, 0, 0.43),
    0 11px 4px rgba(0, 0, 0, 0.23),
    inset 0 1px 1px rgba(255, 255, 255, 0.1),
    inset 1px 0 0 rgba(255, 255, 255, 0.03),
    inset -1px 0 0 rgba(0, 0, 0, 0.15),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35);
}

/* ── Pressed state ────────────────────────────────────── */
.keycap--pressed {
  /* Key drops down by the travel distance */
  transform: translateY(var(--key-press-depth));
  transition:
    transform var(--press-duration) ease-out,
    box-shadow var(--press-duration) ease-out,
    border-bottom-width var(--press-duration) ease-out;

  /* Wall compresses dramatically: from 10px to 3px */
  box-shadow:
    /* crushed wall — much shorter */
    0 var(--key-travel) 0 0 var(--key-wall),
    0 var(--key-travel) 0 1px rgba(0, 0, 0, 0.4),
    /* ground shadow tightens (key is closer to surface) */
    0 calc(var(--key-travel) + 2px) 6px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-travel) + 1px) 2px rgba(0, 0, 0, 0.2),
    /* inset highlights stay */
    inset 0 1px 1px rgba(255, 255, 255, 0.1),
    inset 1px 0 0 rgba(255, 255, 255, 0.03),
    inset -1px 0 0 rgba(0, 0, 0, 0.15),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35);

  /* Front face border shrinks */
  border-bottom-width: 1px;
}

.keycap--pressed::after {
  opacity: 1;
  transition: opacity var(--press-duration) ease-out;
}

/* ── Accent: Orange spacer ────────────────────────────── */
.keycap--accent-orange {
  background: linear-gradient(to bottom, var(--accent-orange) 0%, #c45f22 100%);
  border-bottom-color: #a84d1a;
  box-shadow:
    0 var(--key-depth) 0 0 #a84d1a,
    0 var(--key-depth) 0 1px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-depth) + 5px) 14px rgba(0, 0, 0, 0.45),
    0 calc(var(--key-depth) + 2px) 4px rgba(0, 0, 0, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.18),
    inset 1px 0 0 rgba(255, 255, 255, 0.06),
    inset -1px 0 0 rgba(0, 0, 0, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

.keycap--accent-orange .keycap__legend {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.12) 0%, transparent 60%),
    linear-gradient(to bottom, #f0833e 0%, #d46a28 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 1px 2px rgba(255, 255, 255, 0.08),
    inset 0 -1px 2px rgba(0, 0, 0, 0.15);
}

.keycap--accent-orange::after {
  background: radial-gradient(circle, rgba(232, 113, 42, 0.4) 0%, transparent 70%);
}

.keycap--accent-orange.keycap--pressed {
  box-shadow:
    0 var(--key-travel) 0 0 #a84d1a,
    0 var(--key-travel) 0 1px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-travel) + 2px) 6px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-travel) + 1px) 2px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.18),
    inset 1px 0 0 rgba(255, 255, 255, 0.06),
    inset -1px 0 0 rgba(0, 0, 0, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

/* ── Accent: Teal spacer ──────────────────────────────── */
.keycap--accent-teal {
  background: linear-gradient(to bottom, var(--accent-teal) 0%, #228a82 100%);
  border-bottom-color: #1e766e;
  box-shadow:
    0 var(--key-depth) 0 0 #1e766e,
    0 var(--key-depth) 0 1px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-depth) + 5px) 14px rgba(0, 0, 0, 0.45),
    0 calc(var(--key-depth) + 2px) 4px rgba(0, 0, 0, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.18),
    inset 1px 0 0 rgba(255, 255, 255, 0.06),
    inset -1px 0 0 rgba(0, 0, 0, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

.keycap--accent-teal .keycap__legend {
  background:
    radial-gradient(ellipse at 50% 35%, rgba(255, 255, 255, 0.12) 0%, transparent 60%),
    linear-gradient(to bottom, #34b5ab 0%, #289890 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.08),
    inset 0 1px 2px rgba(255, 255, 255, 0.08),
    inset 0 -1px 2px rgba(0, 0, 0, 0.15);
}

.keycap--accent-teal::after {
  background: radial-gradient(circle, rgba(42, 161, 152, 0.4) 0%, transparent 70%);
}

.keycap--accent-teal.keycap--pressed {
  box-shadow:
    0 var(--key-travel) 0 0 #1e766e,
    0 var(--key-travel) 0 1px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-travel) + 2px) 6px rgba(0, 0, 0, 0.4),
    0 calc(var(--key-travel) + 1px) 2px rgba(0, 0, 0, 0.2),
    inset 0 1px 1px rgba(255, 255, 255, 0.18),
    inset 1px 0 0 rgba(255, 255, 255, 0.06),
    inset -1px 0 0 rgba(0, 0, 0, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.25);
}

/* ── Focus visible (accessibility) ────────────────────── */
.keycap:focus-visible {
  outline: 2px solid var(--key-legend);
  outline-offset: 2px;
}
