*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #faf6f0;
  --bg-card: #ffffff;
  --bg-deep: #1a1612;
  --text: #2c2416;
  --text-soft: #8a7d6b;
  --text-muted: #b5a997;
  --accent: #c4944a;
  --accent-glow: #d4a85a;
  --accent-deep: #a07830;
  --green: #3d7a5f;
  --green-soft: #e8f5ee;
  --red: #b84c4c;
  --red-soft: #fce8e8;
  --orange: #d4874a;
  --orange-soft: #fdf0e3;
  --gold: #c4944a;
  --gold-light: #f5ecd7;
  --border: #e8e0d4;
  --shadow-sm: 0 1px 3px rgba(26, 22, 18, 0.06);
  --shadow-md: 0 4px 16px rgba(26, 22, 18, 0.08);
  --shadow-lg: 0 8px 32px rgba(26, 22, 18, 0.12);
  --shadow-glow: 0 0 40px rgba(196, 148, 74, 0.15);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Nunito", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(
      circle at 20% 20%,
      rgba(196, 148, 74, 0.04) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 80%,
      rgba(61, 122, 95, 0.03) 0%,
      transparent 50%
    );
  pointer-events: none;
  z-index: 0;
}

.geo-pattern {
  position: fixed;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M40 0L80 40L40 80L0 40Z' fill='none' stroke='%231a1612' stroke-width='0.5'/%3E%3Cpath d='M40 10L70 40L40 70L10 40Z' fill='none' stroke='%231a1612' stroke-width='0.5'/%3E%3Cpath d='M40 20L60 40L40 60L20 40Z' fill='none' stroke='%231a1612' stroke-width='0.5'/%3E%3C/svg%3E");
  background-size: 80px 80px;
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

/* ====== HEADER ====== */
.header {
  text-align: center;
  margin-bottom: 40px;
  padding: 40px 0 32px;
}
.header-ornament {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 20px;
  color: var(--accent);
}
.ornament-line {
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.ornament-diamond {
  width: 8px;
  height: 8px;
  background: var(--accent);
  transform: rotate(45deg);
  flex-shrink: 0;
}
.header h1 {
  font-family: "Amiri", serif;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
  margin-bottom: 4px;
}
.header .bismillah {
  font-family: "Scheherazade New", serif;
  font-size: 1.6rem;
  color: var(--accent);
  direction: rtl;
  margin-bottom: 12px;
  line-height: 1.6;
}
.header p {
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.7;
  max-width: 480px;
  margin: 0 auto;
}

/* ====== VERSE DISPLAY ====== */
.verse-display {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 28px;
  text-align: center;
  transition: box-shadow 0.3s;
}
.verse-display:hover {
  box-shadow: var(--shadow-sm);
}
.verse-display .verse-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.verse-arabic {
  font-family: "Amiri Quran", "Noto Naskh Arabic", "Scheherazade New", serif;
  font-size: 1.35rem;
  line-height: 2;
  color: var(--text);
  direction: rtl;
  text-align: right;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
  min-height: 50px;
}
.verse-arabic .ayah {
  margin-bottom: 4px;
  transition:
    opacity 0.3s,
    background 0.3s,
    border-radius 0.3s;
}
.bismillah-ayah {
  text-align: center;
  font-size: 1.15em;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(196, 148, 74, 0.15);
}
.ayah-active {
  background: linear-gradient(
    135deg,
    rgba(196, 148, 74, 0.12),
    rgba(212, 168, 90, 0.08)
  );
  border-radius: 8px;
  padding: 4px 8px;
  margin: -4px -8px 8px;
  border-left: 3px solid var(--accent);
  opacity: 1 !important;
}
.verse-highlighting .verse-arabic .ayah:not(.ayah-active) {
  opacity: 0.5;
}
.ayah-active .ayah-num {
  color: var(--accent-deep);
  font-weight: 700;
}
.verse-arabic .ayah-num {
  font-family: "Amiri", serif;
  font-size: 0.95rem;
  color: var(--accent);
  margin-right: 3px;
}
.verse-arabic.loading {
  opacity: 0.4;
}
.verse-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 20px 0;
}

/* ====== SURAH SELECT ====== */
.surah-select-wrap {
  margin-bottom: 32px;
}
.surah-select-wrap label {
  display: block;
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-soft);
  margin-bottom: 8px;
}
.surah-select {
  width: 100%;
  padding: 14px 18px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  font-family: "Nunito", sans-serif;
  font-size: 16px;
  color: var(--text);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L6 6L11 1' stroke='%238a7d6b' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.surah-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196, 148, 74, 0.12);
}

