:root {
  --bg: #F6F1E7;
  --surface: #EFE8D9;
  --card: #FBF8F1;
  --text: #1E242B;
  --muted: #5F6872;
  --primary: #2F5249;
  --primary-text: #FBF8F1;
  --brass: #C89B54;
  --border: rgba(30, 36, 43, 0.11);
  --shadow: 0 14px 34px rgba(30, 36, 43, 0.08);
  --cassette-body: #E7DEC9;
  --cassette-border: #CFC3A8;
  --cassette-label-bg: #FBF8F1;
  --reel-bg: #262C33;
  --glow: transparent;
}

body[data-theme="night"] {
  --bg: #16191D;
  --surface: #1D2127;
  --card: #21262D;
  --text: #F2ECE1;
  --muted: #A4ADB8;
  --primary: #E0A458;
  --primary-text: #16191D;
  --brass: #E0A458;
  --border: rgba(242, 236, 225, 0.1);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
  --cassette-body: #23272E;
  --cassette-border: #363C47;
  --cassette-label-bg: #1A1E24;
  --reel-bg: #101216;
  --glow: rgba(224, 164, 88, 0.22);
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
  transition: background-color 0.35s ease, color 0.35s ease;
}

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: radial-gradient(var(--text) 0.7px, transparent 0.7px);
  background-size: 16px 16px;
  z-index: 0;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 18px calc(86px + env(safe-area-inset-bottom));
}

.hidden {
  display: none !important;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: #2F5249;
  color: #C89B54;
  display: grid;
  place-items: center;
  box-shadow: 0 6px 16px rgba(47, 82, 73, 0.22);
}

body[data-theme="night"] .brand-mark {
  background: #232930;
  color: #E0A458;
  box-shadow: 0 0 22px var(--glow);
}

.brand-name {
  margin: 0;
  font-family: 'Amiri', serif;
  font-size: 1.55rem;
  line-height: 1.05;
  font-weight: 700;
}

.brand-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.05rem;
  transition: transform 0.15s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.93);
}

body[data-theme="day"] .theme-icon-sun { display: none; }
body[data-theme="night"] .theme-icon-moon { display: none; }

/* Gift Banner */
.gift-banner {
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 18px;
  background: var(--card);
  border: 1px solid var(--brass);
  box-shadow: var(--shadow);
}

.gift-badge {
  display: inline-block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--brass);
  margin-bottom: 6px;
}

.gift-banner-note {
  margin: 0 0 12px;
  font-size: 0.95rem;
  line-height: 1.6;
}

.gift-banner-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Views */
.views {
  flex: 1;
}

.view {
  display: none;
  animation: fadeUp 0.24s ease;
}

.view.active {
  display: block;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Home */
.greeting-block {
  margin-bottom: 16px;
}

.greeting-eyebrow {
  margin: 0 0 4px;
  font-size: 0.85rem;
  color: var(--brass);
  font-weight: 600;
}

.greeting-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
}

.featured-card {
  position: relative;
  padding: 20px;
  border-radius: 22px;
  background: linear-gradient(135deg, #2F5249 0%, #223D36 100%);
  color: #FBF8F1;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  overflow: hidden;
}

body[data-theme="night"] .featured-card {
  background: linear-gradient(135deg, #242A32 0%, #1B2027 100%);
  border: 1px solid rgba(224, 164, 88, 0.3);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4), 0 0 28px rgba(224, 164, 88, 0.08);
}

.featured-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.featured-pill {
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(200, 155, 84, 0.22);
  color: #F0CFA0;
  font-weight: 600;
}

.tape-num {
  font-size: 0.8rem;
  opacity: 0.7;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.featured-title {
  margin: 0 0 4px;
  font-family: 'Amiri', serif;
  font-size: 1.55rem;
}

.featured-sub {
  margin: 0 0 16px;
  font-size: 0.9rem;
  opacity: 0.88;
}

.featured-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.featured-hint {
  font-size: 0.75rem;
  opacity: 0.78;
}

.primary-pill {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  background: var(--brass);
  color: #16191D;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.primary-pill:active {
  transform: scale(0.96);
}

.ghost-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
}

.section-header h3 {
  margin: 0 0 12px;
  font-size: 0.96rem;
  color: var(--muted);
  font-weight: 600;
}

.moments-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.moment-card {
  text-align: right;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 18px;
  padding: 14px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.moment-card::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: var(--card-accent, var(--brass));
}

.moment-card:active {
  transform: scale(0.97);
}

.moment-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  color: var(--muted);
}

.moment-card-title {
  font-family: 'Amiri', serif;
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1.25;
}

.moment-card-mood {
  font-size: 0.76rem;
  color: var(--muted);
}

/* Player View */
.player-top-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.player-top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn.fav-active {
  color: #C94A4A;
  border-color: rgba(201, 74, 74, 0.35);
}

/* Cassette Deck */
.cassette-shell {
  position: relative;
  border-radius: 22px;
  padding: 16px 16px 12px;
  background: var(--cassette-body);
  border: 1.5px solid var(--cassette-border);
  box-shadow: var(--shadow), 0 0 36px var(--glow);
  margin-bottom: 18px;
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}

.cassette-shell.flipping {
  transform: scale(0.97) rotateX(14deg);
}

.cassette-screws span {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
}

body[data-theme="night"] .cassette-screws span {
  background: rgba(255, 255, 255, 0.16);
}

