/* ═══════════════════════════════════════════════════════
   حافظه‌ی دوم — A personal notebook, not an AI product.
   Warm ivory paper. Ink-on-page feel. Serif-forward.
   ═══════════════════════════════════════════════════════ */

:root {
  /* Paper palette */
  --paper: #f5f0e6;
  --paper-deep: #ebe2cf;
  --paper-soft: #faf6ec;

  /* Ink */
  --ink: #2a241d;
  --ink-soft: #5c5246;
  --ink-mute: #8a7f72;
  --ink-fade: #b8ad9e;

  /* Accent — a single warm red, like a seal */
  --seal: #a83c2a;
  --seal-deep: #7d2a1c;
  --seal-soft: #d9806f;

  /* Secondary accent — ink wash green */
  --moss: #5a6b47;

  /* Dividers */
  --rule: rgba(42, 36, 29, 0.15);
  --rule-soft: rgba(42, 36, 29, 0.08);

  /* Shadows — soft and warm, not cold */
  --shadow-sm: 0 1px 2px rgba(93, 73, 44, 0.08);
  --shadow-md: 0 4px 12px rgba(93, 73, 44, 0.1), 0 1px 2px rgba(93, 73, 44, 0.06);
  --shadow-lg: 0 12px 32px rgba(93, 73, 44, 0.14), 0 2px 6px rgba(93, 73, 44, 0.08);

  /* Typography */
  --font-display: 'Noto Naskh Arabic', 'Vazirmatn', serif;
  --font-body: 'Vazirmatn', system-ui, sans-serif;

  /* Layout */
  --container: 640px;
  --radius: 14px;
}

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

html, body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.65;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Paper texture — subtle grain overlay that makes the bg feel physical */
.paper-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(168, 60, 42, 0.03) 0%, transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(90, 107, 71, 0.03) 0%, transparent 40%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.15 0 0 0 0 0.12 0 0 0 0 0.08 0 0 0 0.08 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Topbar ──────────────────────────────────────────── */

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(to bottom, var(--paper-soft) 0%, var(--paper) 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand svg { color: var(--seal); }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.nav-link:hover {
  background: var(--paper-soft);
  border-color: var(--rule);
  color: var(--ink);
}

/* ── Stage ──────────────────────────────────────────── */

.stage {
  position: relative;
  z-index: 1;
  flex: 1;
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 32px 20px 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ── Mode switch ────────────────────────────────────── */

.mode-switch {
  display: inline-flex;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 48px;
}

.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 22px;
  border: none;
  background: transparent;
  color: var(--ink-mute);
  font-family: var(--font-body);
  font-size: 14.5px;
  font-weight: 500;
  border-radius: 999px;
  cursor: pointer;
  transition: all 0.25s ease;
}

.mode-icon {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1;
}

.mode-btn:hover { color: var(--ink-soft); }

.mode-btn.active {
  background: var(--ink);
  color: var(--paper-soft);
  box-shadow: var(--shadow-sm);
}

/* ── Recorder ────────────────────────────────────────── */

.recorder {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.recorder-hint {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--ink-soft);
  text-align: center;
  margin-bottom: 48px;
  max-width: 440px;
  line-height: 1.7;
  font-weight: 400;
}

.record-area {
  position: relative;
  width: 240px;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 32px;
}

/* Concentric waves behind button */
.waves {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.waves::before,
.waves::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--seal-soft);
  opacity: 0;
}
.recording .waves::before {
  animation: pulse 2.2s ease-out infinite;
}
.recording .waves::after {
  animation: pulse 2.2s ease-out infinite 1.1s;
}
@keyframes pulse {
  0%   { transform: scale(0.8); opacity: 0.5; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* The big record button */
.record-btn {
  position: relative;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 30% 25%, #fefaf0 0%, var(--paper-soft) 60%, var(--paper-deep) 100%);
  cursor: pointer;
  box-shadow:
    var(--shadow-lg),
    inset 0 1px 2px rgba(255, 255, 255, 0.8),
    inset 0 -3px 8px rgba(168, 60, 42, 0.06);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--seal);
}

.record-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 18px 40px rgba(93, 73, 44, 0.18),
    inset 0 1px 2px rgba(255, 255, 255, 0.8),
    inset 0 -3px 8px rgba(168, 60, 42, 0.08);
}
.record-btn:active { transform: translateY(0); }

