:root {
  --paper: #e8ddc7;   /* light-brown background */
  --ink: #2b1f13;     /* espresso — text, borders, hover-invert fill */
  --dim: #6d5a3f;     /* mid-brown — secondary text, empty bars */
  --accent: #5a4b7c;  /* dusty purple — active/selected fill only */
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  font-family: var(--mono);
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  max-width: 44rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  text-transform: uppercase;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
}

h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0;
}

h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 2rem 0 0.5rem;
  border-top: 2px solid var(--ink);
  padding-top: 0.5rem;
}

a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
}
a:hover { background: var(--ink); color: var(--paper); }

.note { color: var(--dim); }

button, input {
  font: inherit;
  text-transform: uppercase;
  border-radius: 0;
  -webkit-appearance: none;
  appearance: none;
}

button {
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
}
button:hover { background: var(--ink); color: var(--paper); }
button[aria-pressed="true"] { background: var(--accent); color: var(--paper); border-color: var(--accent); }
button[aria-pressed="true"]:hover { background: var(--ink); border-color: var(--ink); }

:focus-visible { outline: 2px dashed var(--ink); outline-offset: 2px; }

/* ---- deck ---- */
.deck {
  border: 2px solid var(--ink);
  padding: 0.75rem;
  margin-top: 1rem;
}
.deck-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.deck-row + .deck-row { margin-top: 0.6rem; }
.deck-row > label,
.deck-row > .lbl {
  flex: 0 0 auto;
  min-width: 3.5rem;
}
#status, #ears { font-variant-numeric: tabular-nums; }
.val { min-width: 3ch; text-align: right; }

input[type="range"] {
  flex: 1;
  height: 20px;
  background: transparent;
  min-width: 6rem;
}
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--ink);
  margin-top: -6px;
  border-radius: 0;
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--ink); }
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--ink);
  border: none;
  border-radius: 0;
}

/* ---- message ---- */
#msg {
  border: 2px solid var(--ink);
  padding: 0.4rem 0.6rem;
  font-weight: 700;
  margin: 1rem 0 0;
}

/* ---- beat rows ---- */
.rows { border-bottom: 2px solid var(--ink); }
.rows .row:first-child { border-top: 2px solid var(--ink); }
.row {
  display: flex;
  align-items: stretch;
  border-bottom: 2px solid var(--ink);
}
.rows .row:last-child { border-bottom: none; }

.sel {
  flex: 1;
  min-width: 0;
  border: none;
  background: none;
  color: inherit;
  text-align: left;
  display: grid;
  grid-template-columns: 4ch 12ch 9ch 1fr;
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.25rem;
}
.sel .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel .t { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel:hover { background: var(--ink); color: var(--paper); }
.sel:hover .t { color: var(--paper); }

.act {
  flex: 0 0 auto;
  border: none;
  border-left: 2px solid var(--ink);
  background: none;
  color: inherit;
}

.row.current { background: var(--accent); color: var(--paper); }
.row.current .t { color: var(--paper); }
.row.current .act { border-left-color: var(--paper); }

/* ---- carrier ---- */
.carrier {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
}
#carrier-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
#carrier-input {
  flex: 1 1 8rem;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 0.3rem 0.5rem;
}

/* ---- custom form ---- */
#custom-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 0.5rem;
}
#custom-form input {
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  padding: 0.3rem 0.5rem;
}
#c-name { flex: 2 1 8rem; }
#c-carrier, #c-beat { flex: 1 1 6rem; }
#c-add { flex: 0 0 auto; }

/* ---- blink cursor ---- */
@keyframes blink { 50% { opacity: 0; } }
.blink { animation: blink 1s steps(1) infinite; }
@media (prefers-reduced-motion: reduce) { .blink { animation: none; } }

/* ---- metrics charts ---- */
.chart { overflow-x: auto; font-variant-numeric: tabular-nums; }
.chart-row {
  display: grid;
  grid-template-columns: 6ch 1fr;
  gap: 0.5rem;
  padding: 0.2rem 0;
  width: max-content;
  min-width: 100%;
}
.chart-row.beat { grid-template-columns: 12ch 7ch 1fr; }
.chart-row .bn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barcell { white-space: nowrap; }
.chart .bar { color: var(--ink); }
.chart .bar.zero { color: var(--dim); }
.chart .t { color: var(--dim); margin-left: 0.5ch; }
.actions { margin-top: 2rem; }

/* ---- footer ---- */
footer {
  color: var(--dim);
  font-size: 0.8rem;
  margin-top: 3rem;
}
footer p { margin: 0.3rem 0; }

/* ---- mobile ---- */
@media (max-width: 600px) {
  body { font-size: 15px; }
  .sel { grid-template-columns: 4ch 1fr 9ch; }
  .sel .t { display: none; }
  #custom-form input { flex: 1 1 100%; }
}
