.model-link {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 650;
  white-space: nowrap;
}

.nspire {
  --key-height: clamp(21px, 3.85svh, 34px);
  --letter-height: clamp(19px, 3.35svh, 29px);
  --key-gap: clamp(3px, .55svh, 5px);
  --case-padding: clamp(10px, 1.7svh, 16px);
  --keypad-height: calc(8 * var(--key-height) + 4 * var(--letter-height) + 9 * var(--key-gap) + 22px);
}

.nspire header { height: 48px; }

.nspire main {
  display: grid;
  width: min(100% - 24px, 980px);
  grid-template-columns: minmax(0, 412px);
  gap: 16px;
  padding: 12px 0 18px;
  align-items: start;
}

.nspire .device { padding: var(--case-padding); }
.nspire .device-title { margin-bottom: 8px; }

.nspire .device-title h1 {
  margin: 0;
  font: inherit;
  letter-spacing: inherit;
}

.nspire .bezel {
  width: min(100%, max(166px, calc((100svh - 130px - var(--keypad-height)) * 4 / 3)));
  margin-inline: auto;
}

.nspire canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

#keypad {
  min-width: 0;
  margin: 9px 0 0;
  padding: 0;
  border: 0;
}

.command-keys, .modifier-keys, .math-keys, .letter-keys, .directions {
  display: grid;
  gap: var(--key-gap);
}

.command-keys, .modifier-keys, .math-keys { grid-auto-rows: var(--key-height); }
.command-keys { grid-template-columns: minmax(0, 1fr) minmax(0, 2.25fr) minmax(0, 1fr); }
.modifier-keys { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-top: 6px; }
.math-keys {
  grid-template-columns: repeat(2, minmax(0, .85fr)) repeat(3, minmax(0, 1.2fr)) repeat(2, minmax(0, .85fr));
  margin-top: var(--key-gap);
}
.letter-keys {
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-auto-rows: var(--letter-height);
  margin-top: 8px;
  padding-top: 7px;
  border-top: 1px solid #51635a;
}
.letter-keys [data-name="v"] { grid-column: 2; }
.letter-keys .key:not([data-name="π"]) .primary-label { text-transform: uppercase; }

.nspire .key {
  min-height: 0;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: clamp(.65rem, 1.65svh, .8rem);
  line-height: 1;
}