.record-icon {
  position: relative;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.record-icon .stop-icon { display: none; }
.recording .record-icon .mic-icon { display: none; }
.recording .record-icon .stop-icon { display: block; }

.recording .record-btn {
  background: radial-gradient(circle at 30% 25%, var(--seal-soft) 0%, var(--seal) 80%);
  color: var(--paper-soft);
  box-shadow:
    0 0 0 8px rgba(168, 60, 42, 0.1),
    0 18px 40px rgba(168, 60, 42, 0.35);
}

.record-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.timer {
  position: absolute;
  bottom: -36px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 500;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
}
.recording .timer { color: var(--seal); }

.record-controls {
  margin-top: 24px;
}

/* ── Text input (alternative to voice) ──────────── */

.text-divider {
  width: 100%;
  max-width: 420px;
  margin: 36px auto 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink-fade);
  font-family: var(--font-display);
  font-size: 13px;
}
.text-divider::before,
.text-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to left, transparent, var(--rule) 30%, var(--rule) 70%, transparent);
}
.text-divider span {
  padding: 0 4px;
  font-style: italic;
}

.text-input-form {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: 14px;
  padding: 8px 10px 8px 8px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-input-form:focus-within {
  border-color: var(--ink-mute);
  box-shadow: var(--shadow-md);
}

.text-input-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  color: var(--ink);
  padding: 8px 10px;
  max-height: 180px;
  min-height: 24px;
  overflow-y: auto;
}

.text-input-form textarea::placeholder {
  color: var(--ink-fade);
  font-style: italic;
}

.send-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  align-self: flex-end;
}
.send-btn:hover:not(:disabled) {
  background: var(--seal);
  transform: translateX(-2px);
}
.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Toggle ──────────────────────────────────────────── */

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }

.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  background: var(--paper-deep);
  border: 1px solid var(--rule);
  border-radius: 999px;
  transition: background 0.2s ease;
}
.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  background: var(--paper-soft);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, background 0.2s ease;
}
.toggle input:checked ~ .toggle-track {
  background: var(--ink);
}
.toggle input:checked ~ .toggle-track::after {
  transform: translateX(-16px);
  background: var(--seal-soft);
}
.toggle-label {
  font-size: 13.5px;
  color: var(--ink-soft);
}

/* ── Panel (result display) ──────────────────────────── */

.panel {
  width: 100%;
  margin-top: 56px;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.panel-inner {
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 28px 26px;
  box-shadow: var(--shadow-md);
  position: relative;
}

.panel-inner::before {
  content: '';
  position: absolute;
  top: 0;
  right: 24px;
  width: 2px;
  height: 40px;
  background: var(--seal);
  border-radius: 0 0 2px 2px;
}

.panel-label {
  font-family: var(--font-display);
  font-size: 11.5px;
  letter-spacing: 0.14em;
  color: var(--ink-mute);
  text-transform: uppercase;
  margin-bottom: 10px;
  display: block;
}

.panel h3 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
  line-height: 1.5;
}

.panel p {
  color: var(--ink-soft);
  line-height: 1.8;
  font-size: 15.5px;
}

.panel .transcript {
  margin-top: 16px;
  padding: 14px 16px;
  background: rgba(235, 226, 207, 0.4);
  border-right: 2px solid var(--rule);
  border-radius: 6px;
  font-size: 14.5px;
  color: var(--ink-soft);
  line-height: 1.85;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 13px;
  color: var(--ink-soft);
}

.chip.type { background: var(--seal); color: var(--paper-soft); border-color: var(--seal); }
.chip.person { color: var(--moss); border-color: rgba(90, 107, 71, 0.3); }

/* Sources list */
.sources {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--rule);
}
.sources .panel-label { margin-bottom: 8px; }
.source-item {
  font-size: 13.5px;
  color: var(--ink-mute);
  padding: 6px 0;
  line-height: 1.5;
}
.source-item strong {
  color: var(--ink-soft);
  font-weight: 500;
}

