:root {
  color-scheme: light;
  --paper: #f3f0e8;
  --ink: #20211e;
  --muted: #72736b;
  --line: #cfcec4;
  --texture: #c9c7bd;
  --placeholder: #929187;
  --tile-ink: #20211e;
  --red: #f05b42;
  --lime: #d6f05a;
  --blue: #66c6d1;
  --yellow: #f6c950;
  --pink: #ed9ec0;
  --display: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
  --body: 'Trebuchet MS', 'Segoe UI', sans-serif;
  --mono: Consolas, 'Courier New', monospace;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme='system'] {
    color-scheme: dark;
    --paper: #191b18;
    --ink: #f1efe7;
    --muted: #a6a69d;
    --line: #474941;
    --texture: #30332d;
    --placeholder: #a5a59b;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --paper: #191b18;
  --ink: #f1efe7;
  --muted: #a6a69d;
  --line: #474941;
  --texture: #30332d;
  --placeholder: #a5a59b;
}

* { box-sizing: border-box; }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--paper);
  background-image: radial-gradient(var(--texture) 0.65px, transparent 0.65px);
  background-size: 9px 9px;
  font-family: var(--body);
}

button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: min(100% - 40px, 1120px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 0 max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  font: 500 11px var(--mono);
  letter-spacing: 0.04em;
}

.topbar__right { display: flex; align-items: center; gap: 24px; }

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.wordmark__mark {
  width: 30px;
  height: 30px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 2px;
  object-fit: contain;
}

