@charset "utf-8";
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --water-deep:   #0a1a1f;
  --water-mid:    #0f2530;
  --water-light:  #1a3a48;
  --water-glow:   #2a5a6a;
  --water-shine:  rgba(180,220,240,0.12);
  --water-foam:   rgba(200,235,245,0.08);
  --bank-dark:    #05100d;
  --bank-mid:     #0a1f18;
  --bank-light:   #1a3828;
  --moss:         #2a4a30;
  --moss2:        #1a3020;

  /* leaf colours — many tones of autumn/green */
  --leaf-green:   #4a7a3a;
  --leaf-autumn:  #a05020;
  --leaf-gold:    #b87820;
  --leaf-red:     #8a2828;
  --leaf-pale:    #6a7a4a;
  --leaf-dark:    #2a4a20;

  --ink:          #1a1208;
  --paper:        #f0e4c8;
  --cream:        #e8d8b8;

  --font-serif:   'Cormorant Garamond', serif;
  --font-hand:    'Caveat', cursive;
  --font-fa:      'Vazirmatn', sans-serif;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--water-deep);
}

body {
  font-family: var(--font-serif);
  position: relative;
}

/* ─── RIVER CANVAS ─── */
#river {
  position: fixed;
  inset: 0;
  width: 100%; height: 100%;
  z-index: 0;
}

/* ─── LANG TOGGLE ─── */
.lang-btn {
  position: fixed; top: 20px; right: 24px; z-index: 100;
  display: flex; align-items: center; gap: 7px;
  background: rgba(10,26,31,0.7);
  border: 1px solid rgba(180,220,240,0.15);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, background 0.2s;
  font-family: var(--font-hand);
  font-size: 14px;
  color: rgba(180,220,240,0.5);
}
.lang-btn:hover { border-color: rgba(180,220,240,0.35); }
.l-en, .l-fa { transition: color 0.2s; }
.l-en.active, .l-fa.active { color: rgba(180,220,240,0.9); }
.l-sep { color: rgba(180,220,240,0.2); font-size: 11px; }
[dir="rtl"] .lang-btn { right: auto; left: 24px; }

/* ─── HEADER ─── */
.site-header {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 50;
  text-align: center;
  padding: 28px 20px 16px;
  background: linear-gradient(180deg, rgba(5,16,13,0.9) 0%, transparent 100%);
  pointer-events: none;
}
.site-title {
  font-family: var(--font-serif);
  font-style: italic; font-weight: 300;
  font-size: clamp(28px, 5vw, 52px);
  color: rgba(200,230,240,0.7);
  letter-spacing: 2px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.6);
}
.site-sub {
  font-family: var(--font-hand);
  font-size: 15px;
  color: rgba(180,220,240,0.3);
  margin-top: 4px;
  letter-spacing: 0.5px;
}

/* ─── COMPOSE PANEL ─── */
.compose-panel {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 50;
  display: flex; flex-direction: column; align-items: center;
  padding: 0 20px 24px;
  background: linear-gradient(0deg, rgba(5,16,13,0.92) 0%, transparent 100%);
  pointer-events: none;
}
.compose-panel > * { pointer-events: all; }

/* ─── LEAF WRITER ─── */
.leaf-writer {
  width: min(520px, 96vw);
  position: relative;
  filter: drop-shadow(0 8px 32px rgba(0,0,0,0.7));
}

