.spacebar-section {
  --spacebar-surface: #ffffff;
  --spacebar-text: #172a3b;
  --spacebar-muted: #65706b;
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: var(--page-card-gap) 0 calc(var(--page-card-gap) + var(--records-card-overlap));
}

.spacebar-section:has(+ .records-section[hidden]) {
  padding-bottom: var(--page-card-gap);
}

.panel {
  display: grid;
  gap: clamp(16px, 2vw, 24px);
  min-width: 0;
  max-width: 100%;
  padding: clamp(20px, 3vw, 38px);
  overflow: hidden;
  background: var(--spacebar-surface);
  border-radius: 24px;
}

.panel > *,
.stats,
.key-area {
  min-width: 0;
  max-width: 100%;
}

html[data-page="spacebar"] body.fullscreen-open {
  width: 100%;
  overflow: hidden;
}

.panel:fullscreen,
.panel.is-app-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  grid-template-rows: auto minmax(260px, 1fr);
  align-content: stretch;
  width: 100%;
  max-width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  margin: 0;
  padding: clamp(20px, 4vh, 48px) clamp(18px, 5vw, 76px);
  overflow-x: hidden;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 0;
}

html[data-page="spacebar"].is-app-mobile-viewport .panel.is-app-fullscreen,
html[data-page="spacebar"].is-app-mobile-viewport .result-modal {
  right: auto;
  width: min(100%, var(--spacebar-visible-width, 100%));
  max-width: min(100%, var(--spacebar-visible-width, 100%));
}

.panel:fullscreen .key-area,
.panel.is-app-fullscreen .key-area {
  --spacebar-key-rest-y: 0px;
  min-height: 0;
}

.panel:fullscreen .key,
.panel.is-app-fullscreen .key {
  width: min(720px, 58vw);
  min-height: clamp(128px, 14vh, 176px);
  border-radius: 28px;
}

.panel:fullscreen .key span,
.panel.is-app-fullscreen .key span {
  font-size: clamp(1.22rem, 2.1vw, 1.8rem);
  letter-spacing: 0.26em;
}

.tool-controls {
  position: absolute;
  right: clamp(14px, 2vw, 24px);
  bottom: clamp(12px, 1.8vw, 20px);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-height: 38px;
}

.duration-menu {
  --duration-accent: #5b54d0;
  --duration-accent-strong: #4740b8;
  --duration-text: #596660;
  position: absolute;
  top: clamp(14px, 2vw, 20px);
  right: clamp(14px, 2vw, 22px);
  z-index: 8;
}

