:root {
  --accent: #9b8ae6;
  --accent-soft: #c4b5fd;
  --bg: #0b0a0f;
  --bg-elev: #1a1720;
  --card: #2a2830;
  --text: #f3f0f8;
  --muted: #a8a4b3;
  --night: #0c0a12;
  --deep: #16131c;
  --font: "Nunito Sans", "Segoe UI", sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

[data-theme="sage"] {
  --accent: #81c995;
  --accent-soft: #b7e0c2;
  --night: #0a120e;
  --deep: #122018;
}

[data-theme="rose"] {
  --accent: #e0879b;
  --accent-soft: #f0b8c4;
  --night: #140a10;
  --deep: #22141a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(ellipse at 50% 0%, #1a1528 0%, var(--bg) 55%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; }
button { cursor: pointer; }
.app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
}
.brand { color: var(--accent-soft); font-weight: 800; letter-spacing: 0.02em; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--accent-soft);
  display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem 1.25rem 2rem;
  gap: 1.25rem;
}

.cat-hit {
  width: min(72vw, 280px);
  aspect-ratio: 1;
  border: none;
  background: transparent;
  border-radius: 50%;
  position: relative;
  padding: 0;
}
.cat-hit::before {
  content: "";
  position: absolute;
  inset: -8%;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  animation: ring 3.5s ease-in-out infinite;
}
.cat-hit.playing::before { animation-duration: 2.2s; border-color: color-mix(in srgb, var(--accent) 70%, transparent); }
@keyframes ring {
  0%, 100% { transform: scale(0.94); opacity: 0.4; }
  50% { transform: scale(1.05); opacity: 1; }
}
.cat-hit img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 28px color-mix(in srgb, var(--accent) 55%, transparent));
  transition: transform 0.25s ease;
}
.cat-hit.playing img { transform: scale(1.03); }

.hint { color: var(--muted); text-align: center; font-size: 0.95rem; }
.timer-pill {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  color: var(--accent-soft);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-height: 2rem;
}
.quick-row {
  display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center;
}
.chip {
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
}
.chip.active { background: var(--accent); color: #120f18; border-color: transparent; }

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 40;
}
.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Settings: always inside the viewport, scroll inside the panel */
.sheet {
  position: fixed;
  left: 50%;
  top: 50%;
  right: auto;
  bottom: auto;
  width: min(calc(100vw - 1.25rem), 420px);
  height: min(calc(100svh - 2.5rem), calc(100dvh - 2.5rem), 580px);
  max-height: calc(100svh - 2.5rem);
  transform: translate(-50%, -46%) scale(0.98);
  opacity: 0;
  pointer-events: none;
  background: var(--bg-elev);
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  z-index: 50;
  transition: transform 0.22s ease, opacity 0.22s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.sheet.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.95rem;
  flex: 0 0 auto;
  background: var(--bg-elev);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.sheet-head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--accent-soft);
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0.55rem 0.95rem 1.25rem;
  scrollbar-gutter: stable;
}

@supports not (height: 100svh) {
  .sheet {
    height: min(calc(100vh - 2.5rem), 580px);
    max-height: calc(100vh - 2.5rem);
  }
}

