/* Swarpeti — the keyboard: keys, labels, sargam marks, pressed state. */

/* ------------------------------------------------------------------ *
 * Keyboard
 * ------------------------------------------------------------------ */

.keybed-frame {
  padding: 14px 14px 16px;
  border-radius: 14px;
  background: var(--well);
  box-shadow: inset 0 5px 16px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.07);
}

#keybed {
  position: relative;
  height: clamp(190px, 25vw, 300px);
  container-type: inline-size;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.key {
  position: absolute;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 11px;
  padding: 0 0 clamp(6px, 2cqw, 14px);
  border: 1px solid var(--key-white-edge);
  border-top: 0;
  font-family: var(--font-ui);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s ease-out, box-shadow 0.06s, background 0.06s;
}

.key-white {
  bottom: 0;
  z-index: 1;
  border-radius: 0 0 9px 9px;
  background: linear-gradient(180deg, var(--key-white-1) 0%, var(--key-white-2) 100%);
  color: var(--key-white-ink);
  box-shadow: inset 0 -9px 0 rgba(0, 0, 0, 0.07), 0 4px 6px rgba(0, 0, 0, 0.4);
}

.key-black {
  height: 63%;
  z-index: 2;
  border-color: var(--key-black-edge);
  border-radius: 0 0 7px 7px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.1) 0 12%, transparent 12% 88%, rgba(0, 0, 0, 0.3) 88%),
    linear-gradient(180deg, var(--key-black-2) 0%, var(--key-black-2) 72%, var(--key-black-1) 100%);
  color: var(--key-black-ink);
  box-shadow: inset 0 -7px 0 rgba(255, 255, 255, 0.06), 0 6px 8px rgba(0, 0, 0, 0.55);
  /* A black key sits over the line between two white keys, so it must never move
     away from the top edge, or that line shows (worst when keys are hit fast, as
     each release animates back). It is pressed by shortening from the bottom. */
  transform-origin: 50% 0;
}

[data-finish='lacquer'] .key-white {
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.55) 0 22%, transparent 23%),
    linear-gradient(180deg, var(--key-white-1) 0%, var(--key-white-2) 100%);
}

[data-finish='lacquer'] .key-black {
  background:
    linear-gradient(115deg, rgba(255, 255, 255, 0.16) 0 28%, transparent 29%),
    linear-gradient(180deg, var(--key-black-2) 0%, var(--key-black-2) 72%, var(--key-black-1) 100%);
}

.key-label {
  font-size: clamp(0.58rem, 1.5cqw, 0.95rem);
  font-weight: 600;
  white-space: nowrap;
  line-height: 1;
}

.key-cap {
  padding: 2px 5px;
  border: 1px solid currentColor;
  border-radius: 4px;
  font-size: clamp(0.58rem, 1.15cqw, 0.78rem);
  line-height: 1;
  opacity: 0.7;
}

/* Sargam marks, shared by the keys and the guide. Saptak: a dot below the name
   for mandra, above for taar. Latin komal is underlined and tivra Ma carries a
   bar, matching the anudatta and udatta signs the Devanagari names already have. */
.key-label,
.map-name {
  position: relative;
}

.key-label[data-saptak='mandra']::after,
.key-label[data-saptak='taar']::before,
.map-name[data-saptak='mandra']::after,
.map-name[data-saptak='taar']::before {
  content: '';
  position: absolute;
  left: 50%;
  width: 0.28em;
  height: 0.28em;
  margin-left: -0.14em;
  border-radius: 50%;
  background: currentColor;
}

.key-label[data-saptak='mandra']::after,
.map-name[data-saptak='mandra']::after {
  bottom: -0.48em;
}

.key-label[data-saptak='taar']::before,
.map-name[data-saptak='taar']::before {
  top: -0.48em;
}

.key-label[data-swara='komal'],
.map-name[data-swara='komal'] {
  text-decoration: underline;
  text-decoration-thickness: 0.09em;
  text-underline-offset: 0.16em;
}

.key-label[data-swara='komal'][data-saptak='mandra']::after,
.map-name[data-swara='komal'][data-saptak='mandra']::after {
  bottom: -0.62em;
}

.key-label[data-swara='tivra']::before,
.map-name[data-swara='tivra']::before {
  content: '';
  position: absolute;
  left: 50%;
  top: -0.5em;
  width: 0.1em;
  height: 0.4em;
  margin-left: -0.05em;
  background: currentColor;
}

/* Devanagari lines are taller; keep the dots close to the letters. */
.key-label:lang(hi)[data-saptak='mandra']::after,
.map-name:lang(hi)[data-saptak='mandra']::after {
  bottom: -0.12em;
}

.key-label:lang(hi)[data-saptak='taar']::before,
.map-name:lang(hi)[data-saptak='taar']::before {
  top: -0.05em;
}

.key-cap:empty,
.key-label:empty {
  display: none;
}

/* Devanagari vowel signs sit above and below the line: give them room. */
.key-label:lang(hi) {
  line-height: 1.5;
  font-weight: 600;
}

.key.active {
  transform: translateY(3px);
}

.key-white.active {
  background: linear-gradient(180deg, var(--key-white-press), var(--key-white-press-2));
  color: var(--key-white-press-ink);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.4);
}

.key-black.active {
  transform: scaleY(0.975); /* shortened from the bottom: see .key-black */
  background: linear-gradient(180deg, var(--key-black-press-2), var(--key-black-press));
  color: var(--key-black-press-ink);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.4), 0 2px 3px rgba(0, 0, 0, 0.5);
}

/* Narrow keyboards: drop what no longer fits. */
@container (max-width: 560px) {
  .key-black .key-label {
    display: none;
  }
}

@container (max-width: 400px) {
  .key-cap {
    display: none;
  }
}

[data-finish='neon'] .key.active,
[data-finish='glow'] .key.active {
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.3), 0 0 22px var(--glow), 0 0 4px var(--accent);
}

.footnote {
  text-align: center;
  font-size: 0.78rem;
  font-style: italic;
  color: var(--text-dim);
}