.leaf-shape {
  background: #5a7a40;
  background-image: radial-gradient(ellipse at 30% 30%, #6a9050 0%, #4a6a30 50%, #3a5820 100%);
  border-radius: 4px 60% 4px 60% / 4px 4px 60% 60%;
  padding: 28px 32px 22px;
  position: relative;
  clip-path: polygon(
    3% 0%, 97% 0%,
    100% 3%, 100% 50%,
    98% 70%, 92% 86%, 80% 95%, 65% 100%, 50% 100%,
    35% 100%, 20% 95%, 8% 86%, 2% 70%, 0% 50%, 0% 3%
  );
  transition: background 0.4s;
}

/* veins */
.leaf-vein {
  position: absolute;
  background: rgba(0,0,0,0.15);
  border-radius: 2px;
  pointer-events: none;
}
.main-vein {
  top: 0; bottom: 0;
  left: 50%; transform: translateX(-50%);
  width: 1.5px;
}
.side-vein { width: 1px; height: 35%; }
.sv1 { top: 15%; left: 50%; transform-origin: left top; transform: rotate(-35deg); }
.sv2 { top: 35%; left: 50%; transform-origin: left top; transform: rotate(-28deg); }
.sv3 { top: 15%; right: 50%; transform-origin: right top; transform: rotate(35deg); }
.sv4 { top: 35%; right: 50%; transform-origin: right top; transform: rotate(28deg); }

.leaf-fields {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; gap: 8px;
}

.leaf-to {
  background: transparent; border: none; outline: none;
  font-family: var(--font-hand);
  font-size: 20px;
  color: rgba(240,228,200,0.9);
  border-bottom: 1px solid rgba(240,228,200,0.2);
  padding-bottom: 4px;
  width: 100%;
  transition: border-color 0.2s;
}
.leaf-to::placeholder { color: rgba(240,228,200,0.35); }
.leaf-to:focus { border-bottom-color: rgba(240,228,200,0.5); }

textarea {
  background: transparent; border: none; outline: none; resize: none;
  font-family: var(--font-hand);
  font-size: 18px;
  color: rgba(240,228,200,0.85);
  width: 100%; height: 72px;
  line-height: 1.6;
  background-image: repeating-linear-gradient(
    transparent, transparent calc(1.6em - 1px),
    rgba(0,0,0,0.12) calc(1.6em - 1px), rgba(0,0,0,0.12) 1.6em
  );
  background-size: 100% 1.6em;
}
textarea::placeholder { color: rgba(240,228,200,0.3); font-style: italic; }

.leaf-foot {
  display: flex; align-items: center; gap: 10px; margin-top: 4px;
}
.char-wrap { display: flex; align-items: center; gap: 6px; flex: 1; }
.char-track { flex: 1; height: 3px; background: rgba(0,0,0,0.22); border-radius: 2px; overflow: hidden; }
.char-fill { height: 100%; width: 0%; background: rgba(240,228,200,0.55); transition: width 0.15s ease, background 0.3s; border-radius: 2px; }
.char-fill.warn { background: rgba(180,60,60,0.8); }
.char-count { font-family: var(--font-hand); font-size: 11px; color: rgba(240,228,200,0.4); min-width: 40px; }
.char-count.warn { color: rgba(200,80,80,0.9); }

.color-picker {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  padding: 0 4px;
  flex-wrap: wrap;
}
.color-swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  cursor: pointer;
  border: 1.5px solid rgba(0,0,0,0.35);
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.15), 0 1px 3px rgba(0,0,0,0.4);
  transition: transform 0.15s ease, box-shadow 0.2s, outline-color 0.2s;
  outline: 2px solid transparent;
  outline-offset: 2px;
  padding: 0;
}
.color-swatch:hover { transform: scale(1.12); }
.color-swatch.selected {
  outline-color: rgba(240,228,200,0.7);
  transform: scale(1.1);
}

.release-btn {
  display: flex; align-items: center; gap: 6px;
  background: rgba(0,0,0,0.3); color: rgba(240,228,200,0.85);
  border: 1px solid rgba(240,228,200,0.25);
  border-radius: 3px; padding: 7px 16px;
  font-family: var(--font-hand); font-size: 16px;
  cursor: pointer; transition: background 0.2s, border-color 0.2s, transform 0.15s;
  white-space: nowrap;
}
.release-btn:hover {
  background: rgba(0,0,0,0.5);
  border-color: rgba(240,228,200,0.5);
  transform: translateY(-1px);
}
.release-arrow { transition: transform 0.2s; }
.release-btn:hover .release-arrow { transform: translateX(3px); }

.compose-hint {
  font-family: var(--font-hand); font-size: 13px;
  color: rgba(180,220,240,0.25); margin-top: 10px;
  font-style: italic; letter-spacing: 0.5px;
  text-align: center;
}

