:root {
  --bg: #1d1410;
  --panel: #2a1d17;
  --tile: #3a2820;
  --tile-hi: #4a3328;
  --ink: #f6ead8;
  --muted: #cdb79c;
  --terra: #c8553d;
  --terra-dk: #7a2e1d;
  --majorelle: #3a57d6;
  --mint: #3fae8c;
  --saffron: #f2b134;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.3 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  padding-bottom: calc(56px + env(safe-area-inset-bottom));
  background-image:
    radial-gradient(circle at 20px 20px, rgba(200, 85, 61, .08) 2px, transparent 3px);
  background-size: 40px 40px;
}

button { font: inherit; color: inherit; border: 0; cursor: pointer; }

.top {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) 12px 8px;
  background: linear-gradient(180deg, var(--terra-dk), #5b2316);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

.row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }

h1 { flex: 1; margin: 0; font-size: 20px; letter-spacing: .3px; }
h1 span { color: var(--saffron); font-weight: 600; }

.chip {
  min-width: 48px;
  height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .12);
  font-weight: 700;
}
.chip[aria-pressed="true"] { background: var(--mint); color: #08241b; }

.seg {
  flex: 1;
  display: flex;
  padding: 4px;
  border-radius: 999px;
  background: rgba(0, 0, 0, .3);
}
.seg button {
  flex: 1;
  height: 40px;
  border-radius: 999px;
  font-size: 16px;
  opacity: .75;
}
.seg button[aria-checked="true"] {
  background: var(--ink);
  color: var(--terra-dk);
  opacity: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}

#search {
  width: 100%;
  height: 40px;
  margin-bottom: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(0, 0, 0, .28);
  color: var(--ink);
  font-size: 16px; /* >=16px stops iOS zooming on focus */
}
#search::placeholder { color: var(--muted); }

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -12px;
  padding: 0 12px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .1);
  white-space: nowrap;
  font-size: 15px;
}
.tab[aria-selected="true"] { background: var(--saffron); color: #3a2206; font-weight: 700; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  padding: 12px;
}

.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 6px;
  min-height: 112px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--tile);
  border-bottom: 4px solid var(--terra);
  text-align: left;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: transform .08s ease, background .15s ease;
}
.tile:nth-child(3n+2) { border-bottom-color: var(--majorelle); }
.tile:nth-child(3n) { border-bottom-color: var(--mint); }
.tile:active { transform: scale(.96); background: var(--tile-hi); }
.tile.playing { background: var(--tile-hi); box-shadow: 0 0 0 3px var(--saffron) inset; }
.tile.playing .label::before { content: "🔊 "; }

.label { font-size: 17px; font-weight: 700; }
.say { font-size: 14px; color: var(--saffron); font-style: italic; }
.ar { font-size: 18px; color: var(--muted); text-align: right; }
.info {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--saffron);
  color: #3a2206;
  font: 700 13px/20px Georgia, serif;
  text-align: center;
}

.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.foot {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(29, 20, 16, .94);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(6px);
}
#offline { color: var(--mint); white-space: nowrap; }

dialog#card {
  width: min(92vw, 560px);
  padding: 28px 20px 20px;
  border: 0;
  border-radius: 22px;
  background: var(--ink);
  color: #2a1a12;
  text-align: center;
}
dialog#card::backdrop { background: rgba(0, 0, 0, .7); }
.close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 44px;
  height: 44px;
  background: none;
  color: #2a1a12;
  font-size: 22px;
}
.card-label { margin: 0 0 12px; color: #7a5b45; font-size: 15px; }
.card-ar { margin: 0 0 8px; font-size: clamp(34px, 11vw, 56px); line-height: 1.35; font-weight: 700; }
.card-lat { margin: 0 0 14px; font-style: italic; color: var(--terra-dk); font-size: 18px; }
.card-fr { margin: 0 0 12px; font-size: clamp(22px, 7vw, 32px); font-weight: 600; color: var(--majorelle); }
.card-note { margin: 0 0 14px; font-size: 14px; color: #7a5b45; }
.card-note:empty { display: none; }
.card-play {
  width: 100%;
  height: 56px;
  border-radius: 14px;
  background: var(--terra);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
}
.card-play.playing { background: var(--terra-dk); }