.duration-menu summary {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  color: var(--duration-accent-strong);
  background: transparent;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-family: var(--font-display);
  list-style: none;
  user-select: none;
  box-shadow: none;
  transition: color 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

.duration-menu summary::-webkit-details-marker {
  display: none;
}

.duration-menu summary::marker {
  content: "";
}

.duration-trigger-icon {
  display: block;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.15;
  transform-origin: center bottom;
  transition: transform 180ms ease;
}

.duration-progress {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

.duration-progress::-webkit-progress-bar {
  background: #dce4e9;
}

.duration-progress::-webkit-progress-value {
  background: var(--duration-accent);
}

.duration-progress::-moz-progress-bar {
  background: var(--duration-accent);
}

.duration-menu[open] summary,
.duration-menu summary:hover {
  color: var(--duration-accent-strong);
  background: transparent;
  box-shadow: none;
}

.duration-menu[open] .duration-trigger-icon,
.duration-menu summary:hover .duration-trigger-icon {
  transform: none;
}

.duration-menu[open] .duration-trigger-icon {
  animation: duration-trigger-pop 220ms cubic-bezier(0.18, 0.82, 0.32, 1.22) both;
}

.duration-list {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  min-width: 96px;
  padding: 7px;
  background: #ffffff;
  border: 0;
  border-radius: 12px;
  box-shadow: none;
  transform-origin: top right;
}

.duration-menu[open] .duration-list {
  animation: duration-menu-open 180ms cubic-bezier(0.18, 0.82, 0.32, 1) both;
}

.duration-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--duration-text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  line-height: 1;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.duration-menu[open] .duration-option {
  animation: duration-option-reveal 170ms ease-out both;
}

.duration-menu[open] .duration-option:nth-child(2) {
  animation-delay: 18ms;
}

.duration-menu[open] .duration-option:nth-child(3) {
  animation-delay: 36ms;
}

.duration-menu[open] .duration-option:nth-child(4) {
  animation-delay: 54ms;
}

.duration-menu[open] .duration-option:nth-child(5) {
  animation-delay: 72ms;
}

.duration-option span {
  pointer-events: none;
}

.duration-option:hover {
  color: var(--duration-accent-strong);
  background: transparent;
  transform: none;
}

.duration-option[aria-pressed="true"] {
  color: var(--duration-accent-strong);
  background: transparent;
  font-weight: 950;
}

@keyframes duration-trigger-pop {
  0% {
    transform: scale(1);
  }

  42% {
    transform: scale(0.86) rotate(-8deg);
  }

  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes duration-menu-open {
  from {
    opacity: 0;
    transform: translateY(-5px) scale(0.94);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes duration-option-reveal {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.tool-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #687671;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 900;
  line-height: 1;
  transition: color 180ms ease, background-color 180ms ease, transform 180ms ease;
}

.tool-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.35;
}

.tool-button:hover {
  color: #172a3b;
  background: transparent;
}

.tool-button.is-on {
  color: #5d56d9;
  background: transparent;
}

.tool-button.is-off {
  color: #66746f;
  background: transparent;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  --stat-accent: #766bdd;
  --stat-glow: rgba(118, 107, 221, 0.08);
  position: relative;
  display: grid;
  align-content: center;
  gap: 7px;
  min-height: 92px;
  padding: 14px 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 18%, var(--stat-glow), transparent 38%),
    #fbfdff;
  border-radius: 18px;
  box-shadow: none;
  text-align: center;
}

.stat::before {
  content: "";
  position: absolute;
  top: 14px;
  right: 16px;
  width: 7px;
  height: 7px;
  background: var(--stat-accent);
  border-radius: 50%;
  opacity: 0.55;
}

.stat:nth-child(1) {
  --stat-accent: #7068de;
  --stat-glow: rgba(112, 104, 222, 0.14);
}

.stat:nth-child(2) {
  --stat-accent: #4a98c8;
  --stat-glow: rgba(74, 152, 200, 0.14);
}

.stat:nth-child(3) {
  --stat-accent: #b56ab7;
  --stat-glow: rgba(181, 106, 183, 0.14);
}

.stat-label {
  color: #59655f;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.stat-value {
  color: var(--spacebar-text);
  font-family: var(--font-display);
  font-size: clamp(1.78rem, 3vw, 2.35rem);
  line-height: 1;
}

.key-area {
  --spacebar-key-rest-y: clamp(-22px, -2vw, -12px);
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  place-items: center;
  gap: clamp(18px, 2.4vw, 26px);
  min-height: clamp(350px, 37vw, 430px);
  padding: clamp(22px, 2.6vw, 30px) clamp(18px, 3vw, 30px) clamp(20px, 2.4vw, 28px);
  overflow: hidden;
  background: linear-gradient(145deg, #edf7ff 0%, #f5f3ff 52%, #fff6fa 100%);
  border-radius: 22px;
}

.press-effects {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  border-radius: inherit;
  pointer-events: none;
}

.press-pop,
.press-ring,
.press-spark,
.press-fragment {
  position: absolute;
  left: var(--effect-x, 50%);
  top: var(--effect-y, 50%);
  pointer-events: none;
}

.press-pop {
  z-index: 2;
  color: #5b55d6;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2vw, 1.45rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 6px 18px rgba(107, 101, 220, 0.22);
  transform: translate(-50%, -50%);
  animation: spacebar-press-pop 680ms ease-out forwards;
}

.press-ring {
  z-index: 1;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(107, 101, 220, 0.28);
  border-radius: 999px;
  transform: translate(-50%, -50%);
  animation: spacebar-press-ring 520ms ease-out forwards;
}

.press-spark {
  z-index: 1;
  width: 8px;
  height: 8px;
  background: #8fd6ff;
  border-radius: 999px;
  box-shadow: 0 0 12px rgba(143, 214, 255, 0.5);
  transform: translate(-50%, -50%);
  animation: spacebar-press-spark 620ms ease-out forwards;
}

.press-spark:nth-child(3n) {
  background: #f3a6cf;
  box-shadow: 0 0 12px rgba(243, 166, 207, 0.42);
}

.press-spark:nth-child(4n) {
  background: #9ee5cc;
  box-shadow: 0 0 12px rgba(158, 229, 204, 0.42);
}

.press-fragment {
  z-index: 1;
  width: 9px;
  height: 6px;
  background: #7ebdff;
  border-radius: 3px 5px 4px 2px;
  opacity: 0;
  transform: translate(-50%, -50%) rotate(0deg);
  animation: spacebar-press-fragment 920ms cubic-bezier(0.18, 0.76, 0.34, 1) forwards;
  animation-delay: var(--fragment-delay, 0ms);
}

.press-fragment:nth-child(3n) {
  width: 7px;
  height: 7px;
  background: #f2a1cb;
  border-radius: 50%;
}

.press-fragment:nth-child(4n) {
  width: 10px;
  height: 5px;
  background: #99dec7;
  border-radius: 5px 2px 5px 3px;
}

.press-fragment:nth-child(5n) {
  width: 6px;
  height: 10px;
  background: #b8a7ff;
  border-radius: 4px 3px 5px 2px;
}

.key {
  position: relative;
  z-index: 1;
  grid-row: 2;
  grid-column: 1;
  display: grid;
  place-items: center;
  width: min(560px, 100%);
  min-height: clamp(92px, 13vw, 124px);
  padding: 20px;
  color: #425268;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 58%, #e7edf3 100%);
  border: 1px solid #c9d4df;
  border-radius: 22px;
  box-shadow:
    0 13px 0 #b5c2cf,
    0 25px 42px rgba(34, 57, 78, 0.2),
    inset 0 3px 1px rgba(255, 255, 255, 0.95),
    inset 0 -4px 7px rgba(91, 112, 132, 0.12);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform: translateY(var(--spacebar-key-rest-y)) scale(1);
  transition: transform 90ms ease, box-shadow 90ms ease, filter 90ms ease;
}

.key.is-pressed::before {
  opacity: 0.92;
}

.key::before {
  content: "";
  position: absolute;
  inset: 7px 10px auto;
  height: 42%;
  border-radius: 15px 15px 45% 45%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0));
  pointer-events: none;
}

.key::after {
  content: "";
  position: absolute;
  right: 9%;
  bottom: 9px;
  left: 9%;
  height: 2px;
  background: rgba(117, 136, 154, 0.22);
  border-radius: 999px;
  pointer-events: none;
}

.key span {
  position: relative;
  z-index: 1;
  font-family: var(--font-display);
  font-size: clamp(1rem, 2.2vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.22em;
}

.key.is-pressed {
  filter: brightness(0.985);
  transform: translateY(calc(var(--spacebar-key-rest-y) + 8px)) scale(0.995);
  box-shadow:
    0 5px 0 #b5c2cf,
    0 12px 22px rgba(34, 57, 78, 0.16),
    inset 0 1px 1px rgba(255, 255, 255, 0.72),
    inset 0 -3px 6px rgba(91, 112, 132, 0.14);
}

@keyframes spacebar-press-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -38%) scale(0.82);
  }
  16% {
    opacity: 1;
    transform: translate(-50%, -72%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--effect-drift, 0px)), -168%) scale(1.08);
  }
}

