:root {
  color-scheme: dark;
  --bg: #111418;
  --panel: #1a2027;
  --panel-strong: #242c34;
  --screen: #d7f6ca;
  --screen-ink: #102012;
  --warning: #f4c430;
  --warning-dark: #af7d12;
  --red: #f45b69;
  --green: #38d184;
  --blue: #64b5f6;
  --ink: #f3f7fb;
  --muted: #aeb8c2;
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 15%, rgba(244, 196, 48, 0.18), transparent 34%),
    linear-gradient(135deg, #101418 0%, #182026 42%, #12161b 100%);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  min-height: 100dvh;
  width: min(100%, 340px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: minmax(300px, 316px);
  gap: 0;
  align-items: center;
  justify-content: center;
}

.instrument {
  position: relative;
  width: min(100%, 316px);
  min-height: 0;
  padding: 10px;
  border: 3px solid #0b0c0d;
  border-radius: 28px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.2), transparent 28%),
    linear-gradient(155deg, #f3c733 0%, #c8941c 100%);
  color: #18140c;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 156px auto auto auto 96px;
  gap: 9px;
  justify-self: center;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.eyebrow {
  margin: 0 0 4px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.instrument .eyebrow {
  color: rgba(24, 20, 12, 0.66);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.48rem;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 12px;
  font-size: clamp(1.7rem, 4vw, 3rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.info-button {
  width: 30px;
  min-height: 30px;
  padding: 0;
  border: 2px solid #151719;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: #151719;
  font-size: 1rem;
  line-height: 1;
  box-shadow: none;
}

.meter {
  min-height: 156px;
  padding: 10px;
  border: 4px solid #151719;
  border-radius: 16px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0)),
    var(--screen);
  color: var(--screen-ink);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.35),
    inset 0 -18px 28px rgba(18, 62, 24, 0.12);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
}

.meter-topline,
.readings {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meter-topline span,
.readings span {
  white-space: nowrap;
}

.count-output {
  align-self: center;
  justify-self: center;
  font-family: "SF Mono", "Roboto Mono", ui-monospace, monospace;
  font-size: 4.55rem;
  font-weight: 900;
  line-height: 0.88;
  letter-spacing: 0;
  text-shadow: 0 4px 0 rgba(53, 95, 45, 0.1);
}

.count-output[data-digits="4"] {
  font-size: 3.8rem;
}

.count-output[data-digits="5"],
.count-output[data-digits="6"] {
  font-size: 3.1rem;
}

.actions {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 0.8fr);
  gap: 7px;
}

button {
  min-width: 0;
  min-height: 40px;
  padding: 0 6px;
  border: 0;
  border-radius: 10px;
  background: #1a1d20;
  color: #fff7da;
  font-weight: 850;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    0 8px 18px rgba(22, 14, 4, 0.22);
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button.active,
.primary-action {
  background: #132018;
  color: #a9ffd0;
}

.primary-action.running {
  background: #391318;
  color: #ffd5da;
}

.source-options {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.source-options legend {
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.source-options label {
  min-width: 0;
  min-height: 42px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 2px solid rgba(0, 0, 0, 0.18);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.68rem;
  font-weight: 900;
  cursor: pointer;
}

.source-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.source-options label:has(input:checked) {
  border-color: #161616;
  background: #151719;
  color: #fff3cb;
}

.audio-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  align-items: center;
  color: #1a1408;
  font-size: 0.72rem;
  font-weight: 850;
}

.toggle-line,
.volume-control {
  min-width: 0;
  min-height: 36px;
  padding: 7px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-line:has(#vibrationToggle) {
  display: none;
}

.volume-control {
  grid-column: 1 / -1;
}

.volume-control input {
  width: 100%;
  accent-color: #191c1f;
}

.toggle-line input {
  width: 16px;
  height: 16px;
  accent-color: #151719;
}

.footer-emblem {
  min-height: 96px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.08)),
    rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
}

.footer-emblem img {
  width: 82px;
  aspect-ratio: 1;
  opacity: 0.92;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.2));
}

.reference-links {
  margin: 24px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reference-links a {
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.05);
}

.reference-links a:hover {
  border-color: rgba(244, 196, 48, 0.56);
  color: #ffe08a;
}

.source-data {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 10px;
}

.source-data div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.source-data dt {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.source-data dd {
  margin: 0;
  color: var(--ink);
  font-size: 1.18rem;
  font-weight: 900;
}

.about-dialog {
  width: min(calc(100vw - 28px), 560px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: transparent;
  color: var(--ink);
}

.about-dialog::backdrop {
  background: rgba(5, 8, 11, 0.72);
  backdrop-filter: blur(8px);
}

.about-card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, #202833, #151a21);
  box-shadow: var(--shadow);
}

.about-card p {
  color: var(--muted);
  line-height: 1.55;
}

.about-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 12px;
}

.about-header h2 {
  margin: 0;
  font-size: 1.8rem;
}

.about-header button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
}

@media (max-width: 520px) {
  body {
    background: #111418;
  }

  .app-shell {
    min-height: 100dvh;
    width: 100%;
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
    grid-template-columns: 1fr;
    align-items: start;
  }

  .instrument {
    width: 100%;
    justify-self: stretch;
    min-height: calc(100dvh - 20px);
    padding: 14px;
    border-radius: 24px;
    gap: 10px;
    grid-template-rows: auto 1fr auto auto auto;
  }

  .meter {
    min-height: 218px;
    padding: 13px;
  }

  .meter-topline,
  .readings {
    font-size: 0.72rem;
  }

  .actions {
    grid-template-columns: repeat(4, 1fr);
  }

  button {
    min-height: 48px;
    border-radius: 10px;
    font-size: 0.9rem;
  }

  .source-options label {
    min-height: 48px;
    font-size: 0.76rem;
  }

  .audio-controls {
    grid-template-columns: 1fr 1fr;
  }

  .toggle-line:has(#vibrationToggle) {
    display: flex;
  }

  .volume-control {
    grid-column: 1 / -1;
  }

  .footer-emblem {
    display: none;
  }

}

@media (max-width: 380px) {
  .instrument {
    gap: 8px;
  }

  .meter {
    min-height: 196px;
  }

  .count-output {
    font-size: clamp(4.7rem, 24vw, 6.2rem);
  }

  .count-output[data-digits="4"] {
    font-size: clamp(4rem, 20vw, 5.4rem);
  }

  .count-output[data-digits="5"],
  .count-output[data-digits="6"] {
    font-size: clamp(3.3rem, 17vw, 4.5rem);
  }

  .actions,
  .source-options {
    gap: 6px;
  }

  button {
    min-height: 44px;
    font-size: 0.82rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