/* ─── LEAF DETAIL OVERLAY ─── */
.leaf-detail {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.35s;
}
.leaf-detail.open { opacity: 1; pointer-events: all; }

.leaf-detail-bg {
  position: absolute; inset: 0;
  background: rgba(5,16,13,0.75);
  backdrop-filter: blur(6px);
}

.leaf-detail-card {
  position: relative; z-index: 1;
  width: min(380px, 90vw);
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  animation: leafUp 0.4s cubic-bezier(.22,.68,.36,1.1);
}
@keyframes leafUp {
  from { transform: translateY(30px) rotate(-3deg); opacity: 0; }
  to   { transform: translateY(0)    rotate(0deg);  opacity: 1; }
}

.detail-close {
  position: absolute; top: -36px; right: 0;
  background: transparent; border: none;
  color: rgba(180,220,240,0.4); font-size: 16px;
  cursor: pointer; transition: color 0.2s;
}
.detail-close:hover { color: rgba(180,220,240,0.9); }

.detail-leaf-shape {
  width: 100%;
  background: #5a7a40;
  background-image: radial-gradient(ellipse at 30% 30%, #6a9050 0%, #4a6a30 50%, #3a5820 100%);
  border-radius: 4px 60% 4px 60% / 4px 4px 60% 60%;
  padding: 30px 36px 28px;
  position: relative;
  clip-path: polygon(
    3% 0%, 97% 0%, 100% 3%, 100% 50%,
    98% 70%, 92% 86%, 80% 95%, 65% 100%, 50% 100%,
    35% 100%, 20% 95%, 8% 86%, 2% 70%, 0% 50%, 0% 3%
  );
  filter: drop-shadow(0 12px 40px rgba(0,0,0,0.7));
}

.detail-content {
  position: relative; z-index: 2;
}
.detail-to {
  font-family: var(--font-hand); font-size: 14px;
  color: rgba(240,228,200,0.5); margin-bottom: 8px;
  letter-spacing: 1px;
}
.detail-msg {
  font-family: var(--font-hand); font-size: 22px;
  color: rgba(240,228,200,0.92); line-height: 1.5;
  word-break: break-word;
}
.detail-age {
  margin-top: 18px;
  padding-top: 10px;
  font-family: var(--font-hand); font-size: 13px;
  color: rgba(240,228,200,0.45); font-style: italic;
  letter-spacing: 0.5px;
  position: relative;
}
.detail-age::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 28px; height: 1px;
  background: rgba(240,228,200,0.18);
}

.detail-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.detail-btn {
  padding: 8px 20px; border-radius: 3px;
  font-family: var(--font-hand); font-size: 15px;
  cursor: pointer; transition: all 0.2s;
  border: 1px solid;
}
.release-back {
  background: rgba(180,220,240,0.1);
  border-color: rgba(180,220,240,0.25);
  color: rgba(180,220,240,0.8);
}
.release-back:hover {
  background: rgba(180,220,240,0.2);
  border-color: rgba(180,220,240,0.5);
}
.keep-btn {
  background: rgba(90,122,64,0.4);
  border-color: rgba(90,122,64,0.6);
  color: rgba(240,228,200,0.8);
}
.keep-btn:hover {
  background: rgba(90,122,64,0.6);
}

/* ─── CAUGHT TRAY ─── */
.caught-tray {
  position: fixed; top: 88px; left: 20px; z-index: 60;
  max-width: 200px;
}
.tray-label {
  font-family: var(--font-hand); font-size: 12px;
  color: rgba(180,220,240,0.3); letter-spacing: 1px;
  margin-bottom: 8px;
}
.tray-leaves {
  display: flex; flex-direction: column; gap: 6px;
  max-height: calc(100vh - 200px); overflow-y: auto;
}
.tray-leaf-item {
  background: rgba(90,122,64,0.3);
  border: 1px solid rgba(90,122,64,0.4);
  border-radius: 2px 12px 2px 12px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.2s;
  backdrop-filter: blur(4px);
}
.tray-leaf-item:hover { background: rgba(90,122,64,0.5); }
.tray-leaf-to {
  font-family: var(--font-hand); font-size: 11px;
  color: rgba(240,228,200,0.4); margin-bottom: 2px;
}
.tray-leaf-preview {
  font-family: var(--font-hand); font-size: 13px;
  color: rgba(240,228,200,0.75);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}