@keyframes spacebar-press-ring {
  0% {
    opacity: 0.42;
    transform: translate(-50%, -50%) scale(0.72);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(4.2);
  }
}

@keyframes spacebar-press-spark {
  0% {
    opacity: 0.9;
    transform: translate(-50%, -50%) scale(0.8);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--spark-x, 0px)), calc(-50% + var(--spark-y, -36px))) scale(0.45);
  }
}

@keyframes spacebar-press-fragment {
  0% {
    opacity: 0;
    transform: translate(-50%, -58%) rotate(0deg) scale(0.78);
  }
  12% {
    opacity: 0.9;
    transform: translate(calc(-50% + var(--fragment-hop-x, 0px)), -88%) rotate(28deg) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--fragment-x, 0px)), calc(-50% + var(--fragment-y, 92px))) rotate(var(--fragment-rotate, 120deg)) scale(0.56);
  }
}

.status {
  position: relative;
  z-index: 3;
  grid-row: 3;
  grid-column: 1;
  max-width: calc(100% - 260px);
  margin: 0;
  color: #697770;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
}

.result-modal[hidden] {
  display: none;
}

.result-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  place-items: center;
  padding: 24px;
  overflow-x: clip;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.result-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 42, 59, 0.28);
  backdrop-filter: blur(5px);
  pointer-events: none;
}

