/* ==========================================================================
   Design System & Base Theme: Sulaymaniyah Nocturne & Kraft Notebook
   ========================================================================== */
:root {
  --bg-dark: #0c0f14;
  --bg-surface: #141923;
  --bg-surface-elevated: #1a2230;

  /* Kraft Paper & Notebook Colors */
  --kraft-base: #caa073;
  --kraft-dark: #b08254;
  --kraft-shadow: #875d34;
  --kraft-text: #3d2314;

  /* Lined Paper */
  --paper-cream: #faf6ee;
  --paper-line: rgba(74, 94, 122, 0.15);
  --paper-margin: rgba(189, 75, 75, 0.35);
  --paper-ink: #1f2733;

  /* Accents */
  --accent-violet: #8b5cf6;
  --accent-amber: #f59e0b;
  --accent-teal: #14b8a6;

  /* Typography */
  --font-arabic-body: 'Noto Naskh Arabic', -apple-system, BlinkMacSystemFont, serif;
  --font-arabic-title: 'Amiri', 'Aref Ruqaa', serif;
  --font-english-display: 'Plus Jakarta Sans', sans-serif;

  --spiral-width: 38px;
  --notebook-radius: 12px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-dark);
  color: #e2e8f0;
  font-family: var(--font-arabic-body);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(139, 92, 246, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 90%, rgba(20, 184, 166, 0.05) 0%, transparent 50%),
    linear-gradient(180deg, #090c10 0%, #0d121a 100%);
  user-select: none;
}

/* ==========================================================================
   Top Floating Navigation & Minimalist Music Player
   ========================================================================== */
.top-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(12, 15, 20, 0.7);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.brand-pill {
  display: flex;
  align-items: center;
  font-family: var(--font-arabic-title);
  font-size: 1.2rem;
  color: #f1f5f9;
  letter-spacing: 0.5px;
}

/* Tiny Music Player Button */
.player-wrapper {
  position: relative;
}

.player-pill {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(26, 34, 48, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 30px;
  cursor: pointer;
  color: #f1f5f9;
  font-family: var(--font-arabic-body);
  font-size: 0.85rem;
  transition: all 0.25s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.player-pill:hover {
  background: rgba(35, 46, 64, 0.95);
  border-color: rgba(139, 92, 246, 0.4);
  transform: translateY(-1px);
}

/* Sound Wave Bars Animation */
.sound-wave {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 14px;
}

.sound-wave span {
  width: 2.5px;
  height: 4px;
  background-color: var(--accent-amber);
  border-radius: 2px;
  transition: height 0.2s ease;
}

.player-pill.playing .sound-wave span {
  animation: wavePulse 1s ease-in-out infinite alternate;
}

.player-pill.playing .sound-wave span:nth-child(1) {
  animation-delay: 0.1s;
}

.player-pill.playing .sound-wave span:nth-child(2) {
  animation-delay: 0.3s;
}

.player-pill.playing .sound-wave span:nth-child(3) {
  animation-delay: 0.2s;
}

.player-pill.playing .sound-wave span:nth-child(4) {
  animation-delay: 0.4s;
}

@keyframes wavePulse {
  0% {
    height: 3px;
  }

  100% {
    height: 13px;
  }
}

.player-label {
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chevron-icon {
  transition: transform 0.3s ease;
}

.player-pill.open .chevron-icon {
  transform: rotate(180deg);
}

/* Utility */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Music Player Popover (Robust Positioning for LTR & RTL)
   ========================================================================== */
.player-popover {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  right: auto;
  width: 320px;
  min-width: 320px;
  background: rgba(18, 23, 33, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.2);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
  z-index: 200;
}

.player-popover.hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px) scale(0.96);
  pointer-events: none;
}

.popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.popover-title {
  font-family: var(--font-arabic-title);
  font-size: 1rem;
  color: #cbd5e1;
}

.icon-btn-sm {
  background: none;
  border: none;
  color: #94a3b8;
  font-size: 1.2rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
}

.now-playing-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.track-info {
  display: flex;
  flex-direction: column;
  text-align: center;
}

.track-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #f8fafc;
}