/* ─── RTL ─── */
[dir="rtl"] body { font-family: var(--font-fa); }
[dir="rtl"] .leaf-to, [dir="rtl"] textarea { font-family: var(--font-fa); direction: rtl; text-align: right; }
[dir="rtl"] .detail-msg, [dir="rtl"] .detail-to { font-family: var(--font-fa); direction: rtl; text-align: right; }
[dir="rtl"] .tray-leaf-preview, [dir="rtl"] .tray-leaf-to { font-family: var(--font-fa); direction: rtl; }
[dir="rtl"] .leaf-foot { flex-direction: row-reverse; }
[dir="rtl"] .caught-tray { left: auto; right: 20px; }
[dir="rtl"] .release-btn { flex-direction: row-reverse; }
[dir="rtl"] .release-arrow { transform: scaleX(-1); }
[dir="rtl"] .release-btn:hover .release-arrow { transform: scaleX(-1) translateX(3px); }
[dir="rtl"] .site-title, [dir="rtl"] .site-sub,
[dir="rtl"] .compose-hint, [dir="rtl"] .tray-label { font-family: var(--font-fa); }

/* ─── LIKED STATE ─── */
.detail-btn.keep-btn.liked {
  background: rgba(232, 90, 110, 0.5);
  border-color: rgba(255, 130, 150, 0.7);
  color: #ffe0e8;
  text-shadow: 0 0 8px rgba(255, 130, 150, 0.6);
}
.detail-btn.keep-btn.liked:hover {
  background: rgba(232, 90, 110, 0.65);
}

/* ─── SIDE PANEL (search + tabs + list) ─── */
.side-panel {
  position: fixed;
  top: 88px; left: 20px;
  z-index: 60;
  width: 260px;
  max-height: calc(100vh - 220px);
  display: flex; flex-direction: column;
  gap: 10px;
  pointer-events: auto;
}

.search-box {
  display: flex; align-items: center; gap: 8px;
  background: rgba(10,26,31,0.7);
  border: 1px solid rgba(180,220,240,0.18);
  border-radius: 20px;
  padding: 8px 14px;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, background 0.2s;
}
.search-box:focus-within {
  border-color: rgba(180,220,240,0.45);
  background: rgba(10,26,31,0.85);
}
.search-icon {
  color: rgba(180,220,240,0.4);
  font-size: 14px;
  line-height: 1;
}
#searchInput {
  flex: 1;
  background: transparent;
  border: none; outline: none;
  font-family: var(--font-hand);
  font-size: 15px;
  color: rgba(240,228,200,0.9);
  width: 100%;
}
#searchInput::placeholder {
  color: rgba(180,220,240,0.35);
  font-style: italic;
}
.search-clear {
  background: transparent; border: none;
  color: rgba(180,220,240,0.3);
  font-size: 12px; cursor: pointer;
  padding: 0 4px;
  display: none;
  transition: color 0.2s;
}
.search-clear:hover { color: rgba(180,220,240,0.8); }
.search-box.has-text .search-clear { display: inline-block; }

.mode-tabs {
  display: flex;
  background: rgba(10,26,31,0.5);
  border: 1px solid rgba(180,220,240,0.12);
  border-radius: 14px;
  padding: 3px;
  backdrop-filter: blur(8px);
}
.mode-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 6px 8px;
  font-family: var(--font-hand);
  font-size: 13px;
  color: rgba(180,220,240,0.45);
  cursor: pointer;
  border-radius: 10px;
  transition: all 0.2s;
  white-space: nowrap;
}
.mode-tab:hover { color: rgba(180,220,240,0.75); }
.mode-tab.active {
  background: rgba(90,122,64,0.45);
  color: rgba(240,228,200,0.95);
  box-shadow: inset 0 0 0 0.5px rgba(240,228,200,0.2);
}