.result-card {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(210px, 0.86fr) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 28px);
  width: 100%;
  max-width: 760px;
  min-width: 0;
  max-height: calc(100dvh - 48px);
  padding: clamp(16px, 3vw, 24px);
  overflow-y: auto;
  color: var(--spacebar-text);
  background: var(--spacebar-surface);
  border-radius: 22px 20px 24px 19px;
  box-shadow: 0 24px 70px rgba(23, 42, 59, 0.18);
  animation: spacebar-result-enter 220ms ease-out both;
}

.result-card:focus {
  outline: none;
}

.result-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  color: #5f6a64;
  background: #f2f5f7;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, transform 180ms ease;
}

.result-close:hover {
  color: var(--spacebar-text);
  background: #e8f2fb;
  transform: translateY(-1px);
}

.result-close svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
}

.result-visual {
  overflow: hidden;
  min-height: 220px;
  border-radius: 18px 16px 20px 15px;
  background: #e8f2fb;
}

.result-visual img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 220px;
  object-fit: cover;
}

.result-content {
  display: grid;
  align-content: center;
  gap: 12px;
  padding: 8px 34px 8px 0;
}

.result-eyebrow {
  margin: 0;
  color: var(--spacebar-muted);
  font-family: "Segoe Print", "Bradley Hand ITC", "Comic Sans MS", "SF Pro Rounded", cursive;
  font-size: 0.88rem;
  font-weight: 800;
}

.result-content h2 {
  margin: 0;
  color: var(--spacebar-text);
  font-family: var(--font-display);
  font-size: clamp(1.9rem, 4vw, 3rem);
  line-height: 1;
}

.result-stars {
  display: flex;
  gap: 4px;
  color: #d8dde4;
  font-size: clamp(1.85rem, 4vw, 2.55rem);
  line-height: 1;
}

.result-stars span {
  transform: rotate(-4deg);
}

.result-stars .is-filled {
  color: #f0b84d;
  text-shadow: 0 2px 0 rgba(23, 42, 59, 0.08);
}

.result-summary {
  margin: 0;
  color: var(--spacebar-muted);
  font-size: 1rem;
  line-height: 1.65;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.result-stats span {
  padding: 8px 10px;
  color: var(--spacebar-muted);
  background: #f4f7fb;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
}

.result-stats strong {
  color: var(--spacebar-text);
}

html[data-page="spacebar"] body.result-open {
  overflow: hidden;
}

@keyframes spacebar-result-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

#spacebar-test {
  scroll-margin-top: 92px;
}

.duration-menu summary:focus-visible,
.duration-option:focus-visible,
.tool-button:focus-visible,
.result-close:focus-visible,
.key:focus-visible {
  outline: 3px solid rgba(107, 101, 220, 0.32);
  outline-offset: 4px;
}

.key:focus-visible {
  outline: none;
}

