:root {
  --black: #0a0505;
  --black-2: #150a0a;
  --dark-red: #3a0a0a;
  --red: #d81e1e;
  --red-2: #e63a2e;
  --white: #f5f3f0;
  --gold: #f5b82e;
  --tile-bg: #f2efe9;
  --tab-inactive: #1c1414;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--black);
  color: var(--white);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 0%, rgba(216,30,30,0.18), transparent 55%),
    radial-gradient(circle at 85% 20%, rgba(216,30,30,0.12), transparent 50%),
    repeating-linear-gradient(135deg, rgba(216,30,30,0.05) 0 2px, transparent 2px 60px),
    var(--black);
}

button { font-family: inherit; }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  flex-shrink: 0;
}

.app-header .logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
}

.title-block {
  display: flex;
  flex-direction: column;
  line-height: 1.05;
}

.title-main {
  font-size: 26px;
  font-weight: 800;
  color: var(--white);
  letter-spacing: 0.5px;
}

.title-sub {
  font-size: 15px;
  font-weight: 800;
  color: var(--red-2);
  letter-spacing: 1px;
}

/* Category tabs */
.category-tabs {
  display: flex;
  gap: 8px;
  padding: 4px 14px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex-shrink: 0;
}
.category-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  min-height: 48px;
  border-radius: 999px;
  border: none;
  background: var(--tab-inactive);
  color: var(--white);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.tab-btn .tab-icon {
  display: inline-flex;
  width: 18px;
  height: 18px;
}
.tab-btn .tab-icon svg { width: 100%; height: 100%; }

.tab-btn.active {
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
  box-shadow: 0 2px 10px rgba(216,30,30,0.45), inset 0 0 0 1px rgba(245,184,46,0.35);
}

/* Sound grid */
.sound-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: min-content;
  gap: 10px;
  padding: 4px 14px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  align-content: start;
}

@media (max-width: 370px) {
  .sound-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 640px) {
  .sound-grid { grid-template-columns: repeat(4, 1fr); max-width: 1100px; margin: 0 auto; width: 100%; }
  .category-tabs { max-width: 1100px; margin: 0 auto; width: 100%; }
  .app-header { max-width: 1100px; margin: 0 auto; width: 100%; }
}

@media (min-width: 900px) {
  .sound-grid { grid-template-columns: repeat(5, 1fr); }
}

@media (min-width: 1200px) {
  .sound-grid { grid-template-columns: repeat(6, 1fr); }
}

.sound-tile {
  background: var(--tile-bg);
  color: var(--black);
  border: none;
  border-radius: 16px;
  padding: 16px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: clamp(104px, 18dvh, 190px);
  cursor: pointer;
  position: relative;
  transition: background 0.1s ease, color 0.1s ease, transform 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

.sound-tile:active {
  transform: scale(0.96);
}

.sound-tile .tile-icon {
  font-size: 28px;
  line-height: 1;
}

.sound-tile .tile-name {
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

.sound-tile.playing {
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
  box-shadow: 0 4px 14px rgba(216,30,30,0.55), inset 0 0 0 2px rgba(245,184,46,0.45);
}

.sound-tile.error::after {
  content: "⚠";
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 12px;
  color: var(--red);
}

.sound-tile.error {
  opacity: 0.55;
}

/* Master controls */
.master-controls {
  flex-shrink: 0;
  background: var(--black-2);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 10px 14px calc(10px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

.volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-icon {
  color: var(--white);
  flex-shrink: 0;
  display: flex;
}

.volume-slider {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #3a2a2a;
  border-radius: 999px;
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--white);
  border: 2px solid var(--red);
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--white);
  border: 2px solid var(--red);
  cursor: pointer;
}

.volume-value {
  font-size: 14px;
  font-weight: 700;
  min-width: 42px;
  text-align: right;
}

.buttons-row {
  display: flex;
  gap: 10px;
}

.btn {
  border: none;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  font-weight: 800;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }

.btn-fade {
  flex: 1;
  background: #221616;
  color: var(--white);
  padding: 12px 8px;
}
.btn-fade .btn-label { font-size: 13px; letter-spacing: 0.5px; }
.btn-fade .btn-sub { font-size: 11px; font-weight: 600; color: #bbb; }

.btn-stop {
  flex: 1.6;
  flex-direction: row;
  background: linear-gradient(180deg, var(--red-2), var(--red));
  color: #fff;
  padding: 14px 8px;
  box-shadow: 0 2px 10px rgba(216,30,30,0.4);
}
.btn-stop .btn-label { font-size: 16px; letter-spacing: 0.5px; }
.btn-stop .icon { display: flex; }