.side-list {
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto;
  max-height: calc(100vh - 320px);
  padding-right: 2px;
}
.side-list::-webkit-scrollbar { width: 4px; }
.side-list::-webkit-scrollbar-thumb {
  background: rgba(180,220,240,0.15); border-radius: 2px;
}

.side-item {
  background: rgba(90,122,64,0.25);
  border: 1px solid rgba(90,122,64,0.35);
  border-radius: 3px 14px 3px 14px;
  padding: 7px 11px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  backdrop-filter: blur(4px);
  position: relative;
}
.side-item:hover {
  background: rgba(90,122,64,0.45);
  border-color: rgba(90,122,64,0.6);
  transform: translateX(2px);
}
.side-item-to {
  font-family: var(--font-hand);
  font-size: 11px;
  color: rgba(240,228,200,0.45);
  margin-bottom: 1px;
  letter-spacing: 0.3px;
}
.side-item-preview {
  font-family: var(--font-hand);
  font-size: 13px;
  color: rgba(240,228,200,0.85);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.side-item-heart {
  position: absolute;
  top: 6px; right: 8px;
  font-size: 10px;
  color: rgba(232, 130, 150, 0.7);
  display: flex; align-items: center; gap: 2px;
}

.side-empty {
  font-family: var(--font-hand);
  font-size: 13px;
  color: rgba(180,220,240,0.3);
  font-style: italic;
  padding: 20px 8px;
  text-align: center;
  line-height: 1.5;
}

.side-count {
  font-family: var(--font-hand);
  font-size: 11px;
  color: rgba(180,220,240,0.3);
  text-align: center;
  letter-spacing: 1px;
  padding-top: 4px;
  border-top: 1px solid rgba(180,220,240,0.08);
}

/* ─── HIGHLIGHT mode in river — dim other leaves when searching ─── */
#river.searching { transition: filter 0.3s; }

/* ─── RTL ─── */
[dir="rtl"] .side-panel { left: auto; right: 20px; }
[dir="rtl"] #searchInput { direction: rtl; text-align: right; font-family: var(--font-fa); }
[dir="rtl"] .mode-tab,
[dir="rtl"] .side-item-to,
[dir="rtl"] .side-item-preview,
[dir="rtl"] .side-empty,
[dir="rtl"] .side-count { font-family: var(--font-fa); }
[dir="rtl"] .side-item { border-radius: 14px 3px 14px 3px; direction: rtl; }
[dir="rtl"] .side-item-heart { right: auto; left: 8px; }
[dir="rtl"] .side-item:hover { transform: translateX(-2px); }

/* ─── MOBILE: collapse side panel ─── */
@media (max-width: 700px) {
  .side-panel {
    top: 76px;
    left: 12px; right: 12px;
    width: auto;
    max-height: 40vh;
  }
  .side-list { max-height: calc(40vh - 130px); }
}

/* ─── MUSIC BUTTON ─── */
.music-btn {
  position: fixed;
  top: 20px; right: 110px;
  z-index: 100;
  display: flex; align-items: center; gap: 7px;
  background: rgba(10,26,31,0.7);
  border: 1px solid rgba(180,220,240,0.15);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
  font-family: var(--font-hand);
  font-size: 14px;
  color: rgba(180,220,240,0.5);
}
.music-btn:hover {
  border-color: rgba(180,220,240,0.35);
  color: rgba(240,228,200,0.9);
}
.music-btn.playing {
  border-color: rgba(232,200,150,0.5);
  color: rgba(244,216,150,0.95);
  box-shadow: 0 0 14px -2px rgba(232,200,150,0.4);
}
.music-btn.playing .music-icon {
  animation: musicPulse 1.6s ease-in-out infinite;
}
.music-icon {
  font-size: 13px;
  line-height: 1;
}
@keyframes musicPulse {
  0%, 100% { opacity: 0.7; transform: scale(1); }
  50%      { opacity: 1;   transform: scale(1.15); }
}
[dir="rtl"] .music-btn {
  right: auto; left: 110px;
  font-family: var(--font-fa);
}