/* Playback bar */
.playback {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 10px;
}
.play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--ink);
  color: var(--paper-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.play-btn:hover { background: var(--seal); }
.playback-label {
  font-size: 13px;
  color: var(--ink-soft);
}

/* ── Status states ──────────────────────────────────── */

.panel.processing .panel-inner::before { background: var(--moss); }
.panel.error .panel-inner::before { background: #c44; }

.loading-dots {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.loading-dots span {
  width: 6px;
  height: 6px;
  background: var(--ink-mute);
  border-radius: 50%;
  animation: bounce 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40%           { transform: scale(1);   opacity: 1;   }
}

/* ── Footer ─────────────────────────────────────────── */

.footer {
  position: relative;
  z-index: 1;
  padding: 24px 20px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--ink-fade);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════════
   REVIEW PAGE
   ═══════════════════════════════════════════════════════ */

.review-stage { align-items: stretch; padding-top: 40px; }

.page-title {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}
.page-title::after {
  content: '';
  display: block;
  width: 32px;
  height: 3px;
  background: var(--seal);
  margin-top: 10px;
  border-radius: 2px;
}

.page-sub {
  color: var(--ink-mute);
  font-size: 15px;
  margin-bottom: 32px;
}

.memories {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.memory-card {
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  position: relative;
  transition: all 0.2s ease;
}

.memory-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: rgba(42, 36, 29, 0.2);
}

.memory-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 10px;
}

.memory-date {
  font-family: var(--font-display);
  font-size: 12.5px;
  color: var(--ink-mute);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.memory-summary {
  font-family: var(--font-display);
  font-size: 16.5px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.55;
  flex: 1;
}

.memory-text {
  color: var(--ink-soft);
  font-size: 14.5px;
  line-height: 1.75;
  margin-top: 6px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.memory-card.expanded .memory-text {
  -webkit-line-clamp: unset;
  overflow: visible;
}

.memory-foot {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.memory-del {
  margin-right: auto;
  border: none;
  background: transparent;
  color: var(--ink-fade);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12.5px;
  transition: all 0.2s ease;
}
.memory-del:hover { color: var(--seal); background: rgba(168, 60, 42, 0.05); }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-mute);
}
.empty p { margin-bottom: 20px; font-size: 16px; }
.btn-primary {
  display: inline-block;
  padding: 11px 24px;
  background: var(--ink);
  color: var(--paper-soft);
  text-decoration: none;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}
.btn-primary:hover { background: var(--seal); transform: translateY(-1px); }

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 520px) {
  .stage { padding: 24px 16px 100px; }
  .recorder-hint { font-size: 17px; margin-bottom: 36px; }
  .record-area { width: 200px; height: 200px; }
  .record-btn { width: 120px; height: 120px; }
  .record-icon { width: 38px; height: 38px; }
  .page-title { font-size: 30px; }
  .mode-switch { margin-bottom: 36px; }
}

/* Prevent text selection on buttons */
button { user-select: none; -webkit-user-select: none; }

/* ═══════════════════════════════════════════════════════
   این CSS رو به آخر فایل styles.css اضافه کن
   ═══════════════════════════════════════════════════════ */

/* Edit hint - small text under each card */
.edit-hint {
  position: absolute;
  bottom: 6px;
  left: 14px;
  font-size: 11px;
  color: var(--ink-fade);
  opacity: 0;
  transition: opacity 0.2s ease;
  font-style: italic;
  pointer-events: none;
}

.memory-card {
  position: relative;
}

.memory-card:hover .edit-hint {
  opacity: 1;
}

.memory-card.editing .edit-hint {
  display: none;
}

/* Editing state */
.memory-card.editing {
  border-color: var(--seal);
  box-shadow: 0 4px 16px rgba(168, 60, 42, 0.12);
}

.memory-edit-textarea {
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.8;
  color: var(--ink);
  resize: none;
  outline: none;
  min-height: 80px;
  transition: border-color 0.2s ease;
}

.memory-edit-textarea:focus {
  border-color: var(--ink-mute);
  background: var(--paper-soft);
}

.edit-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-save,
.btn-cancel {
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-save {
  background: var(--ink);
  color: var(--paper-soft);
}
.btn-save:hover {
  background: var(--seal);
}

.btn-cancel {
  background: transparent;
  color: var(--ink-mute);
  border: 1px solid var(--rule);
}
.btn-cancel:hover {
  color: var(--ink);
  background: var(--paper-soft);
}

.edit-tip {
  font-size: 12px;
  color: var(--ink-fade);
  font-style: italic;
  margin-right: auto;
}

/* Edit button in view mode */
.memory-edit {
  border: none;
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: var(--font-body);
  transition: all 0.2s ease;
  margin-right: auto;
}
.memory-edit:hover {
  color: var(--moss);
  background: rgba(90, 107, 71, 0.06);
}

/* Fix delete button - make sure it stays on the right */
.memory-card .memory-foot .memory-del {
  margin-right: 0;
}
.memory-card .memory-foot .memory-edit {
  margin-right: auto;
}

/* On mobile, hide the hint permanently */
@media (max-width: 520px) {
  .edit-hint { display: none; }
}