.track-artist {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 2px;
}

.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 4px;
  direction: ltr;
  /* Universal standard: [|<] Prev on the left, [>|] Next on the right */
}

.ctrl-btn {
  background: none;
  border: none;
  color: #cbd5e1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.ctrl-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.ctrl-btn.active {
  color: var(--accent-violet);
  background: rgba(139, 92, 246, 0.2);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
}

.ctrl-btn.play-btn {
  width: 42px;
  height: 42px;
  background: var(--accent-violet);
  color: #fff;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.ctrl-btn.play-btn:hover {
  background: #7c3aed;
  transform: scale(1.05);
}

/* Scrubber */
.progress-bar-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 14px;
  direction: ltr;
  /* Universal playback timeline: 0:00 on left, fills to right */
}

.time-label {
  font-size: 0.7rem;
  color: #94a3b8;
  font-family: var(--font-english-display);
}

.seek-slider,
.vol-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
}

.seek-slider::-webkit-slider-thumb,
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-amber);
  cursor: pointer;
}

/* Ambient Rain Row */
.ambient-rain-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(139, 92, 246, 0.08);
  border: 1px solid rgba(139, 92, 246, 0.15);
  border-radius: 10px;
  margin-bottom: 14px;
}

.rain-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #e2e8f0;
  flex-shrink: 0;
}

.rain-ctrl {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
  min-width: 0;
  direction: ltr;
}

.vol-slider {
  width: 70px;
  flex: 1;
  max-width: 85px;
}

.rain-toggle-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #94a3b8;
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 0.75rem;
  cursor: pointer;
  font-family: var(--font-arabic-body);
  transition: all 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
}

.rain-toggle-btn.active {
  background: var(--accent-teal);
  color: #042f2e;
  font-weight: 600;
}

/* Track List */
.playlist-header {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-bottom: 6px;
}

.track-list {
  list-style: none;
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 4px;
}

/* Custom Sleek Dark Scrollbar */
.track-list::-webkit-scrollbar {
  width: 5px;
}

.track-list::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
}

.track-list::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.4);
  border-radius: 4px;
}

.track-list::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.7);
}

.track-list li {
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #cbd5e1;
  transition: background 0.15s;
}

.track-list li:hover {
  background: rgba(255, 255, 255, 0.06);
}

.track-list li.active {
  background: rgba(139, 92, 246, 0.2);
  color: #f1f5f9;
  font-weight: 600;
}

/* ==========================================================================
   Main Notebook Stage
   ========================================================================== */
.notebook-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 16px 70px;
  width: 100%;
}

.notebook-container {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 660px;
  max-height: calc(100vh - 160px);
  perspective: 1800px;
  display: flex;
}

/* ==========================================================================
   Realistic Spiral Wire Binding (Twin-Loop Wire Rings on the RIGHT for RTL)
   ========================================================================== */
.spiral-binding {
  position: absolute;
  top: 15px;
  bottom: 15px;
  right: -16px;
  left: auto;
  width: 32px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  pointer-events: none;
}