.cassette-screws span:nth-child(1) { top: 9px; right: 10px; }
.cassette-screws span:nth-child(2) { top: 9px; left: 10px; }
.cassette-screws span:nth-child(3) { bottom: 9px; right: 10px; }
.cassette-screws span:nth-child(4) { bottom: 9px; left: 10px; }

.cassette-label {
  background: var(--cassette-label-bg);
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
  padding: 0 14px 14px;
}

.label-stripe {
  height: 10px;
  margin: 0 -14px 10px;
  background: var(--tape-accent);
  transition: background-color 0.3s ease;
}

.label-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.label-side-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--tape-accent);
  color: #FBF8F1;
}

.label-num {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 600;
}

.label-title-wrap {
  text-align: center;
  margin-bottom: 12px;
}

.label-title {
  margin: 0;
  font-family: 'Amiri', serif;
  font-size: 1.55rem;
  line-height: 1.25;
}

.label-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Reels Window */
.reels-window {
  background: var(--reel-bg);
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.reel {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--brass);
  display: grid;
  place-items: center;
  background: radial-gradient(circle, #181B20 42%, #2B313B 100%);
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.6);
}

.cassette-shell.playing .reel {
  animation: spinReel 2.6s linear infinite;
}

@keyframes spinReel {
  from { transform: rotate(0deg); }
  to { transform: rotate(-360deg); }
}

.reel-hub {
  position: relative;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--brass);
}

.reel-hub span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 2px;
  background: var(--brass);
  transform-origin: center;
}

.reel-hub span:nth-child(1) { transform: translate(-50%, -50%) rotate(0deg); }
.reel-hub span:nth-child(2) { transform: translate(-50%, -50%) rotate(60deg); }
.reel-hub span:nth-child(3) { transform: translate(-50%, -50%) rotate(120deg); }

.tape-bridge {
  flex: 1;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  padding: 0 8px;
}

.tape-ribbon {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(200, 155, 84, 0.35), rgba(200, 155, 84, 0.8), rgba(200, 155, 84, 0.35));
}

.cassette-bottom-trapezoid {
  width: 68%;
  height: 18px;
  margin: 10px auto 0;
  border-radius: 6px 6px 2px 2px;
  background: rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 18px;
}

body[data-theme="night"] .cassette-bottom-trapezoid {
  background: rgba(0, 0, 0, 0.32);
}

.pin {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cassette-border);
}

.pin-sm {
  width: 6px;
  height: 6px;
}

/* Side Switch */
.side-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 5px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.side-tab {
  border: none;
  border-radius: 12px;
  padding: 9px 10px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.side-tab strong {
  font-size: 0.9rem;
}

.side-tab span {
  font-size: 0.72rem;
  opacity: 0.85;
}

.side-tab.active {
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* Reciter Switcher */
.reciter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.reciter-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.reciter-pills {
  display: flex;
  gap: 6px;
}

.reciter-pill {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.reciter-pill.active {
  background: var(--brass);
  color: #16191D;
  border-color: var(--brass);
}

/* Track Info */
.now-playing-info {
  text-align: center;
  margin-bottom: 12px;
}

.track-caption {
  margin: 0 0 3px;
  font-size: 0.96rem;
  font-weight: 700;
}

.track-subcaption {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Seek Bar */
.progress-wrap {
  margin-bottom: 16px;
}

.seek-bar {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
  height: 5px;
}

.time-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 4px;
}

.ayah-counter {
  color: var(--brass);
  font-weight: 600;
}

/* Controls */
.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin-bottom: 16px;
}

.ctrl-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.14s ease;
}

.ctrl-btn:active {
  transform: scale(0.92);
}

.play-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid var(--brass);
  background: var(--primary);
  color: var(--primary-text);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18), 0 0 24px var(--glow);
  transition: transform 0.15s ease;
}

.play-btn:active {
  transform: scale(0.94);
}

.utility-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.chip-btn.active {
  border-color: var(--brass);
  color: var(--text);
}

/* Shelf */
.shelf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.shelf-header h2 {
  margin: 0;
  font-size: 1.35rem;
}

.shelf-filters {
  display: flex;
  gap: 6px;
}

.filter-pill {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

.shelf-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shelf-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.shelf-item:active {
  transform: scale(0.985);
}

.shelf-spine {
  width: 10px;
  height: 46px;
  border-radius: 6px;
  flex-shrink: 0;
}

.shelf-info {
  flex: 1;
  min-width: 0;
}

.shelf-title {
  margin: 0 0 2px;
  font-family: 'Amiri', serif;
  font-size: 1.15rem;
  font-weight: 700;
}

.shelf-sub {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shelf-play-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 100%);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 20;
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 0;
  cursor: pointer;
}

.nav-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.nav-item.active {
  color: var(--primary);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 50;
}

.modal-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.modal-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-desc {
  margin: 0 0 14px;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.6;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.gift-textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.88rem;
  padding: 10px 12px;
  resize: none;
  margin-bottom: 12px;
}

.gift-link-box {
  display: flex;
  gap: 8px;
  align-items: center;
}

.gift-link-input {
  flex: 1;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  padding: 9px 10px;
  font-size: 0.76rem;
  direction: ltr;
}

.copy-status {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--brass);
  min-height: 1.2em;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  background: #1E242B;
  color: #FBF8F1;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  z-index: 60;
}

/* End-of-tape prompt + share */
.end-card { margin: 14px 0 6px; text-align: center; }
.end-card-q { font-size: 1.05rem; font-weight: 600; }
.end-card .gift-banner-actions { justify-content: center; }
.share-wide { display: block; width: 100%; margin-top: 12px; padding: 13px 18px; font-size: 1rem; }
