:root {
  --bg: #08090c;
  --bg-2: #0d1016;
  --tile: rgba(20, 24, 32, 0.86);
  --tile-hover: rgba(28, 33, 44, 0.96);
  --tile-line: rgba(148, 170, 200, 0.14);
  --tile-line-hot: rgba(148, 170, 200, 0.3);
  --ink: #f2f5f9;
  --dim: #7f8ca0;
  --record: #ff4d5a;
  --reverse: #67d0ff;
  --reveal: #b6f24a;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --gutter: clamp(12px, 3.2vw, 22px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef1f5;
    --bg-2: #e3e8ef;
    --tile: rgba(255, 255, 255, 0.9);
    --tile-hover: #ffffff;
    --tile-line: rgba(28, 48, 74, 0.12);
    --tile-line-hot: rgba(28, 48, 74, 0.26);
    --ink: #0c1724;
    --dim: #5d6b7e;
    --record: #e0364a;
    --reverse: #0d7fa8;
    --reveal: #4f7c0a;
    --shadow: 0 20px 48px rgba(20, 40, 70, 0.14);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg) 62%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: clamp(8px, 1.6vh, 16px);
  padding:
    calc(env(safe-area-inset-top) + var(--gutter))
    var(--gutter)
    calc(env(safe-area-inset-bottom) + var(--gutter));
  max-width: 1120px;
  margin: 0 auto;
}

/* --- head ----------------------------------------------------------------- */
.head { display: flex; flex-direction: column; gap: 3px; padding: 2px 2px 0; }
.head h1 {
  margin: 0;
  font-size: clamp(22px, 6.4vw, 30px);
  font-weight: 650;
  letter-spacing: -0.02em;
}
.status {
  margin: 0;
  font-size: clamp(12.5px, 3.4vw, 14px);
  color: var(--dim);
}

/* --- waveform ------------------------------------------------------------- */
.wave {
  width: 100%;
  height: clamp(46px, 9vh, 96px);
  display: block;
  opacity: 0.95;
}

/* --- deck ----------------------------------------------------------------- */
.deck {
  display: grid;
  grid-template-columns: 1fr;
  grid-auto-rows: 1fr;
  gap: clamp(8px, 1.4vh, 14px);
  min-height: 0;
}

.tile {
  -webkit-tap-highlight-color: transparent;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vh, 10px);
  min-height: 0;
  padding: clamp(14px, 2.4vh, 26px) 16px;
  border-radius: 20px;
  border: 1px solid var(--tile-line);
  background: var(--tile);
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s cubic-bezier(.2, .8, .3, 1), border-color .18s ease,
              background .18s ease, opacity .18s ease, box-shadow .18s ease;
}

.tile .icon {
  font-size: clamp(30px, 9vw, 44px);
  line-height: 1;
  color: var(--dim);
  transition: color .18s ease, transform .18s ease;
}
.tile .label {
  font-size: clamp(19px, 5.4vw, 24px);
  font-weight: 600;
  letter-spacing: -0.01em;
}
.tile .meta {
  font-size: clamp(11.5px, 3.1vw, 13px);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.tile:not(:disabled):active { transform: scale(0.985); }

/* Taps must not leave a pressed/focused look behind; keyboard users still get a ring. */
.tile:focus, .trybar__main:focus, .trybar__redo:focus { outline: none; }
.tile:focus-visible, .trybar__main:focus-visible, .trybar__redo:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

@media (hover: hover) {
  .tile:not(:disabled):hover {
    color: var(--ink);
    border-color: var(--tile-line-hot);
    background: var(--tile-hover);
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.22);
  }
}

.tile:disabled {
  cursor: not-allowed;
  opacity: 0.36;
  box-shadow: none;
}

.tile--reverse:not(:disabled) .icon { color: var(--reverse); }
.tile--reveal:not(:disabled) .icon { color: var(--reveal); }
.tile--reverse.is-playing { border-color: var(--reverse); box-shadow: 0 0 0 1px var(--reverse) inset; }
.tile--reveal.is-playing { border-color: var(--reveal); box-shadow: 0 0 0 1px var(--reveal) inset; }