.wire-ring {
  position: relative;
  width: 34px;
  height: 16px;
  border-radius: 8px;
  background: linear-gradient(180deg, #1f252e 0%, #475569 35%, #1e293b 65%, #0f172a 100%);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.4),
    inset 0 -1px 2px rgba(0, 0, 0, 0.8),
    -2px 2px 4px rgba(0, 0, 0, 0.5);
  transform: rotate(3deg);
}

.wire-ring::before {
  content: '';
  position: absolute;
  left: 3px;
  top: 3px;
  right: 3px;
  height: 2px;
  background: rgba(255, 255, 255, 0.35);
  border-radius: 2px;
}

/* Punched Holes along the right spine */
.hole-punch {
  position: absolute;
  right: 20px;
  left: auto;
  width: 10px;
  height: 12px;
  border-radius: 3px;
  background: #090c10;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.9), 0 0 1px rgba(255, 255, 255, 0.1);
  z-index: 2;
}

/* ==========================================================================
   The 3D Book & Sheets (RTL Spine: transform-origin: right center)
   ========================================================================== */
.book {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  border-radius: var(--notebook-radius);
  box-shadow:
    8px 12px 30px rgba(0, 0, 0, 0.6),
    0 4px 10px rgba(0, 0, 0, 0.4);
}

.sheet {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: right center;
  transform-style: preserve-3d;
  transition: transform 0.75s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.75s ease;
  border-radius: var(--notebook-radius);
  cursor: pointer;
}

.sheet.flipped {
  transform: rotateY(180deg);
  pointer-events: none;
}

/* Page Face (Front & Back) */
.page {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: var(--notebook-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
  box-shadow: inset 10px 0 20px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   Kraft Cardboard Cover (Resembling Packmate Image)
   ========================================================================== */
.cover-page {
  background-color: var(--kraft-base);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(255, 255, 255, 0.15) 0%, transparent 60%),
    linear-gradient(135deg, var(--kraft-base) 0%, var(--kraft-dark) 100%);
  border: 1px solid rgba(135, 93, 52, 0.4);
  box-shadow:
    inset 0 0 40px rgba(100, 60, 20, 0.2),
    inset -18px 0 25px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 40px 30px;
  position: relative;
}

/* Subtle doodles on Kraft cover background */
.cover-texture-overlay {
  position: absolute;
  inset: 0;
  opacity: 0.12;
  background-image:
    radial-gradient(#3d2314 1px, transparent 1px),
    radial-gradient(#3d2314 1px, transparent 1px);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  pointer-events: none;
}

.cover-content {
  position: relative;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  color: var(--kraft-text);
  width: 100%;
}

.cover-badge {
  font-family: var(--font-arabic-title);
  font-size: 0.95rem;
  padding: 4px 16px;
  border: 1.5px dashed var(--kraft-text);
  border-radius: 20px;
  margin-bottom: 24px;
  letter-spacing: 0.5px;
}

.cover-title {
  font-family: 'Arial Black', Impact, sans-serif;
  font-size: 3.2rem;
  line-height: 0.92;
  font-weight: 900;
  color: #2b170c;
  letter-spacing: -0.5px;
  text-transform: uppercase;
  margin-bottom: 18px;
}

.cursive-ideas {
  font-family: 'Brush Script MT', 'Segoe Script', cursive, sans-serif;
  font-size: 3.6rem;
  font-weight: 400;
  color: #3b2010;
  display: inline-block;
  margin: -6px 0;
  text-transform: lowercase;
}

.cover-sub {
  font-family: var(--font-arabic-title);
  font-size: 1.15rem;
  margin-top: 14px;
  color: #4a2d19;
  font-weight: 700;
}

.cover-author {
  font-family: var(--font-arabic-title);
  font-size: 1.15rem;
  margin-top: 24px;
  color: #4a2d19;
  font-weight: 700;
  border-top: 1px solid rgba(61, 35, 20, 0.25);
  padding-top: 10px;
  width: 50%;
  letter-spacing: 0.5px;
}

.cover-hint {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 36px;
  font-size: 0.85rem;
  color: #57361f;
  background: rgba(255, 255, 255, 0.3);
  padding: 6px 18px;
  border-radius: 20px;
  animation: pulseHint 2s infinite ease-in-out;
}

@keyframes pulseHint {

  0%,
  100% {
    opacity: 0.8;
    transform: translateX(0);
  }

  50% {
    opacity: 1;
    transform: translateX(4px);
  }
}

/* ==========================================================================
   Inner Paper Pages (Lined Paper for Arabic Writing)
   ========================================================================== */
.inner-page {
  background-color: var(--paper-cream);
  background-image:
    linear-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 100% 34px;
  background-position: 0 45px;
  border: 1px solid #e2d9c8;
  display: flex;
  flex-direction: column;
  padding: 30px 42px 20px 24px;
  /* space for spiral on the right */
  position: relative;
  box-shadow:
    inset -16px 0 20px rgba(0, 0, 0, 0.08),
    inset 0 0 10px rgba(0, 0, 0, 0.02);
}

/* Vertical Margin Line (Left side for RTL Arabic) */
.inner-page::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 28px;
  right: auto;
  width: 1px;
  background-color: var(--paper-margin);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 38px;
  border-bottom: 2px solid rgba(74, 94, 122, 0.25);
  margin-bottom: 8px;
  padding-bottom: 4px;
}

.page-title-input {
  background: transparent;
  border: none;
  outline: none;
  flex: 1;
  min-width: 0;
  font-family: var(--font-arabic-title);
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
}

.page-title-input::placeholder {
  color: rgba(100, 116, 139, 0.4);
  font-weight: 400;
}

.page-entry-date {
  font-family: var(--font-english-display), monospace;
  font-size: 0.85rem;
  color: #475569;
  letter-spacing: 1px;
  direction: ltr;
  white-space: nowrap;
  margin-right: 12px;
  font-weight: 600;
  flex-shrink: 0;
}

/* Page Editable Writing Area */
.page-body {
  flex: 1;
  width: 100%;
  font-family: var(--font-arabic-body);
  font-size: 1.05rem;
  line-height: 34px;
  /* Matches ruled background */
  color: var(--paper-ink);
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: transparent;
  border: none;
  resize: none;
  cursor: text;
  user-select: text;
}

.page-body::placeholder {
  color: rgba(100, 116, 139, 0.5);
  font-style: italic;
}

.page-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 24px;
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 4px;
}

/* Bottom-Right Subtle Save Confirmation */
.save-indicator {
  font-family: var(--font-arabic-body);
  font-size: 0.75rem;
  color: #059669;
  font-weight: 500;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  user-select: none;
}

.save-indicator.visible {
  opacity: 0.85;
  transform: translateY(0);
}

.page-num {
  font-family: var(--font-arabic-title);
  color: #64748b;
  font-size: 0.85rem;
}

/* ==========================================================================
   Bottom Controls Bar
   ========================================================================== */
.page-controls-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  z-index: 10;
}

.nav-page-btn,
.action-page-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font-arabic-body);
}

