:root {
  --bg: #0a0d0c;
  --panel: #101513;
  --ink: #d7e6de;
  --dim: #5d726a;
  --green: #38f79b;
  --green-soft: #1d8f5c;
  --amber: #ffcf70;
  --red: #ff7a6b;
  --edge: #1e2a26;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas,
    monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 5fr) 7fr;
  height: 100dvh;
}

.panel {
  min-width: 0;
  min-height: 0;
}

/* ------------------------------------------------------------- key panel */

.panel--key {
  display: flex;
  flex-direction: column;
  align-items: center;
  /* `safe` keeps the top of the column reachable when the content is taller
     than the panel — plain centring clips it past the top edge instead. */
  justify-content: safe center;
  /* Opening the code drawer can outgrow the panel; it scrolls here rather than
     pushing the terminal off the page. */
  overflow-y: auto;
  gap: 1.5rem;
  padding: 2rem 1.5rem;
  background:
    radial-gradient(120% 80% at 50% 0%, #14211c 0%, transparent 60%),
    var(--panel);
  border-right: 1px solid var(--edge);
}

.panel__head {
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  letter-spacing: 0.42em;
  color: var(--green);
  text-shadow: 0 0 18px rgba(56, 247, 155, 0.35);
}

.subtitle {
  margin: 0.6rem 0 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  color: var(--dim);
}

.key {
  position: relative;
  width: min(46vw, 240px);
  aspect-ratio: 1;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.key__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(56, 247, 155, 0.28);
  transition: transform 160ms ease, opacity 160ms ease;
}

.key__face {
  position: absolute;
  inset: 8%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #1c2b25, #0d1512 70%);
  border: 1px solid #243731;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.05),
    0 18px 40px rgba(0, 0, 0, 0.55);
  transition: transform 90ms ease, box-shadow 160ms ease, background 160ms ease;
}

.key__glyph {
  font-size: clamp(1.4rem, 4vw, 2rem);
  letter-spacing: 0.1em;
  color: var(--green-soft);
  transition: color 120ms ease, text-shadow 120ms ease;
}

.key:focus-visible .key__ring {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(56, 247, 155, 0.18);
}

.key.is-down .key__face {
  transform: scale(0.965);
  background: radial-gradient(circle at 50% 32%, #23453a, #0f1c17 72%);
  box-shadow:
    inset 0 3px 12px rgba(0, 0, 0, 0.6),
    0 0 60px rgba(56, 247, 155, 0.28);
}

.key.is-down .key__glyph {
  color: var(--green);
  text-shadow: 0 0 22px rgba(56, 247, 155, 0.7);
}

.key.is-down .key__ring {
  transform: scale(1.06);
  border-color: rgba(56, 247, 155, 0.6);
}

.meter {
  width: min(100%, 260px);
  height: 4px;
  border-radius: 999px;
  background: #17211d;
  overflow: hidden;
}

.meter__fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--green-soft);
  transition: background-color 120ms ease;
}

.meter__fill[data-mode="dash"] {
  background: var(--green);
}

.meter__fill[data-mode="gap"] {
  background: var(--amber);
}

.key-hint {
  margin: -0.6rem 0 0;
  min-height: 1.2em;
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  color: var(--dim);
}

/* The tone toggle sits under the key because that is where the sound appears
   to come from, and it stays put when the legend and drawer get hidden. */
.sound {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: -0.4rem 0 0;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 999px;
  cursor: pointer;
  transition: color 120ms ease, border-color 120ms ease;
}

.sound:hover,
.sound:focus-visible {
  color: var(--ink);
  border-color: var(--green-soft);
}

.sound[aria-pressed="true"] {
  color: var(--green-soft);
}

.sound[aria-pressed="true"]:hover,
.sound[aria-pressed="true"]:focus-visible {
  color: var(--green);
  border-color: var(--green-soft);
}

.sound__icon {
  width: 20px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sound__cone {
  fill: currentColor;
  stroke: none;
}

.sound[aria-pressed="false"] .sound__wave,
.sound[aria-pressed="true"] .sound__cross {
  display: none;
}

.legend {
  display: grid;
  gap: 0.3rem;
  margin: 0;
  width: min(100%, 300px);
  font-size: 0.72rem;
  color: var(--dim);
}

.legend > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  white-space: nowrap;
  padding-bottom: 0.3rem;
  border-bottom: 1px dashed #1b2622;
}

.legend dt {
  color: #8ea79d;
}

.legend dd {
  margin: 0;
}

/* ------------------------------------------------------------ code drawer */

.codes {
  width: min(100%, 300px);
  font-size: 0.72rem;
  color: var(--dim);
}

/* The flex row lives on a child, not on the <summary> itself: giving a summary
   a display other than list-item has broken the disclosure in Safari. */