/* --- record tile ---------------------------------------------------------- */
.icon--dot {
  width: clamp(30px, 8.4vw, 42px);
  height: clamp(30px, 8.4vw, 42px);
  border-radius: 50%;
  background: var(--record);
  box-shadow: 0 0 0 0 rgba(255, 77, 90, 0.5);
  transition: border-radius .18s ease, width .18s ease, height .18s ease, box-shadow .2s ease;
}
.tile--record:not(:disabled) .icon--dot { box-shadow: 0 0 26px rgba(255, 77, 90, 0.4); }

.tile--record.is-recording { border-color: var(--record); }
.tile--record.is-recording .icon--dot {
  width: clamp(22px, 6vw, 30px);
  height: clamp(22px, 6vw, 30px);
  border-radius: 7px;
  animation: blink 1.4s ease-in-out infinite;
}
.tile--record.is-recording .meta { color: var(--record); }

.pulse {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 1px solid var(--record);
  opacity: 0;
  pointer-events: none;
}
.tile--record.is-recording .pulse { animation: pulse 1.6s ease-out infinite; }

@keyframes pulse {
  0% { opacity: .5; transform: scale(1); }
  70%, 100% { opacity: 0; transform: scale(1.015); }
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: .45; }
}

/* --- try bar -------------------------------------------------------------- */
.trybar { display: flex; gap: 8px; align-items: stretch; }

.trybar__main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  min-height: 62px;
  padding: 10px 16px;
  border-radius: 18px;
  border: 1px dashed var(--tile-line-hot);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .18s ease, background .18s ease, transform .12s var(--ease);
}
.trybar__main:not(:disabled):active { transform: scale(.99); }
@media (hover: hover) {
  .trybar__main:not(:disabled):hover { background: var(--tile-hover); border-color: var(--reverse); }
}
.trybar__main.is-recording { border-style: solid; border-color: var(--record); background: var(--tile); }
.trybar__main.is-playing { border-style: solid; border-color: var(--reverse); background: var(--tile); }

.trybar__icon {
  flex: none;
  font-size: 22px;
  line-height: 1;
  color: var(--reverse);
}
.trybar__main.is-recording .trybar__icon { color: var(--record); }
.trybar__text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.trybar__label { font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.trybar__meta {
  font-size: 11.5px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.trybar__redo {
  flex: none;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--tile-line);
  background: var(--tile);
  color: var(--dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
.trybar__redo:not(:disabled):hover { color: var(--ink); border-color: var(--tile-line-hot); }
.trybar__redo[hidden] { display: none; }

/* --- hint ----------------------------------------------------------------- */
.foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.hint {
  margin: 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--dim);
  opacity: .85;
}
.keys { display: none; margin: 0; }
kbd {
  font: inherit;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--tile-line);
  background: var(--tile);
  color: var(--ink);
}

/* --- desktop -------------------------------------------------------------- */
@media (min-width: 760px) {
  .app {
    grid-template-rows: auto auto 1fr auto;
    gap: clamp(14px, 2.2vh, 24px);
    padding: 40px 28px 28px;
  }
  .head { align-items: baseline; gap: 6px; }
  .head h1 { font-size: 34px; }
  .status { font-size: 14.5px; }

  .wave { height: 104px; }

  .deck {
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr;
    gap: 18px;
    align-self: center;
    height: min(40vh, 330px);
  }

  .tile { border-radius: 24px; }
  .tile .icon { font-size: 54px; }
  .tile .label { font-size: 26px; }
  .tile .meta { font-size: 13.5px; }
  .icon--dot { width: 52px; height: 52px; }

  .foot { justify-content: space-between; padding: 0 4px; }
  .hint { text-align: left; font-size: 12.5px; }
  .trybar__main { min-height: 68px; padding: 12px 20px; border-radius: 20px; }
  .trybar__label { font-size: 16px; }
  .trybar__meta { font-size: 12px; }
  .keys {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: var(--dim);
  }
  .keys .sep { opacity: .5; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