/* ====== CARD ====== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  position: relative;
  overflow: hidden;
  transition:
    box-shadow 0.3s,
    border-color 0.3s;
}
.card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(196, 148, 74, 0.2);
}
.card h3 {
  font-family: "Amiri", serif;
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}
.card .desc {
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.6;
  margin-bottom: 16px;
}

/* ====== REF AUDIO SECTION ====== */
.ref-audio-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 24px;
}
.ref-audio-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ref-audio-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ref-audio-label {
  font-family: "Amiri", serif;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.ref-audio-section .status-msg {
  margin-top: 0;
  flex: 1;
}
.ref-audio-section .audio-player {
  margin-top: 0;
  border-radius: 8px;
}

/* ====== AUDIO PLAYER ====== */
.audio-player {
  width: 100%;
  margin-top: 10px;
  border-radius: 8px;
  display: none;
}
.audio-player.visible {
  display: block;
}

/* ====== STATUS ====== */
.status-msg {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 10px;
  min-height: 20px;
  line-height: 1.5;
}
.status-msg.loading {
  color: var(--accent);
}
.status-msg.success {
  color: var(--green);
}
.status-msg.error {
  color: var(--red);
}

/* ====== RECORDING ====== */
.rec-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}
.rec-timer {
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--red);
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
  min-height: 22px;
  opacity: 0;
  transition: opacity 0.3s;
}
.rec-timer.visible {
  opacity: 1;
}

.btn-record {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: "Nunito", sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
}
.btn-rec-start {
  background: linear-gradient(135deg, #c0392b, #e74c3c);
  color: #fff;
  box-shadow: 0 4px 16px rgba(192, 57, 43, 0.25);
}
.btn-rec-start:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(192, 57, 43, 0.35);
}
.btn-rec-start:active {
  transform: translateY(0);
}
.btn-rec-start.recording {
  animation: rec-pulse 1.2s ease-in-out infinite;
}
.btn-rec-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  animation: none;
}
@keyframes rec-pulse {
  0%,
  100% {
    box-shadow: 0 4px 16px rgba(192, 57, 43, 0.25);
  }
  50% {
    box-shadow: 0 4px 28px rgba(192, 57, 43, 0.5);
  }
}

.btn-rec-stop {
  background: var(--bg);
  color: var(--text-soft);
  border: 1.5px solid var(--border);
}
.btn-rec-stop:hover {
  border-color: var(--text-soft);
  color: var(--text);
}
.btn-rec-stop:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
  display: inline-block;
  animation: blink 1s infinite;
}
@keyframes blink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* Waveform */
.waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 32px;
  margin: 12px 0 4px;
  opacity: 0;
  transition: opacity 0.3s;
}
.waveform.active {
  opacity: 1;
}
.waveform-bar {
  width: 3px;
  height: 4px;
  background: var(--red);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}
.waveform-bar:nth-child(1) {
  animation-delay: 0s;
}
.waveform-bar:nth-child(2) {
  animation-delay: 0.1s;
}
.waveform-bar:nth-child(3) {
  animation-delay: 0.2s;
}
.waveform-bar:nth-child(4) {
  animation-delay: 0.3s;
}
.waveform-bar:nth-child(5) {
  animation-delay: 0.4s;
}
.waveform-bar:nth-child(6) {
  animation-delay: 0.15s;
}
.waveform-bar:nth-child(7) {
  animation-delay: 0.25s;
}
@keyframes wave {
  0%,
  100% {
    height: 4px;
  }
  50% {
    height: 24px;
  }
}

/* ====== COMPARE BUTTON ====== */
.compare-section {
  margin-top: 20px;
  text-align: center;
  margin-bottom: 40px;
}
.btn-compare {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 48px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--accent-deep), var(--accent));
  color: #fff;
  font-family: "Nunito", sans-serif;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(196, 148, 74, 0.3);
  transition: all 0.3s;
}
.btn-compare:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(196, 148, 74, 0.4);
}
.btn-compare:active:not(:disabled) {
  transform: translateY(0);
}
.btn-compare:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
}
.btn-compare .icon {
  font-size: 1.2rem;
}