.codes__summary {
  padding: 0.25rem 0;
  list-style: none;
  letter-spacing: 0.14em;
  cursor: pointer;
}

.codes__row-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.codes__summary::-webkit-details-marker {
  display: none;
}

.codes__summary:hover,
.codes[open] .codes__summary {
  color: #8ea79d;
}

.codes:focus-within .codes__summary {
  color: var(--green);
}

.codes__caret {
  display: inline-block;
  transition: transform 140ms ease;
}

.codes[open] .codes__caret {
  transform: rotate(90deg);
}

/* Bounded so opening the drawer can never push the terminal off the screen —
   it scrolls inside itself instead of growing the key panel. */
.codes__body {
  max-height: min(26vh, 190px);
  overflow-y: auto;
  padding: 0.2rem 0.1rem 0;
  border-top: 1px dashed #1b2622;
}

.codes__group {
  margin-top: 0.5rem;
}

.codes__group:first-child {
  margin-top: 0.35rem;
}

.codes__title {
  margin: 0 0 0.25rem;
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  color: #33463f;
}

.codes__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(4.4rem, 1fr));
  gap: 0.15rem 0.5rem;
}

.codes__row {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  white-space: nowrap;
}

.codes__char {
  flex: none;
  width: 1ch;
  color: var(--green-soft);
}

.codes__code {
  color: #8ea79d;
  letter-spacing: 0.12em;
}

.codes__body::-webkit-scrollbar {
  width: 6px;
}

.codes__body::-webkit-scrollbar-thumb {
  background: #1c2a25;
  border-radius: 999px;
}

/* -------------------------------------------------------------- terminal */

.panel--term {
  padding: 1.25rem;
  display: flex;
}

.term {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border: 1px solid var(--edge);
  border-radius: 10px;
  background: #060908;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.term__bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.8rem;
  background: #0d1211;
  border-bottom: 1px solid var(--edge);
}

.term__dots {
  display: flex;
  gap: 0.35rem;
}

.term__dots i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #26332e;
}

.term__name {
  flex: 1;
  font-size: 0.74rem;
  letter-spacing: 0.12em;
  color: var(--dim);
}

.term__clear {
  font: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.6rem;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 4px;
  cursor: pointer;
}

.term__clear:hover,
.term__clear:focus-visible {
  color: var(--green);
  border-color: var(--green-soft);
}

.term__icon {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.55rem;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 4px;
  cursor: pointer;
}

.term__icon:hover,
.term__icon:focus-visible {
  color: var(--ink);
  border-color: var(--green-soft);
}

.term__icon[aria-pressed="true"] {
  color: var(--amber);
  border-color: #4a3a1c;
}

.hints__icon {
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.term__icon[aria-pressed="true"] .hints__bulb {
  fill: rgba(255, 207, 112, 0.22);
}

.term__icon[aria-pressed="false"] .hints__rays {
  display: none;
}

/* ------------------------------------------------------------- hint panel */

.hint {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--edge);
  background: #0b100e;
}

.hint[hidden] {
  display: none;
}

.hint__label {
  flex: none;
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  color: var(--amber);
}

.hint__input {
  flex: none;
  width: 8.5rem;
  font: inherit;
  font-size: 0.82rem;
  padding: 0.25rem 0.5rem;
  color: var(--ink);
  background: #060908;
  border: 1px solid var(--edge);
  border-radius: 4px;
}

.hint__input::placeholder {
  color: #3f574e;
  letter-spacing: 0.04em;
}

.hint__input:focus-visible {
  outline: none;
  border-color: var(--amber);
}

.hint__readout {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 0.72rem;
  color: var(--dim);
}

.hint__idle,
.hint__miss {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint__idle {
  color: #3f574e;
}

.hint__char {
  flex: none;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  color: var(--amber);
}

/* Dots and dashes as bars, so the rhythm reads at a glance. */
/* Never wrap: a rhythm split across two rows is not a rhythm. If the width
   truly is not there the readout clips, which at least stays readable. */
.hint__bars {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex: none;
  flex-wrap: nowrap;
}

.hint__bar {
  height: 6px;
  border-radius: 999px;
  background: var(--green-soft);
  transition: background-color 90ms ease, transform 90ms ease;
}

.hint__bar[data-symbol="."] {
  width: 6px;
}

.hint__bar[data-symbol="-"] {
  width: 18px;
}

.hint__bar.is-sounding {
  background: var(--green);
  transform: scaleY(1.6);
}

.hint__name {
  flex: none;
  color: #5f7a70;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint__miss {
  color: var(--red);
}

.hint__play {
  flex: none;
  font: inherit;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  padding: 0.2rem 0.6rem;
  color: var(--dim);
  background: transparent;
  border: 1px solid var(--edge);
  border-radius: 4px;
  cursor: pointer;
}

.hint__play:hover:not(:disabled),
.hint__play:focus-visible:not(:disabled) {
  color: var(--green);
  border-color: var(--green-soft);
}

.hint__play:disabled {
  opacity: 0.4;
  cursor: default;
}

.term__screen {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.9rem 1rem;
  font-size: 0.82rem;
  line-height: 1.65;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.014) 0 1px,
    transparent 1px 3px
  );
}

