:root {
  --ink: #171713;
  --paper: #eee9df;
  --paper-soft: #f6f2ea;
  --orange: #ff5c35;
  --line: rgba(23, 23, 19, 0.18);
  --muted: #79766e;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 92, 53, .12), transparent 30rem),
    var(--paper);
  font-family: "Manrope", sans-serif;
  min-width: 320px;
}

button { font: inherit; cursor: pointer; }

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
}

.app-shell {
  width: min(1120px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.topbar {
  min-height: 62px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(246, 242, 234, .74);
  backdrop-filter: blur(14px);
}

.brand {
  min-width: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  color: inherit;
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
}

.brand > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand small {
  display: none;
  color: var(--muted);
  font-size: 8px;
  letter-spacing: .1em;
  margin-left: 5px;
}

.brand-mark {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 22px;
}

.brand-mark i {
  display: block;
  width: 2px;
  background: var(--ink);
}

.brand-mark i:nth-child(1),
.brand-mark i:nth-child(4) { height: 8px; }
.brand-mark i:nth-child(2) { height: 18px; }
.brand-mark i:nth-child(3) { height: 13px; }

.return-link {
  flex: 0 0 auto;
  color: var(--ink);
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .12em;
  font: 500 9px "DM Mono", monospace;
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 10px 12px;
  transition: .2s ease;
}

.return-link:hover {
  border-color: var(--orange);
  color: var(--orange);
}

.tool-card {
  min-height: 0;
  border-radius: 30px;
  overflow: hidden;
  background: var(--ink);
  box-shadow: 0 22px 70px rgba(35, 30, 23, .12);
  display: grid;
  grid-template-rows: auto auto minmax(250px, 1fr) auto auto;
}

.intro {
  padding: 16px 18px;
  background: var(--paper-soft);
}

.intro-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px 18px;
}

.eyebrow {
  margin: 0;
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .15em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow span {
  width: 26px;
  height: 1px;
  background: var(--orange);
  display: inline-block;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 8vw, 68px);
  font-weight: 500;
  letter-spacing: -.06em;
  line-height: .94;
}

h1 em {
  font-family: Georgia, serif;
  font-weight: 400;
  color: var(--orange);
}

.intro p:last-child {
  grid-column: 1 / -1;
  margin: 0;
  color: #5b5953;
  font-size: 13px;
  line-height: 1.55;
}

.metronome-bar {
  min-height: 92px;
  padding: 14px 16px;
  border-top: 1px solid #353530;
  border-bottom: 1px solid #353530;
  background: var(--ink);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.metronome-bar p {
  margin: 0 0 5px;
  color: var(--orange);
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .16em;
}

.metronome-bar span {
  color: #aaa69d;
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.metronome-switch {
  flex: 0 0 auto;
  width: 134px;
  height: 42px;
  border: 1px solid #3d3d38;
  border-radius: 99px;
  background: #0d0d0b;
  color: #88847c;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  padding: 4px;
  position: relative;
  isolation: isolate;
}

.metronome-switch::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: 99px;
  background: var(--paper);
  transition: transform .24s ease, background .24s ease, box-shadow .24s ease;
}

.metronome-switch span {
  text-align: center;
  color: inherit;
  font-size: 9px;
  transition: color .2s ease;
}

.metronome-switch span:first-child {
  color: var(--ink);
}

.metronome-switch.is-on {
  border-color: rgba(255, 92, 53, .72);
  box-shadow: 0 0 24px rgba(255, 92, 53, .18);
}

.metronome-switch.is-on::before {
  transform: translateX(100%);
  background: var(--orange);
  box-shadow: 0 0 34px rgba(255, 92, 53, .45);
}

.metronome-switch.is-on span:first-child {
  color: #88847c;
}

.metronome-switch.is-on span:last-child {
  color: var(--paper);
}

.metronome-switch.is-pulse::before {
  filter: brightness(1.4);
}

.metronome-controls {
  display: grid;
  gap: 8px;
  justify-items: stretch;
}

.manual-toggle {
  width: 134px;
  min-height: 32px;
  border: 1px solid #3d3d38;
  border-radius: 99px;
  background: transparent;
  color: #aaa69d;
  font: 500 9px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .1em;
  transition: .2s ease;
}

.manual-toggle:hover,
.manual-toggle.is-open {
  border-color: var(--orange);
  color: var(--orange);
}

.manual-form {
  flex: 1 1 100%;
  display: grid;
  grid-template-columns: auto minmax(92px, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #353530;
}

.manual-form[hidden] {
  display: none;
}

.manual-form label {
  color: #aaa69d;
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.manual-form input {
  min-width: 0;
  height: 38px;
  border: 1px solid #3d3d38;
  border-radius: 99px;
  background: #0d0d0b;
  color: var(--paper);
  font: 500 18px "DM Mono", monospace;
  text-align: center;
}

.manual-form input:focus {
  outline: 0;
  border-color: var(--orange);
}

.manual-form button {
  height: 38px;
  border: 0;
  border-radius: 99px;
  background: var(--orange);
  color: var(--paper);
  font: 500 9px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .1em;
  padding: 0 14px;
}

.tap-pad {
  width: 100%;
  min-height: 240px;
  border: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid rgba(238, 233, 223, .14);
  color: var(--paper);
  background:
    radial-gradient(circle at 50% 26%, rgba(255, 92, 53, .22), transparent 18rem),
    var(--ink);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 4px;
  touch-action: manipulation;
  user-select: none;
  position: relative;
  overflow: hidden;
  scroll-margin-top: 0;
  transition: transform .08s ease, filter .16s ease;
}

.tap-pad::before,
.tap-pad::after {
  content: "";
  position: absolute;
  inset: -35%;
  pointer-events: none;
  opacity: 0;
  transition: opacity .18s ease;
}

.tap-pad::before {
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, .38), transparent 18%),
    radial-gradient(circle at 50% 42%, rgba(255, 92, 53, .34), transparent 34%);
  filter: blur(18px);
  animation: none;
}

.tap-pad::after {
  background:
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .18), transparent);
  mix-blend-mode: screen;
  filter: blur(0);
}