/* Processing overlay */
.processing-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(250, 246, 240, 0.85);
  backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 16px;
}
.processing-overlay.visible {
  display: flex;
}
.processing-overlay .spinner-lg {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.processing-overlay .process-text {
  font-size: 0.95rem;
  color: var(--text-soft);
  font-weight: 600;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ====== RESULT ====== */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  text-align: center;
  margin-bottom: 32px;
  display: none;
  animation: result-in 0.5s ease-out;
}
.result-card.visible {
  display: block;
}
@keyframes result-in {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.result-score {
  font-family: "Amiri", serif;
  font-size: 4rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
  transition: color 0.3s;
}
.result-score.great {
  color: var(--green);
}
.result-score.good {
  color: var(--accent);
}
.result-score.needs-work {
  color: var(--red);
}

.result-bar-wrap {
  width: 100%;
  max-width: 400px;
  margin: 16px auto 20px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.result-bar {
  height: 100%;
  border-radius: 3px;
  transition:
    width 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94),
    background 0.3s;
  width: 0%;
}
.result-bar.great {
  background: linear-gradient(90deg, var(--green), #52b788);
}
.result-bar.good {
  background: linear-gradient(90deg, var(--accent-deep), var(--accent-glow));
}
.result-bar.needs-work {
  background: linear-gradient(90deg, var(--red), #d46b6b);
}

.result-message {
  font-size: 0.95rem;
  color: var(--text-soft);
  line-height: 1.7;
  max-width: 400px;
  margin: 0 auto 12px;
}
.result-detail {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.result-emoji {
  font-size: 2rem;
  margin-bottom: 8px;
  display: block;
}

/* Level badge */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 16px;
}
.level-badge.pemula {
  background: var(--red-soft);
  color: var(--red);
}
.level-badge.menengah {
  background: var(--orange-soft);
  color: var(--orange);
}
.level-badge.lanjut {
  background: var(--green-soft);
  color: var(--green);
}

/* ====== SEGMENT COMPARISON ====== */
.segment-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
  display: none;
}
.segment-section.visible {
  display: block;
  animation: result-in 0.5s ease-out 0.2s both;
}
.segment-title {
  font-family: "Amiri", serif;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}
.segment-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.segment-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  transition: background 0.2s;
}
.segment-item:hover {
  background: var(--bg);
}
.segment-marker {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.segment-marker.good {
  background: var(--green);
}
.segment-marker.medium {
  background: var(--orange);
}
.segment-marker.bad {
  background: var(--red);
}
.segment-text {
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text);
}
.segment-score {
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 2px;
}
.segment-score.good {
  color: var(--green);
}
.segment-score.medium {
  color: var(--orange);
}
.segment-score.bad {
  color: var(--red);
}

/* ====== HISTORY ====== */
.history-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
}
.history-title {
  font-family: "Amiri", serif;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-clear {
  font-size: 0.75rem;
  color: var(--red);
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-weight: 600;
}
.history-clear:hover {
  text-decoration: underline;
}
.history-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  transition: background 0.2s;
}
.history-item:hover {
  background: var(--bg);
}
.history-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.history-item-surah {
  font-weight: 700;
  color: var(--text);
}
.history-item-date {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.history-item-score {
  font-family: "Amiri", serif;
  font-size: 1.1rem;
  font-weight: 700;
}
.history-item-score.great {
  color: var(--green);
}
.history-item-score.good {
  color: var(--accent);
}
.history-item-score.needs-work {
  color: var(--red);
}

/* ====== TIPS ====== */
.tips-card {
  background: linear-gradient(135deg, var(--gold-light), #fdf8ee);
  border: 1px solid rgba(196, 148, 74, 0.2);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 32px;
}
.tips-card h4 {
  font-family: "Amiri", serif;
  font-size: 1.05rem;
  color: var(--accent-deep);
  margin-bottom: 10px;
}
.tips-card ul {
  list-style: none;
  padding: 0;
}
.tips-card li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-soft);
  line-height: 1.6;
}
.tips-card li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

/* ====== TOAST ====== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s ease-out;
  max-width: 360px;
  cursor: pointer;
}
.toast.success {
  background: var(--green);
}
.toast.error {
  background: var(--red);
}
.toast.warning {
  background: var(--orange);
}
.toast.info {
  background: var(--text-soft);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}
@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ====== FOOTER ====== */
.footer {
  text-align: center;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  margin-top: 40px;
}
.footer p {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.footer a {
  color: var(--accent);
  text-decoration: none;
}
.footer a:hover {
  text-decoration: underline;
}

/* ====== UTILITIES ====== */
.fade-in {
  animation: fadeIn 0.6s ease-out both;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.fade-in-delay-1 {
  animation-delay: 0.1s;
}
.fade-in-delay-2 {
  animation-delay: 0.2s;
}
.fade-in-delay-3 {
  animation-delay: 0.3s;
}
.fade-in-delay-4 {
  animation-delay: 0.4s;
}
.hidden {
  display: none !important;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 640px) {
  .header h1 {
    font-size: 1.8rem;
  }
  .header .bismillah {
    font-size: 1.3rem;
  }
  .result-score {
    font-size: 3rem;
  }
  .verse-arabic {
    font-size: 1.15rem;
  }
  .app {
    padding: 16px 16px 60px;
  }
}