.section { margin: 0.75rem 0 0.95rem; }
.section h3 {
  margin: 0 0 0.5rem; font-size: 0.7rem; letter-spacing: 0.08em;
  color: var(--muted); font-weight: 800;
}
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  background: var(--card); border-radius: 14px; padding: 0.85rem 0.95rem;
  margin-bottom: 0.5rem; border: 1px solid rgba(255,255,255,0.05);
}
.row button.linkish, .linkish {
  background: transparent; border: none; color: var(--accent-soft);
  font-weight: 700; padding: 0;
}
.list-btn {
  width: 100%; text-align: left; background: var(--card); color: var(--text);
  border: 1px solid rgba(255,255,255,0.05); border-radius: 14px;
  padding: 0.85rem 0.95rem; margin-bottom: 0.45rem; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.list-btn.active { outline: 2px solid var(--accent); }

.slider {
  width: 100%; accent-color: var(--accent);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: none; border-radius: 999px; padding: 0.7rem 1.1rem;
  font-weight: 800; background: var(--accent); color: #120f18;
}
.btn.ghost {
  background: rgba(255,255,255,0.06); color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
}
.btn.block { width: 100%; }
.btn.danger { background: #e24b4a; color: white; }
.muted { color: var(--muted); font-size: 0.85rem; }
.stack { display: grid; gap: 0.55rem; }
.field {
  width: 100%; background: #121018; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px; color: var(--text); padding: 0.75rem 0.85rem;
}
.panel {
  display: none; position: fixed; inset: 0; z-index: 60;
  background: var(--bg); max-width: 480px; margin: 0 auto;
  flex-direction: column;
}
.panel.open { display: flex; }
.panel-body { flex: 1; overflow: auto; padding: 1rem 1.1rem 1.5rem; }
.mixer-sliders label {
  display: grid; gap: 0.25rem; margin-bottom: 0.85rem; font-size: 0.82rem; color: var(--muted);
}
.note {
  background: rgba(155,138,230,0.12); border: 1px solid rgba(155,138,230,0.25);
  color: var(--accent-soft); border-radius: 12px; padding: 0.65rem 0.8rem;
  font-size: 0.8rem; margin: 0.35rem 0 0.65rem; line-height: 1.4;
}
.overlay-screen {
  position: fixed; inset: 0; z-index: 80; background: rgba(5,5,8,0.72);
  display: none; align-items: center; justify-content: center; padding: 1rem;
  backdrop-filter: blur(6px);
}
.overlay-screen.open { display: flex; }
.overlay-card {
  width: min(100%, 340px);
  max-height: min(78dvh, 520px);
  background: var(--bg-elev);
  border-radius: 18px;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
}
.overlay-card-head {
  padding: 1.1rem 1.15rem 0.65rem;
  flex-shrink: 0;
}
.overlay-card h1 {
  margin: 0 0 0.35rem;
  color: var(--accent-soft);
  font-size: 1.25rem;
}
.overlay-card .muted { margin: 0; font-size: 0.85rem; }
.overlay-card-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.35rem 1.15rem;
  flex: 1;
  min-height: 0;
}
.overlay-card-foot {
  padding: 0.75rem 1.15rem 1.1rem;
  flex-shrink: 0;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: var(--bg-elev);
}
.lang-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 0.15rem;
}
.lang-item {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid rgba(255,255,255,0.06);
  color: var(--text);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font-weight: 600;
}
.lang-item.active {
  outline: 2px solid var(--accent);
  color: var(--accent-soft);
}
.modal-screen {
  position: fixed; inset: 0; z-index: 90; background: rgba(5,5,8,0.7);
  display: none; align-items: center; justify-content: center; padding: 1rem;
}
.modal-screen.open { display: flex; }
.modal-card {
  width: min(100%, 360px);
  background: var(--bg-elev);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.1);
  padding: 1.15rem;
}
.modal-actions {
  display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.9rem;
}
.sil-preview {
  width: 120px; height: 120px; object-fit: contain; display: block; margin: 0.5rem auto;
  filter: drop-shadow(0 0 16px color-mix(in srgb, var(--accent) 60%, transparent));
}
.hidden-file { display: none; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.stat {
  background: var(--card); border-radius: 14px; padding: 0.85rem; text-align: center;
}
.stat b { display: block; font-size: 1.25rem; color: var(--accent-soft); }
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(1.25rem + var(--safe-b));
  transform: translate(-50%, 140%);
  background: #221e2c;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.7rem 1rem;
  border-radius: 12px;
  z-index: 100;
  transition: transform 0.25s ease, opacity 0.2s ease;
  max-width: min(92vw, 420px);
  text-align: center;
  font-size: 0.9rem;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
a.site-link { color: var(--accent-soft); font-size: 0.85rem; }