.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.connection__dot, .status-line__pulse { width: 7px; height: 7px; border-radius: 50%; background: #7c9d40; }

.theme-switch { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 3px; }
.theme-option { width: 30px; height: 28px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 2px; background: transparent; color: var(--muted); cursor: pointer; }
.theme-option svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.theme-option:hover { color: var(--ink); }
.theme-option[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.theme-option:focus-visible { outline: 2px solid #2b6f88; outline-offset: 2px; }

main { flex: 1; }

.intro {
  min-height: 235px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 31px 0 28px;
}

.eyebrow, .clip-count__label, .status-line, .footer, .sound-button__index, .sound-button__format {
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.eyebrow { margin: 0 0 10px; color: var(--red); font-size: 10px; font-weight: 500; }

h1 {
  margin: 0;
  font: 900 clamp(62px, 10vw, 112px)/0.78 var(--display);
  letter-spacing: 0;
}

h1 span { color: var(--red); }

.clip-count {
  width: 106px;
  height: 106px;
  margin: 0 7% 0 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  transform: rotate(8deg);
}

.clip-count__number { font: 700 40px/1 var(--display); }
.clip-count__label { font-size: 8px; line-height: 1.5; }

.controls {
  min-height: 60px;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.search-box {
  min-width: 120px;
  display: flex;
  align-items: center;
  flex: 1;
  gap: 12px;
}

.search-box__prefix { color: var(--muted); font: 10px var(--mono); }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 14px; }
.search-box input::placeholder { color: var(--placeholder); opacity: 1; }
.search-box__key { min-width: 22px; padding: 3px 6px; border: 1px solid var(--line); color: var(--muted); font: 11px var(--mono); text-align: center; }
.volume-control { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.volume-control svg { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.volume-control input { width: 86px; height: 24px; margin: 0; accent-color: var(--red); cursor: pointer; }
.volume-control output { width: 32px; color: var(--muted); font: 9px var(--mono); text-align: right; }

.control-actions { display: flex; gap: 8px; }
.utility-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--ink);
  border-radius: 2px;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.utility-button:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.utility-button:disabled { cursor: not-allowed; opacity: 0.4; }
.utility-button--refresh { background: var(--ink); color: var(--paper); }
.utility-button--refresh:hover:not(:disabled) { background: var(--red); border-color: var(--red); }
.refresh-symbol { display: inline-block; margin-right: 4px; font-size: 16px; line-height: 0; vertical-align: -1px; }

.category-strip { min-height: 55px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.category-tabs { min-width: 0; display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: thin; }
.category-tab { min-height: 32px; flex: 0 0 auto; padding: 0 11px; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--muted); font: 10px var(--mono); cursor: pointer; }
.category-tab:hover { border-color: var(--ink); color: var(--ink); }
.category-tab[aria-selected='true'] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.category-tab-group { min-width: 0; display: flex; flex: 0 0 auto; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 2px; }
.category-tab-group .category-tab { border: 0; border-radius: 0; }
.category-color-picker { width: 30px; height: 30px; display: grid; flex: 0 0 auto; place-items: center; border-left: 1px solid var(--line); cursor: pointer; }
.category-color-picker input { width: 18px; height: 18px; padding: 0; overflow: hidden; border: 0; border-radius: 50%; background: transparent; cursor: pointer; appearance: none; -webkit-appearance: none; }
.category-color-picker input::-webkit-color-swatch-wrapper { padding: 0; }
.category-color-picker input::-webkit-color-swatch, .category-color-picker input::-moz-color-swatch { border: 1px solid var(--line); border-radius: 50%; }
.category-color-picker input:focus-visible { outline: 2px solid #2b6f88; outline-offset: 2px; }
.category-manage-button { width: 28px; height: 30px; display: grid; flex: 0 0 auto; place-items: center; padding: 0; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.category-manage-button:hover { color: var(--ink); }
.category-manage-button svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.add-category-button { min-height: 34px; flex: 0 0 auto; display: inline-flex; align-items: center; gap: 5px; padding: 0 9px; border: 0; background: transparent; color: var(--red); font-size: 11px; font-weight: 700; cursor: pointer; }
.add-category-button:hover { color: var(--ink); }
.add-category-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.8; }

.status-line {
  min-height: 37px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 9px;
  text-transform: uppercase;
}

.status-line__pulse { width: 6px; height: 6px; flex: 0 0 auto; }
.status-line[data-state='error'] .status-line__pulse { background: var(--red); }
.status-line[data-state='loading'] .status-line__pulse { background: var(--yellow); animation: blink 0.8s steps(2, start) infinite; }

.sound-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  padding: 4px 0 28px;
}

.sound-card { position: relative; min-width: 0; display: flex; flex-direction: column; }

.sound-button {
  position: relative;
  min-width: 0;
  min-height: 170px;
  aspect-ratio: 1.15;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  padding: 15px 16px;
  border: 1px solid var(--tile-ink);
  border-radius: 3px;
  background: var(--tone, var(--lime));
  color: var(--tile-ink);
  text-align: left;
  cursor: pointer;
  transition: transform 110ms ease, box-shadow 110ms ease, filter 110ms ease;
  -webkit-tap-highlight-color: transparent;
}

.sound-card:nth-child(5n + 1) .sound-button { --tone: var(--lime); }
.sound-card:nth-child(5n + 2) .sound-button { --tone: var(--red); }
.sound-card:nth-child(5n + 3) .sound-button { --tone: var(--blue); }
.sound-card:nth-child(5n + 4) .sound-button { --tone: var(--yellow); }
.sound-card:nth-child(5n) .sound-button { --tone: var(--pink); }
.sound-button:hover { z-index: 1; transform: translateY(-3px); box-shadow: 4px 4px 0 var(--ink); }
.sound-button:active { transform: translateY(1px) scale(0.985); box-shadow: none; }
.sound-button:focus-visible, .utility-button:focus-visible, .search-box input:focus-visible { outline: 3px solid #2b6f88; outline-offset: 3px; }
.sound-button.is-playing { box-shadow: inset 0 0 0 3px var(--ink); }
.sound-button.is-playing .sound-button__play { animation: thump 0.65s ease-in-out infinite alternate; }

.sound-button__top, .sound-button__bottom { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sound-button__index, .sound-button__format { font-size: 9px; }
.sound-button__play { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; }
.sound-button__play svg { width: 11px; height: 11px; display: block; fill: currentColor; }
.favorite-button { position: absolute; z-index: 2; top: 10px; right: 49px; width: 29px; height: 29px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--tile-ink); cursor: pointer; }
.favorite-button:hover { background: rgba(255, 255, 255, 0.3); }
.favorite-button svg { width: 17px; height: 17px; fill: transparent; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.favorite-button[aria-pressed='true'] { color: #d32f48; }
.favorite-button[aria-pressed='true'] svg { fill: currentColor; }
.sound-button__name { width: 100%; margin: auto 0; overflow-wrap: anywhere; font: 800 30px/0.95 var(--display); text-transform: uppercase; }
.sound-button__bottom { margin-top: 12px; }
.sound-button__state { font: 9px var(--mono); }
.sound-button__state[data-state='loading'] { color: #374a70; }
.sound-button__state[data-state='stream'] { color: #74472e; }

.sound-category-button { min-width: 0; min-height: 34px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--ink); border-top: 0; border-radius: 0 0 3px 3px; background: var(--paper); color: var(--muted); text-align: left; cursor: pointer; }
.sound-category-button:hover { color: var(--ink); }
.sound-category-button svg { width: 14px; height: 14px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.6; }
.sound-category-button__label { min-width: 0; overflow: hidden; font: 9px var(--mono); text-overflow: ellipsis; white-space: nowrap; }

.category-dialog { width: min(100% - 32px, 420px); max-width: 420px; padding: 0; border: 1px solid var(--ink); border-radius: 3px; background: var(--paper); color: var(--ink); box-shadow: 6px 6px 0 rgba(0, 0, 0, 0.25); }
.category-dialog::backdrop { background: rgba(15, 16, 14, 0.62); }
.category-dialog__surface { padding: 22px; }
.category-dialog__header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.category-dialog__header .eyebrow { margin-bottom: 6px; }
.category-dialog h2 { margin: 0; font: 800 34px/0.95 var(--display); }
.dialog-close { width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--muted); cursor: pointer; }
.dialog-close:hover { border-color: var(--ink); color: var(--ink); }
.dialog-close svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-width: 1.8; }
.category-dialog__description { margin: 12px 0 18px; color: var(--muted); font-size: 13px; }
.category-name-field, .category-color-field { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font: 10px var(--mono); }
.category-name-field input { width: 100%; min-height: 42px; padding: 0 10px; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--ink); font: 14px var(--body); }
.category-name-field input:focus-visible { outline: 2px solid #2b6f88; outline-offset: 2px; }
.category-color-field { margin-top: 14px; }
.category-color-field input { width: 42px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 2px; background: transparent; cursor: pointer; }
.category-color-field[hidden] { display: none; }
.category-dialog__error { margin: 8px 0 0; color: var(--red); font-size: 12px; }
.category-options { max-height: min(45vh, 320px); display: grid; gap: 6px; overflow-y: auto; }
.category-management-controls { display: grid; gap: 12px; margin-top: 18px; }
.category-management-controls[hidden] { display: none; }
.category-order-controls { display: flex; gap: 8px; }
.category-order-button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; flex: 1; padding: 0 8px; border: 1px solid var(--line); border-radius: 2px; background: transparent; color: var(--ink); font-size: 11px; cursor: pointer; }
.category-order-button:hover:not(:disabled) { border-color: var(--ink); background: var(--line); }
.category-order-button:disabled { opacity: 0.4; cursor: not-allowed; }
.category-order-button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.category-delete-button { min-height: 38px; justify-self: start; padding: 0 10px; border: 1px solid var(--red); border-radius: 2px; background: transparent; color: var(--red); font-size: 11px; font-weight: 700; cursor: pointer; }
.category-delete-button:hover { background: var(--red); color: #20211e; }
.category-choice { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 10px; border: 1px solid var(--line); border-radius: 2px; color: var(--ink); font-size: 13px; }
.category-choice__name { min-width: 0; display: flex; align-items: center; flex: 1; gap: 10px; cursor: pointer; }
.category-choice__name input { width: 17px; height: 17px; flex: 0 0 auto; margin: 0; accent-color: var(--red); }
.category-choice__color { width: 30px; height: 28px; padding: 2px; border: 1px solid var(--line); border-radius: 2px; background: transparent; cursor: pointer; }
.category-options__empty { margin: 0; color: var(--muted); font-size: 13px; }
.category-options__add { justify-self: start; padding: 5px 0; border: 0; background: transparent; color: var(--red); font-size: 12px; font-weight: 700; cursor: pointer; }
.category-dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-cancel, .dialog-save { min-height: 40px; padding: 0 13px; border: 1px solid var(--ink); border-radius: 2px; font-size: 12px; font-weight: 700; cursor: pointer; }
.dialog-cancel { background: transparent; color: var(--ink); }
.dialog-save { background: var(--ink); color: var(--paper); }
.dialog-cancel:hover { background: var(--line); }
.dialog-save:hover { border-color: var(--red); background: var(--red); color: #20211e; }
.add-category-button:focus-visible, .category-tab:focus-visible, .sound-category-button:focus-visible, .dialog-close:focus-visible, .dialog-cancel:focus-visible, .dialog-save:focus-visible { outline: 2px solid #2b6f88; outline-offset: 2px; }
.category-manage-button:focus-visible, .favorite-button:focus-visible, .volume-control input:focus-visible, .category-order-button:focus-visible, .category-delete-button:focus-visible { outline: 2px solid #2b6f88; outline-offset: 2px; }

.empty-state { padding: 34px 0; color: var(--muted); font-size: 14px; }
.footer { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; }
.footer__year { color: var(--red); }
.footer__repo { display: inline-flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; }
.footer__repo:hover { color: var(--ink); }
.footer__repo svg { width: 16px; height: 16px; flex: 0 0 auto; fill: currentColor; }
.footer__repo:focus-visible { outline: 2px solid #2b6f88; outline-offset: 3px; }

@keyframes blink { to { opacity: 0.35; } }
@keyframes thump { to { transform: scale(1.13); } }

@media (max-width: 760px) {
  .app-shell { width: min(100% - 28px, 560px); }
  .topbar { min-height: 58px; }
  .topbar__right { gap: 0; }
  .connection { display: none; }
  .controls { flex-wrap: wrap; align-items: center; row-gap: 4px; }
  .search-box { flex: 1 1 0; }
  .volume-control { order: 3; flex: 1 0 100%; }
  .volume-control input { width: auto; flex: 1; }
  .control-actions { order: 2; }
  .intro { position: relative; min-height: 190px; align-items: flex-end; justify-content: flex-start; padding: 26px 0 22px; }
  .intro__copy { width: 100%; }
  h1 { font-size: 76px; }
  .clip-count { position: absolute; top: 15px; right: 4px; width: 68px; height: 68px; margin: 0; flex-direction: column; gap: 1px; }
  .clip-count__number { font-size: 27px; }
  .clip-count__label { font-size: 6px; line-height: 1.1; text-align: center; }
  .sound-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .category-strip { gap: 5px; }
  .category-tabs { flex: 1; }
  .add-category-button { width: 36px; justify-content: center; padding: 0; }
  .add-category-button span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .sound-button { min-height: 145px; padding: 12px; }
  .sound-button__name { font-size: 27px; }
}

@media (min-width: 391px) and (max-width: 480px) {
  h1 { font-size: 64px; }
}

@media (max-width: 390px) {
  .app-shell { width: calc(100% - 22px); }
  .wordmark { gap: 7px; font-size: 9px; }
  h1 { font-size: 58px; }
  .intro { min-height: 170px; }
  .clip-count { width: 68px; height: 68px; }
  .control-actions { gap: 5px; }
  .utility-button { padding: 0 9px; font-size: 11px; }
  .search-box { gap: 7px; }
  .search-box__key { display: none; }
  .volume-control { gap: 6px; }
  .sound-button { min-height: 132px; padding: 10px; }
  .sound-button__name { font-size: 24px; }
  .category-dialog__surface { padding: 17px; }
}

@media (max-width: 340px) {
  h1 { font-size: 52px; }
}

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