/* Riff Boi colors — defined once here, used everywhere below. */
:root {
  --bg: #0b0b0b;          /* near-black background */
  --panel: #161616;       /* panels and cards */
  --red: #d7141f;         /* main red: buttons and highlights */
  --red-dark: #8e0d14;    /* pressed buttons */
  --text: #ececec;        /* main text */
  --muted: #8a8a8a;       /* less important text */
  --title-font: 'UnifrakturCook', 'Times New Roman', serif; /* blackletter, only for the logo and titles */
  --label-font: 'Oswald', system-ui, -apple-system, "Segoe UI", sans-serif; /* condensed caps for buttons and labels */
  --tab-font: ui-monospace, Menlo, Consolas, monospace; /* tab: every character the same width */
  /* Angled corners (the metal look): cut the top-left and bottom-right corners off a box. */
  --cut: polygon(14px 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%, 0 14px);
  --cut-small: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

* {
  box-sizing: border-box;
}

/* Flat black with a fine grain texture (an SVG noise pattern), like a printed flyer. */
body {
  margin: 0;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-weight: 600;
}

/* Mobile-first: one centered column that fills the screen. */
.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-height: 100vh;
  min-height: 100dvh; /* phones: the real visible height, without the browser bars */
}

.screen[hidden] {
  display: none;
}

/* --- Home --- */

/* The logo, with the Tuner button tucked in the top corner. */
.home-top {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center;
}

.logo {
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 4.5rem;
  line-height: 1;
  color: var(--red);
  margin: 40px 0 0;
}

/* Blackletter is hard to read in ALL CAPS, so titles keep normal capitals. */
.screen-title {
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 1.75rem;
  color: var(--text);
  opacity: 0.8;
  margin: 0;
}

/* New Riff: a big round record button, the biggest thing on the home screen. */
.record-btn {
  width: 168px;
  height: 168px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: var(--label-font);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--text);
  background: var(--red);
  border: none;
  box-shadow: 0 0 0 6px var(--bg), 0 0 0 10px var(--red-dark); /* a dark gap, then a ring */
  cursor: pointer;
}

.record-btn:active {
  background: var(--red-dark);
}

.record-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
}

/* Latest Riffs: each riff is a card with its date, note count, confidence and a mini tab. */
.riff-list {
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.riff-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  font: inherit;
  color: var(--text);
  text-align: left;
  background: var(--panel);
  border: none;
  border-left: 4px solid var(--red);
  clip-path: var(--cut);
  cursor: pointer;
}

.riff-card:active {
  background: var(--red-dark);
}

.riff-card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--label-font);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.riff-meta {
  color: var(--muted);
  white-space: nowrap;
}

.mini-tab {
  display: block;
  margin: 0;
  font-family: var(--tab-font);
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--muted);
  white-space: pre;
  overflow: hidden;
}

/* --- Buttons --- */

/* The big red buttons (Stop, Done) — full width, with angled corners. */
.big-btn {
  width: 100%;
  padding: 22px;
  font-family: var(--label-font);
  font-size: 1.5rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text);
  background: var(--red);
  border: none;
  clip-path: var(--cut);
  cursor: pointer;
}

.big-btn:active {
  background: var(--red-dark);
}

/* Stop and Done sit at the bottom of the screen, where your thumb is. */
.bottom-btn {
  margin-top: auto;
}

/* Outlined in red (Tuner). */
.secondary-btn {
  padding: 8px 12px;
  font-family: var(--label-font);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text);
  background: transparent;
  border: 2px solid var(--red);
  clip-path: var(--cut-small);
  cursor: pointer;
}

.secondary-btn:active {
  background: var(--red-dark);
}

.tuner-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.small-btn {
  padding: 10px 16px;
  font: inherit;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.small-btn[hidden] {
  display: none;
}

/* "← Latest Riffs" in the top-left corner of the Riff View. */
.back-btn {
  align-self: flex-start;
  padding: 8px 0;
  font: inherit;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
}

/* Keyboard focus: the angled corners would cut off a normal outline, so draw it inside. */
.big-btn:focus-visible,
.secondary-btn:focus-visible,
.riff-card:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: -5px;
}

/* --- Recording --- */

/* Top bar: a pulsing red dot, "Listening…" and the time since New Riff. */
.rec-bar {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-family: var(--label-font);
  text-transform: uppercase;
  letter-spacing: 0.15em;
}

.rec-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--red);
  animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
  50% { opacity: 0.25; }
}

.rec-time {
  margin-left: auto;
  font-family: var(--tab-font);
  letter-spacing: 0.05em;
  color: var(--text);
}

/* The last note heard, big, with the note count under it. */
.note-display {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}

.note-name {
  font-family: var(--tab-font);
  font-size: 4rem;
  line-height: 1;
  color: var(--red);
}

/* The tab: six lines in a monospace font so the fret numbers line up like real tab.
   Scrolls sideways when the riff gets long. */
.tab {
  width: 100%;
  margin: 0;
  padding: 20px 16px;
  background: var(--panel);
  border-left: 4px solid var(--red);
  clip-path: var(--cut);
  font-family: var(--tab-font);
  font-size: 1.25rem;
  line-height: 1.5;
  color: var(--text);
  overflow-x: auto;
}

/* Confidence bar under the tab: 0% (not sure at all) to 100% (very sure), plus a hint. */
.confidence {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.confidence[hidden] {
  display: none;
}

.confidence-label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-family: var(--label-font);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.9rem;
}

.confidence-pct {
  color: var(--text);
}

.confidence-bar {
  height: 8px;
  background: var(--panel);
  border-radius: 4px;
  overflow: hidden;
}

.confidence-fill {
  width: 0;
  height: 100%;
  background: var(--red);
  transition: width 200ms ease-out;
}

.confidence-hint {
  margin: 0;
  min-height: 1.3em; /* keeps the layout still when a hint appears */
  color: var(--muted);
  font-size: 0.9rem;
}

.status-msg {
  color: var(--red);
  min-height: 1.5em;
  margin: 0;
  text-align: center;
}

.muted {
  color: var(--muted);
  margin: 0;
}

/* --- Saving confirmation --- */
.saving-title {
  margin: 20vh 0 0;
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 2.75rem;
  color: var(--red);
}

.saving-details {
  margin: 0;
  font-size: 1.25rem;
}

/* --- Tuner --- */
.tuner {
  width: 100%;
  background: var(--panel);
  border-left: 4px solid var(--red);
  clip-path: var(--cut);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.tuner-note {
  font-family: var(--tab-font);
  font-size: 5rem;
  line-height: 1;
  color: var(--red);
}

.tuner.in-tune .tuner-note,
.tuner.in-tune .tuner-status {
  color: var(--text);
}

/* The meter: -50 cents on the left, in tune in the middle, +50 cents on the right. */
.tuner-meter {
  position: relative;
  width: 100%;
  height: 40px;
  background: var(--bg);
  border-radius: 4px;
}

.tuner-center {
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--muted);
}

.tuner-needle {
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 8px;
  margin-left: -4px;
  border-radius: 4px;
  background: var(--red);
  transition: left 80ms linear;
}

.tuner-needle[hidden] {
  display: none;
}

.tuner.in-tune .tuner-needle {
  background: var(--text);
}

.tuner-scale {
  width: 100%;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
}

.tuner-status {
  font-size: 1.25rem;
  color: var(--red);
}

/* Less movement for people who ask their device for it. */
@media (prefers-reduced-motion: reduce) {
  .rec-dot {
    animation: none;
  }

  .confidence-fill,
  .tuner-needle {
    transition: none;
  }
}