.tap-pad:active,
.tap-pad.is-tapping {
  filter: brightness(1.32) saturate(1.45);
}

.tap-pad.is-tapping::before,
.tap-pad.is-tapping::after {
  opacity: 1;
}

.tap-pad.is-tapping::before {
  animation: blinkPulse .22s ease-out;
}

.tap-pad.is-tapping::after {
  animation: blinkSweep .22s ease-out;
}

.tap-count,
.tap-hint {
  color: #aaa69d;
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .14em;
}

.tap-pad strong {
  font-size: clamp(84px, 30vw, 170px);
  font-weight: 500;
  letter-spacing: -.09em;
  line-height: .86;
}

.tap-pad small {
  color: var(--orange);
  font: 500 13px "DM Mono", monospace;
  letter-spacing: .24em;
}

.tap-pad > * {
  position: relative;
  z-index: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--ink);
  color: var(--paper);
}

.stats-grid article {
  min-width: 0;
  padding: 16px 14px;
  border-right: 1px solid #353530;
}

.stats-grid article:last-child {
  border-right: 0;
}

.stats-grid p {
  margin: 0 0 10px;
  color: #918e87;
  font-size: 10px;
}

.stats-grid strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font: 500 clamp(18px, 5vw, 28px) "DM Mono", monospace;
  white-space: nowrap;
}

.stats-grid span {
  display: block;
  margin-top: 4px;
  color: #77746e;
  font: 10px "DM Mono", monospace;
}

.actions {
  display: flex;
  justify-content: center;
  padding: 14px;
  background: var(--ink);
}

.ghost-button {
  width: min(260px, 100%);
  min-height: 48px;
  border: 1px solid #373733;
  border-radius: 99px;
  background: transparent;
  color: var(--paper);
  font: 500 10px "DM Mono", monospace;
  text-transform: uppercase;
  letter-spacing: .14em;
  transition: .2s ease;
}

.ghost-button:hover:not(:disabled) {
  border-color: var(--paper);
}

.ghost-button:disabled {
  cursor: not-allowed;
  opacity: .35;
}

.ghost-button.danger {
  color: var(--orange);
}

@keyframes blinkPulse {
  0% {
    transform: scale(.72);
    opacity: 0;
  }
  32% {
    opacity: 1;
  }
  100% {
    transform: scale(1.18);
    opacity: 0;
  }
}

@keyframes blinkSweep {
  from {
    transform: translateX(-48%) scaleX(.42);
    opacity: .9;
  }
  to {
    transform: translateX(48%) scaleX(.82);
    opacity: 0;
  }
}