.line {
  display: flex;
  gap: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.line__time {
  flex: none;
  color: #33463f;
}

.line__tag {
  flex: none;
  width: 3ch;
  color: #4a6b5e;
}

.line__body {
  color: #9fb8ad;
}

.line--accent .line__body {
  color: var(--green);
}

.line--muted .line__body {
  color: #5f7a70;
}

.line--warn .line__body {
  color: var(--red);
}

.line--pending .line__body {
  color: var(--amber);
  letter-spacing: 0.22em;
}

.cursor {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  margin-left: 0.15em;
  vertical-align: -0.15em;
  background: var(--green);
  animation: blink 1.05s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.term__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1rem;
  border-top: 1px solid var(--edge);
  background: #0d1211;
}

.out {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  min-width: 0;
}

.out__label {
  flex: none;
  font-size: 0.66rem;
  letter-spacing: 0.2em;
  color: var(--dim);
}

.out__text {
  font-size: 1rem;
  letter-spacing: 0.18em;
  color: var(--green);
  text-shadow: 0 0 14px rgba(56, 247, 155, 0.3);
  overflow-wrap: anywhere;
}

.stats {
  flex: none;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: #3f574e;
}

/* -------------------------------------------------------------- scrollbar */

.term__screen::-webkit-scrollbar {
  width: 8px;
}

.term__screen::-webkit-scrollbar-thumb {
  background: #1c2a25;
  border-radius: 999px;
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(240px, 1fr);
  }

  .panel--key {
    border-right: none;
    border-bottom: 1px solid var(--edge);
    padding: 1.5rem 1.25rem;
    gap: 1.1rem;
  }

  .key {
    width: min(40vw, 170px);
  }

  .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.3rem 1.5rem;
    width: 100%;
    max-width: 460px;
  }

  .codes {
    width: 100%;
    max-width: 460px;
  }

  .panel--term {
    padding: 0.75rem;
    min-height: 0;
  }
}

/* Phone widths can't hold two legend columns without the rows colliding. */
@media (max-width: 520px) {
  .legend {
    grid-template-columns: 1fr;
    max-width: 300px;
  }

  .codes {
    max-width: 300px;
  }

}

/* Compact hint row. Two different layouts leave the terminal column narrow: a
   phone in portrait, and a landscape phone, where the viewport is wide but the
   column is not. Both need the row on one line — wrapping it costs ~30px of
   height, and the log is down to a few lines in either case. */
@media (max-width: 520px), (max-width: 860px) and (orientation: landscape) {
  .hint {
    gap: 0.45rem;
    padding: 0.45rem 0.7rem;
  }

  /* The written-out "dash dash dot" goes; the bars already carry the rhythm. */
  .hint__label,
  .hint__name,
  .term__icon-label {
    display: none;
  }

  /* The box holds one character, so it gives its width to the readout, which
     needs room for up to seven bars. */
  .hint__input {
    flex: 0 0 2.9rem;
    width: auto;
    min-width: 0;
  }

  .term__foot {
    padding: 0.5rem 0.7rem;
  }
}

/* Short viewports (landscape phones, small laptops) can't spare the vertical
   room, so the key panel gives its optional furniture back to the terminal. */
@media (max-height: 620px) {
  .panel--key {
    gap: 0.9rem;
    padding: 1rem 1.25rem;
  }

  .key {
    width: min(30vh, 240px);
  }

  .title {
    font-size: 1rem;
  }

  .subtitle {
    display: none;
  }
}

/* Tighter still: the legend goes too, since the terminal prints the same rules
   in its opening lines. Stacked layouts hit this sooner — they spend their
   height on both panels. */
@media (max-height: 480px), (max-width: 860px) and (max-height: 620px) {
  .legend {
    display: none;
  }

  /* The drawer stays — it is the reference the hidden legend no longer gives —
     so the key gives up the height instead. */
  .key {
    width: min(26vh, 200px);
  }
}

/* With the height gone but the width still there, side by side beats stacked. */
@media (max-width: 860px) and (orientation: landscape) {
  .app {
    grid-template-columns: minmax(180px, 2fr) 3fr;
    grid-template-rows: 1fr;
  }

  .panel--key {
    border-right: 1px solid var(--edge);
    border-bottom: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