@media (max-width: 1180px) {
  .tool-controls {
      grid-column: 2;
      gap: 9px;
    }
}

@media (max-width: 760px) {
  #spacebar-test {
      scroll-margin-top: 82px;
    }

  .stats {
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 8px;
    }

  .stat:nth-child(3) {
      grid-column: auto;
      justify-self: stretch;
      width: auto;
    }

  .stat {
      min-height: 82px;
      padding: 10px 8px;
    }

  .stat-value {
      font-size: clamp(1.32rem, 6vw, 1.82rem);
    }

  .stat-label {
      font-size: 0.72rem;
    }

  .panel:fullscreen,
  .panel.is-app-fullscreen {
      grid-template-rows: auto minmax(180px, 1fr) auto;
      gap: 14px;
      padding: 14px 16px 18px;
    }

  .panel:fullscreen .key-area,
  .panel.is-app-fullscreen .key-area {
      min-height: 0;
    }

  .panel:fullscreen .key,
  .panel.is-app-fullscreen .key {
      width: min(100%, 560px);
      min-height: clamp(104px, 16vh, 142px);
      border-radius: 22px;
    }

  .result-modal {
      padding: 16px;
    }

  .result-card {
      grid-template-columns: 1fr;
      gap: 14px;
      max-height: calc(100dvh - 32px);
      padding: 16px;
      overflow-y: auto;
    }

  .result-visual {
      min-height: 150px;
    }

  .result-visual img {
      min-height: 150px;
    }

  .result-content {
      padding: 0;
    }
}

@media (max-width: 560px) {
  .stats {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }

  .stat:nth-child(3) {
      grid-column: 1 / -1;
      justify-self: stretch;
      width: auto;
    }

  .stat {
      min-height: 82px;
    }

  .tool-controls {
      position: static;
      grid-row: 4;
      grid-column: 1;
      justify-self: center;
      justify-content: center;
    }

  .key-area {
      grid-template-rows: auto minmax(0, 1fr) auto auto;
    }

  .status {
      max-width: 100%;
    }
}

@media (max-width: 460px) {
  .spacebar-section {
      width: min(100% - 22px, 1200px);
    }

  #spacebar-test {
      scroll-margin-top: 76px;
    }

  .panel {
      gap: 18px;
      padding: 16px;
      border-radius: 20px;
    }

  .tool-controls {
      justify-content: center;
    }

  .stats {
      gap: 8px;
    }

  .stat:nth-child(3) {
      width: auto;
    }

  .stat {
      min-height: 80px;
      padding: 10px 8px;
    }

  .stat-value {
      font-size: 1.7rem;
    }

  .key-area {
      gap: 14px;
      min-height: 330px;
      padding: 18px 10px;
    }

  .duration-menu summary {
      width: 44px;
      height: 44px;
    }

  .duration-list {
      grid-template-columns: 1fr;
      gap: 4px;
      width: auto;
      min-width: 92px;
    }

  .duration-option {
      min-height: 36px;
      padding: 8px 10px;
    }

  .key {
      min-height: 88px;
      border-radius: 18px;
    }

  .result-visual {
      min-height: 126px;
    }

  .result-visual img {
      min-height: 126px;
    }

  .result-content {
      gap: 9px;
    }

  .result-summary {
      font-size: 0.92rem;
      line-height: 1.5;
    }
}

html[data-page="spacebar"].is-app-compact-viewport .stats {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

html[data-page="spacebar"].is-app-compact-viewport .stat:nth-child(3) {
  grid-column: 1 / -1;
  justify-self: stretch;
  width: auto;
}

html[data-page="spacebar"].is-app-compact-viewport .tool-controls {
  position: static;
  grid-row: 4;
  grid-column: 1;
  justify-self: center;
  justify-content: center;
}

html[data-page="spacebar"].is-app-compact-viewport .key-area {
  grid-template-rows: auto minmax(0, 1fr) auto auto;
}

html[data-page="spacebar"].is-app-compact-viewport .status {
  max-width: 100%;
}
