:root {
  --accent: #C8102E;          /* Welsh flag red: accents only */
  --accent-soft: #c8102e1a;
  --slate: #3b4550;           /* Welsh slate */
  --bg: #fdfbf7;              /* warm off-white */
  --sidebar-bg: #eef0f1;      /* pale slate */
  --card-bg: #ffffff;
  --paper: #fbf6ea;           /* cream, behind the sheet music */
  --text: #262b31;
  --muted: #66707a;
  --border: #dcdfe3;
  --link: #1c6ecf;
  --radius: 8px;
  --search-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2366707a' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='m15.5 15.5 5 5'/%3E%3C/svg%3E");
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --sidebar-bg: #1a1f25;
    --card-bg: #171b21;
    --text: #eef0f2;
    --muted: #a0a8b1;
    --border: #343b44;
    --link: #6fb1ff;
    /* --paper stays cream: the sheet music reads best on paper colours */
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: 1fr auto;
  min-height: 100vh;
  /* The carthen band (Welsh tapestry blanket pattern) across the top. */
  padding-top: 14px;
  background: url("carthen.svg") repeat-x top left / auto 14px, var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--link); }
::selection { background: var(--accent); color: #fff; }
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 .5rem; }
main h1::after, .guide h1::after {    /* short red underline under page titles */
  content: ""; display: block; width: 3rem; height: 3px;
  margin-top: .45rem; border-radius: 2px; background: var(--accent);
}
h2 { font-size: 1.35rem; margin: 2rem 0 .75rem; }
button, input, select { font: inherit; color: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Left column: brand + search on top, then buttons and links */
.nav {
  grid-row: 1 / span 2;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: calc(100vh - 14px);
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.topbar { display: grid; gap: 1rem; }
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; }
.brand {
  display: flex; align-items: center; gap: .6rem;
  font-size: 1.75rem; font-weight: 700; color: var(--accent); text-decoration: none;
}
.sidebar-actions { display: grid; gap: .5rem; }
.sidebar-links { display: grid; gap: .35rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.sidebar-links a { text-decoration: none; }
.sidebar-links a:hover { color: var(--accent); text-decoration: underline; }

button {
  border: 1px solid var(--border);
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: .45rem .9rem;
  cursor: pointer;
  transition: border-color .15s, color .15s, background-color .15s;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { color: #fff; filter: brightness(1.1); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Search boxes (sidebar and the big one on the home page) */
.search { position: relative; }
.search input {
  width: 100%;
  padding: .7rem 2.4rem .7rem 2.5rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--search-icon) no-repeat .85rem center / 1.15rem, var(--card-bg);
  box-shadow: 0 1px 2px #0000000d;
  transition: border-color .15s, box-shadow .15s;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.shortcut {
  position: absolute; right: .8rem; top: 1.35rem; transform: translateY(-50%);
  font: 600 .75rem/1 ui-monospace, monospace; color: var(--muted);
  border: 1px solid var(--border); border-radius: 4px; padding: .2rem .4rem; pointer-events: none;
}
.search input:focus ~ .shortcut { display: none; }
.suggestions {
  position: absolute; left: 0; right: 0; z-index: 20;
  margin: .35rem 0 0; padding: .3rem 0;
  list-style: none;
  max-height: 60vh; overflow-y: auto;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px #00000026;
}
.suggestions li { padding: .45rem 1rem; cursor: pointer; }
.suggestions li[aria-selected="true"] { background: var(--accent-soft); }
.suggestions li.empty { color: var(--muted); cursor: default; }

.hero-search { max-width: 40rem; margin: 1.5rem 0 1rem; }
.hero-search input { font-size: 1.15rem; padding: 1rem 3rem 1rem 3.1rem; background-position: 1.1rem center; background-size: 1.35rem; box-shadow: 0 2px 10px #0000000f; }
.hero-search .shortcut { top: 1.85rem; right: 1.1rem; }

/* Main */
main { padding: 2.5rem 3rem 4rem; max-width: 1200px; width: 100%; animation: fade-in .2s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }
.loading, .caption { color: var(--muted); }
.caption { font-size: .9rem; }
.lead { font-size: 1.1rem; max-width: 50rem; }

.pills { display: flex; flex-wrap: wrap; gap: .5rem; }
.pills button { border-radius: 999px; }
.pills button { display: inline-flex; align-items: center; }
.pills button:hover:not(:disabled) { border-color: var(--c); color: inherit; }
.pills button[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); font-weight: 600; }

/* Tune-type colourways: a small woven swatch */
.swatch {
  display: inline-block; flex: none;
  width: .7em; height: .7em; margin-right: .5em;
  border-radius: 2px;
  background: repeating-linear-gradient(45deg, var(--c) 0 2px, color-mix(in srgb, var(--c) 65%, #fff) 2px 3px);
  box-shadow: inset 0 0 0 1px #00000022;
}
.tune-list .swatch { width: .55em; height: .55em; opacity: .9; transform: translateY(-.05em); }

/* A short strip of the carthen under section headings */
.section-heading::after, .about h2::after {
  content: ""; display: block; width: 9rem; height: 7px; margin-top: .45rem;
  background: url("carthen.svg") repeat-x left center / auto 7px;
}
.tune-list { columns: 3 14rem; column-gap: 2rem; padding: 0; list-style: none; margin: .5rem 0 0; }
.tune-list li { break-inside: avoid; padding: .15rem 0; display: flex; align-items: baseline; }  /* long names wrap beside the swatch */
.tune-list a { color: var(--text); text-decoration: none; }
.tune-list a:hover { color: var(--accent); text-decoration: underline; }

/* Tune page */
.controls { display: flex; flex-wrap: wrap; gap: 1rem 2.5rem; align-items: end; margin: 1rem 0 1.25rem; }
.control label { display: block; font-size: .9rem; margin-bottom: .3rem; }
.control select { padding: .4rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); }
.control.tempo { flex: 1 1 18rem; max-width: 32rem; }
.control input[type="range"] { width: 100%; accent-color: var(--accent); }
.practice-toggle { margin-left: auto; }
.tune-layout { display: grid; grid-template-columns: minmax(0, 3fr) minmax(14rem, 1fr); gap: 1.5rem; align-items: start; }
.score {                     /* sheet music on cream "paper", also in dark mode */
  background: var(--paper); color: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1rem 1rem;
  box-shadow: 0 1px 3px #0000000f;
}
.score .abcjs-inline-audio { background-color: var(--slate); border-radius: 6px; }
.score .abcjs-inline-audio .abcjs-midi-progress-background { background-color: #2a323b; }
.score .abcjs-note_playing { fill: var(--accent); }
/* Player: red progress knob, and play/loop in red while they're on. */
.score .abcjs-inline-audio .abcjs-midi-progress-indicator { background-color: var(--accent); }
.score .abcjs-inline-audio .abcjs-btn.abcjs-pushed { background-color: var(--accent); }
.card { border: 1px solid var(--border); border-top: 3px solid var(--accent); border-radius: var(--radius); padding: 1rem 1.1rem; background: var(--card-bg); }
.card h2 { margin: 0 0 .6rem; font-size: 1.15rem; }
.card dl { margin: 0; }
.card dt { font-weight: 600; }
.card dd { margin: 0 0 .5rem; }
details.abc { margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .9rem; background: var(--card-bg); }
details.abc summary { cursor: pointer; }
details.abc pre { overflow-x: auto; font-size: .8rem; margin: .75rem 0 .25rem; }

/* Footer: the carthen band again, and a line of links */
.site-footer {
  padding: 22px 3rem 1.5rem;
  background: url("carthen.svg") repeat-x top left / auto 14px;
  color: var(--muted); font-size: .9rem;
}
.site-footer p { margin: 0; max-width: 1200px; }
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }

/* Practice mode: just the controls and a big score, for a tablet on a music stand */
body.practice { grid-template-columns: 1fr; }
body.practice .nav, body.practice .tune-side, body.practice .site-footer, body.practice main h1::after, body.practice .aka { display: none; }
body.practice main { max-width: none; padding: 1rem 1.5rem 2rem; }
body.practice h1 { font-size: 1.4rem; }
body.practice .controls { margin: .5rem 0 1rem; }
body.practice .tune-layout { grid-template-columns: 1fr; }
body.practice .score { width: 100%; max-width: 1400px; margin: 0 auto; padding: 1rem 1.5rem 1.5rem; }

/* Guide pages (CONTRIBUTING.md) */
.guide { max-width: 50rem; }
.guide table { border-collapse: collapse; margin: 1rem 0; }
.guide th, .guide td { border: 1px solid var(--border); padding: .35rem .6rem; text-align: left; vertical-align: top; }
.guide pre { background: var(--sidebar-bg); padding: .75rem 1rem; border-radius: var(--radius); overflow-x: auto; }
.guide code { font-size: .9em; }

/* Narrow screens: brand + search pinned to the top, everything else in one column */
@media (max-width: 800px) {
  body { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr auto; }  /* top bar, sidebar, page, footer */
  .nav { display: contents; }
  .topbar {
    position: sticky; top: 0; z-index: 30;
    grid-template-columns: auto 1fr; align-items: center; gap: .75rem;
    background: var(--sidebar-bg); padding: .6rem 1rem;
    border-bottom: 1px solid var(--border); box-shadow: 0 2px 8px #0000000f;
  }
  .brand { font-size: 1.25rem; gap: .4rem; }
  .brand img { width: 26px; height: 26px; }
  .search input { padding-top: .55rem; padding-bottom: .55rem; }
  .topbar .shortcut { display: none; }
  .sidebar { background: var(--sidebar-bg); padding: .6rem 1rem .8rem; gap: .6rem; border-bottom: 1px solid var(--border); }
  .sidebar-actions { grid-template-columns: 1fr 1fr; }
  .sidebar-links { display: flex; flex-wrap: wrap; gap: .25rem 1rem; padding-top: .5rem; font-size: .9rem; }
  main { padding: 1.5rem 1rem 3rem; }
  .site-footer { padding: 22px 1rem 1.25rem; }
  .tune-layout { grid-template-columns: 1fr; }
  .practice-toggle { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { main { animation: none; } }