.nav-page-btn:hover,
.action-page-btn:hover {
  background: var(--bg-surface-elevated);
  border-color: rgba(255, 255, 255, 0.2);
  color: #fff;
  transform: translateY(-1px);
}

.nav-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.action-page-btn {
  background: rgba(139, 92, 246, 0.15);
  border-color: rgba(139, 92, 246, 0.3);
  color: #c4b5fd;
}

.action-page-btn:hover {
  background: rgba(139, 92, 246, 0.3);
  color: #fff;
}

.page-indicator {
  font-size: 0.85rem;
  color: #94a3b8;
  min-width: 90px;
  text-align: center;
  font-family: var(--font-arabic-title);
}

/* ==========================================================================
   Responsive adjustments for Mobile & Tablets
   ========================================================================== */
@media (max-width: 768px) {
  .player-popover {
    position: fixed;
    top: 68px;
    left: 16px;
    right: 16px;
    width: auto;
    min-width: 0;
    max-width: none;
  }
}

@media (max-width: 520px) {
  .notebook-container {
    height: 580px;
    max-height: calc(100vh - 150px);
  }

  .cover-title {
    font-size: 2.7rem;
  }

  .cursive-ideas {
    font-size: 3rem;
  }

  .inner-page {
    padding: 24px 36px 16px 20px;
  }

  .player-label {
    max-width: 90px;
  }
}