.nspire .primary-label { white-space: nowrap; }
.nspire .secondary-label { font-size: clamp(.46rem, 1.12svh, .6rem); color: #c5dcb7; }
.nspire .key.num { font-size: clamp(.8rem, 2.1svh, 1rem); }
.nspire .key.num .secondary-label,
.nspire .key[data-name="enter"] .secondary-label,
.nspire .key[data-name="on"] .secondary-label { color: #384b31; }
.nspire .key[data-name="ctrl"] { background: #92d4c2; color: #163f33; border-bottom-color: #549986; }
.nspire .key[data-name="on"] { background: #bade75; color: #263917; border-bottom-color: #75934c; }
.nspire .key[data-name="on"] .primary-label { text-transform: uppercase; }
.nspire .key[data-name="enter"] {
  grid-column: span 2;
  background: #cedfba;
  color: #20331e;
  border-bottom-color: #7f9a6e;
}
.nspire .key[data-name="space"] { grid-column: span 3; }
.nspire .key:disabled { opacity: .83; }

.math-keys .key:nth-child(7n + 1),
.math-keys .key:nth-child(7n + 6):not([data-name="enter"]) { border-radius: 7px 3px 3px 9px; }
.math-keys .key:nth-child(7n + 2),
.math-keys .key:nth-child(7n + 7) { border-radius: 3px 7px 9px 3px; }

.directions {
  grid-column: 2;
  grid-row: 1 / span 3;
  grid-template: minmax(0, 1fr) minmax(0, 2.3fr) minmax(0, 1fr) / 1fr 2.8fr 1fr;
  border: 1px solid #6a8274;
  border-radius: 14px;
  padding: 3px;
  gap: 1px;
  background: #293631;
}

.directions .key {
  border: 0;
  border-radius: 8px;
  background: transparent;
}
.directions .key:not(:disabled):hover,
.directions .key.held { background: #4c6255; }
.directions .key:focus-visible { outline-offset: -2px; }
.directions [data-name="↑"] { grid-area: 1 / 1 / 2 / -1; }
.directions [data-name="←"] { grid-area: 2 / 1; }
.directions [data-name="→"] { grid-area: 2 / 3; }
.directions [data-name="↓"] { grid-area: 3 / 1 / 4 / -1; }
.directions .key.touchpad {
  grid-area: 2 / 2;
  position: relative;
}
.directions .touchpad::before {
  content: "";
  width: clamp(20px, 4.4svh, 34px);
  height: clamp(17px, 3.4svh, 29px);
  border: 1px solid #789285;
  border-radius: 6px;
  background: #3e5148;
}
.directions .touchpad::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border: 1px solid #c2d2c2;
  border-radius: 50%;
}

.image-form {
  display: grid;
  gap: 9px;
  margin-top: 25px;
  padding: 16px;
  border: 1px solid #aab69f;
  border-radius: 12px;
  background: #f9f8f0;
}

.image-form h2 { margin: 0 0 5px; }
.nspire .image-form { margin: 0; }
.nspire .form-title { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.nspire #close-images {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px;
  text-decoration: underline;
  text-underline-offset: .2em;
}

.nspire #cover {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px;
}

.presets {
  max-width: 100%;
  min-height: 0;
  overflow: auto;
  padding: 4px;
}

.presets ul {
  display: flex;
  flex-direction: column;
  gap: 5px;
  list-style: none;
  padding: 0;
  margin: 0;
}
.presets .upload, .screen-import {
  max-width: 100%;
  border: 0;
  min-height: 35px;
  padding: 5px 10px;
  overflow-wrap: anywhere;
  font-size: .88rem;
}

.screen-import {
  background: #28442d;
  color: white;
  border-radius: 7px;
  font-weight: 700;
}

.screen-import:hover { background: #355d3e; }
.presets:not([hidden]) + .screen-import {
  background: transparent;
  color: #293823;
  text-decoration: underline;
  text-underline-offset: .2em;
}

.image-form label { display: grid; justify-items: start; gap: 4px; }
.image-form code { overflow-wrap: anywhere; }
.image-form input {
  width: 100%;
  min-width: 0;
  margin-bottom: 10px;
  color: var(--muted);
  font: inherit;
  font-size: .85rem;
}

.image-form input::file-selector-button {
  cursor: pointer;
  min-height: 35px;
  margin-right: 8px;
  padding: 5px 10px;
  color: var(--ink);
  font: inherit;
  border: 1px solid #9fae97;
  border-radius: 6px;
  background: #edf1e5;
}

.image-form .upload { justify-self: start; border: none; }
.image-form button:disabled, .nspire .actions button:disabled { opacity: .6; cursor: default; }
.nspire .actions { margin-top: 10px; justify-content: center; }
.nspire .notice { text-align: center; margin: 7px 0 0; }
.nspire .notice:empty { display: none; }

.nspire footer {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding-block: 10px 15px;
}
.nspire footer nav { display: flex; gap: 14px; }
.nspire footer summary { font-weight: 500; }
.nspire footer details[open] { flex-basis: min(100%, 385px); }
.nspire footer details p { margin-bottom: 0; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (min-width: 740px) and (min-height: 521px) {
  .nspire main:has(.image-form:not([hidden])) {
    grid-template-columns: minmax(0, 412px) minmax(0, 320px);
  }
  .nspire .image-form { align-self: center; }
}

@media (orientation: landscape) and (max-height: 520px) and (min-width: 650px) {
  .nspire {
    --key-height: clamp(18px, calc((100svh - 143px) / 12), 27px);
    --letter-height: calc(var(--key-height) - 2px);
  }
  .nspire .secondary-label { display: none; }
  .nspire header { height: 42px; }
  .nspire main { grid-template-columns: minmax(0, 680px); padding-top: 8px; }
  .nspire .device {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    column-gap: 14px;
    align-items: center;
  }
  .nspire .device-title { grid-column: 1 / -1; }
  .nspire .bezel { width: 100%; }
  .nspire #keypad { margin-top: 0; }
}