@media (min-width: 700px) {
  .app-shell {
    padding: 24px;
  }

  .topbar {
    padding: 16px 20px;
  }

  .brand {
    font-size: 13px;
  }

  .brand small {
    display: inline;
  }

  .return-link {
    font-size: 10px;
    padding: 11px 16px;
  }

  .tool-card {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(300px, 1fr) auto auto;
    max-height: calc(100dvh - 124px);
  }

  .intro {
    padding: 18px 24px;
  }

  .intro-strip {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .intro p:last-child {
    grid-column: auto;
    justify-self: end;
    max-width: 390px;
    text-align: right;
  }

  .tap-pad {
    grid-row: auto;
    grid-column: auto;
    min-height: 0;
    border-top: 1px solid #353530;
    border-left: 0;
    padding-top: 0;
  }

  .metronome-bar {
    min-height: 84px;
    padding: 14px 24px;
  }

  .stats-grid,
  .actions {
    grid-column: auto;
  }
}

@media (max-width: 699px) {
  .app-shell {
    min-height: 100svh;
    padding: 8px;
    gap: 8px;
  }

  .topbar {
    min-height: 48px;
    padding: 9px 10px;
    border-radius: 18px;
  }

  .brand {
    font-size: 9px;
  }

  .return-link {
    font-size: 8px;
    padding: 8px 9px;
  }

  .tool-card {
    min-height: calc(100svh - 64px);
    border-radius: 22px;
  }

  .intro {
    padding: 12px 14px 10px;
  }

  .intro-strip {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: clamp(25px, 9.6vw, 36px);
    line-height: .9;
  }

  .intro p:last-child {
    font-size: 10px;
    line-height: 1.3;
  }

  .metronome-bar {
    min-height: 68px;
    padding: 9px 12px;
    gap: 9px;
  }

  .metronome-bar p {
    font-size: 9px;
  }

  .metronome-bar span {
    font-size: 8px;
  }

  .metronome-switch {
    width: 108px;
    height: 34px;
  }

  .manual-toggle {
    width: 108px;
    min-height: 25px;
    font-size: 8px;
  }

  .manual-form {
    grid-template-columns: 1fr 92px;
  }

  .manual-form label {
    display: none;
  }

  .manual-form button {
    height: 34px;
    padding: 0 10px;
    font-size: 8px;
  }

  .manual-form input {
    height: 34px;
    font-size: 16px;
  }

  .tap-pad {
    min-height: 0;
    gap: 2px;
  }

  .tap-pad strong {
    font-size: clamp(60px, 23vw, 96px);
  }

  .tap-count,
  .tap-hint {
    font-size: 8px;
    letter-spacing: .12em;
  }

  .tap-pad small {
    font-size: 10px;
  }

  .stats-grid article {
    padding: 9px 8px;
  }

  .stats-grid p {
    min-height: 20px;
    margin-bottom: 5px;
    font-size: 8px;
  }

  .stats-grid strong {
    font-size: clamp(14px, 4.6vw, 18px);
  }

  .stats-grid span {
    font-size: 8px;
  }

  .actions {
    padding: 8px 12px;
  }

  .ghost-button {
    min-height: 38px;
    font-size: 9px;
  }
}

@media (max-width: 699px) and (max-height: 760px) {
  .intro p:last-child {
    display: none;
  }

  .metronome-bar {
    min-height: 62px;
  }

  .tap-pad strong {
    font-size: clamp(56px, 21vw, 86px);
  }

  .stats-grid article {
    padding-block: 8px;
  }

  .actions {
    padding-block: 7px;
  }
}

@media (max-width: 699px) and (max-height: 680px) {
  .topbar {
    min-height: 44px;
  }

  .tool-card {
    min-height: calc(100svh - 60px);
  }

  .intro {
    padding-block: 10px 8px;
  }

  h1 {
    font-size: clamp(23px, 8.8vw, 32px);
  }

  .stats-grid p,
  .stats-grid span {
    display: none;
  }

  .stats-grid article {
    padding-block: 9px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding: 7px;
    gap: 7px;
  }

  .topbar {
    border-radius: 18px;
    padding: 9px;
  }

  .return-link {
    padding: 9px 10px;
    letter-spacing: .08em;
  }

  .intro {
    padding: 11px 12px 9px;
  }

  .tool-card {
    border-radius: 20px;
  }

  .stats-grid article {
    padding: 8px 7px;
  }
}

@media (max-width: 340px) {
  .return-link {
    display: none;
  }
}
