/* Kur'an Rehberi — "Nur" teması
   Tezhipli el yazmaları ve İznik çinilerinden esinlenen lacivert + varak altın paleti.
   Gündüz: sabah ışığında parşömen. Gece: kandil ışığında gece laciverti. */

/* ---------- Yazı tipleri (çevrimdışı, PWA kabuğunda) ---------- */
@font-face {
  font-family: "Marcellus"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/marcellus-normal-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Marcellus"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/marcellus-normal-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Lora"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/lora-normal-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lora"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url(fonts/lora-normal-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Lora"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url(fonts/lora-italic-latin.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2212, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Lora"; font-style: italic; font-weight: 400 700; font-display: swap;
  src: url(fonts/lora-italic-latin-ext.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02D7, U+02DD-02FF, U+1E00-1EFF, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Palet ---------- */
:root {
  --paper: #f6f2e8;          /* parşömen zemin */
  --paper-raised: #fdfbf4;   /* kart / sayfa */
  --paper-deep: #efe9da;     /* alıntı zemini */
  --ink: #262c3f;            /* mavi-siyah mürekkep */
  --muted: #6f7285;
  --lapis: #1e4477;          /* İznik kobaltı */
  --lapis-deep: #12294a;
  --gold: #b28a33;           /* varak altın (süsleme, çizgi) */
  --gold-ink: #7d5f1d;       /* altın, metin için koyultulmuş */
  --gold-soft: rgba(178, 138, 51, .38);
  --turquoise: #257d78;
  --line: #e2dac6;
  --glow: rgba(201, 162, 75, .17);
  --error: #a5473d;
  --font-display: "Marcellus", "Palatino Linotype", Georgia, serif;
  --font-body: "Lora", Georgia, "Times New Roman", serif;
  --star: url("data:image/svg+xml,%3Csvg xmlns%3D'http://www.w3.org/2000/svg' viewBox%3D'0 0 512 512'%3E%3Cpath d%3D'M286.5 142.0A44.5 44.5 0 0 1 339.4 172.6A44.5 44.5 0 0 1 370.0 225.5A44.5 44.5 0 0 1 370.0 286.5A44.5 44.5 0 0 1 339.4 339.4A44.5 44.5 0 0 1 286.5 370.0A44.5 44.5 0 0 1 225.5 370.0A44.5 44.5 0 0 1 172.6 339.4A44.5 44.5 0 0 1 142.0 286.5A44.5 44.5 0 0 1 142.0 225.5A44.5 44.5 0 0 1 172.6 172.6A44.5 44.5 0 0 1 225.5 142.0A44.5 44.5 0 0 1 286.5 142.0Z' fill%3D'none' stroke%3D'%23000' stroke-width%3D'48' stroke-linejoin%3D'round'/%3E%3Ccircle cx%3D'256' cy%3D'256' r%3D'52' fill%3D'%23000'/%3E%3C/svg%3E");
  --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='132' height='132'%3E%3Cg fill='none' stroke='%23a8802f' stroke-opacity='.038'%3E%3Crect x='46' y='46' width='40' height='40'/%3E%3Crect x='46' y='46' width='40' height='40' transform='rotate(45 66 66)'/%3E%3C/g%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0d1526;         /* gece laciverti */
    --paper-raised: #141f36;
    --paper-deep: #0f1930;
    --ink: #e9e3d3;           /* kandil ışığında fildişi */
    --muted: #8f96a8;
    --lapis: #1d3a66;
    --lapis-deep: #0f2242;
    --gold: #d4b06a;
    --gold-ink: #dcbe80;
    --gold-soft: rgba(212, 176, 106, .42);
    --turquoise: #4fb3ac;
    --line: #273450;
    --glow: rgba(212, 176, 106, .12);
    --error: #d98a80;
    --pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='132' height='132'%3E%3Cg fill='none' stroke='%23d4b06a' stroke-opacity='.04'%3E%3Crect x='46' y='46' width='40' height='40'/%3E%3Crect x='46' y='46' width='40' height='40' transform='rotate(45 66 66)'/%3E%3C/g%3E%3C/svg%3E");
  }
}

/* ---------- Zemin ---------- */
* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 1rem;
  background:
    radial-gradient(900px 420px at 50% -160px, var(--glow), transparent 70%),
    var(--pattern),
    var(--paper);
  color: var(--ink);
  display: flex; flex-direction: column;
}
::selection { background: var(--gold-soft); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* Teslim taşı — Bektaşi nişanı, logoyla aynı form; asistanın imzası */
.star {
  display: inline-block; width: 20px; height: 20px; background: var(--gold);
  -webkit-mask: var(--star) center / contain no-repeat;
  mask: var(--star) center / contain no-repeat;
}

/* ---------- Başlık ---------- */
/* padding-top: yerel uygulamada çentik/saat şeridinin altına girmesin (web'de 0) */
header {
  position: sticky; top: 0; z-index: 10; background: transparent;
  padding-top: env(safe-area-inset-top);
}
header::after {
  content: ""; display: block; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft) 18%, var(--gold-soft) 82%, transparent);
}
.header-inner {
  max-width: 860px; margin: 0 auto; padding: 12px 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; }
.brand img { border-radius: 9px; }
#history-btn, #account-btn {
  background: none; border: 1px solid var(--line); border-radius: 12px;
  width: 40px; height: 40px; display: grid; place-items: center;
  color: var(--muted); cursor: pointer; flex-shrink: 0;
  transition: border-color .2s, color .2s;
}
#history-btn:hover, #account-btn:hover { border-color: var(--gold-soft); color: var(--gold-ink); }

/* Hesap menüsü (Firebase kimlik) */
.account { position: relative; flex-shrink: 0; }
#account-menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  min-width: 210px; padding: 10px; display: none;
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 10px 28px rgba(13, 21, 38, .18);
}
#account-menu.open { display: grid; gap: 8px; }
#account-status {
  font-size: .8rem; color: var(--muted); padding: 2px 4px;
  overflow-wrap: anywhere;
}
#account-menu button {
  background: none; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: .85rem; color: var(--ink);
  cursor: pointer; text-align: left; transition: border-color .2s, color .2s;
}
#account-menu button:hover { border-color: var(--gold-soft); color: var(--gold-ink); }
h1 {
  font-family: var(--font-display); font-weight: 400;
  font-size: 1.22rem; letter-spacing: .04em; color: var(--ink);
}
.subtitle { font-size: .74rem; font-style: italic; color: var(--muted); margin-top: 1px; }
#lang {
  background: transparent; color: var(--muted); font: inherit; font-size: .82rem;
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px; cursor: pointer;
}
#lang:hover { border-color: var(--gold-soft); color: var(--ink); }

/* ---------- Sohbet alanı ---------- */
main {
  flex: 1; overflow-y: auto; width: 100%;
  max-width: 860px; margin: 0 auto; padding: 20px 16px 12px;
  scrollbar-width: thin; scrollbar-color: var(--gold-soft) transparent;
}

/* Karşılama: mihrap nişi — kandil ışığı yukarıdan süzülür */
.welcome { padding: clamp(16px, 5vh, 56px) 4px 8px; }
.arch {
  position: relative; max-width: 560px; margin: 0 auto;
  padding: 56px 34px 36px;
  background:
    radial-gradient(130% 85% at 50% 0%, var(--glow) 0%, transparent 62%),
    var(--paper-raised);
  border: 1px solid var(--gold-soft);
  border-radius: 50% 50% 18px 18px / 26% 26% 18px 18px;
}
.arch::before { /* el yazması çift cetvel çizgisi */
  content: ""; position: absolute; inset: 7px; pointer-events: none;
  border: 1px solid var(--line);
  border-radius: inherit;
}
.arch .star {
  display: block; width: 34px; height: 34px; margin: 0 auto 20px;
  filter: drop-shadow(0 0 7px var(--glow));
  animation: breathe 5s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
.arch p { text-align: center; line-height: 1.8; font-size: 1.03rem; }

.examples-label {
  margin: 30px 0 12px; text-align: center;
  font-family: var(--font-display); font-size: .72rem;
  letter-spacing: .22em; text-transform: uppercase; color: var(--gold-ink);
}
.examples { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.examples button {
  max-width: 460px; width: 100%;
  background: var(--paper-raised); border: 1px solid var(--line); color: var(--ink);
  border-radius: 18px 18px 8px 8px;   /* kapı / niş silueti */
  padding: 11px 20px; font: inherit; font-size: .92rem; cursor: pointer;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.examples button:hover {
  border-color: var(--gold); box-shadow: 0 3px 16px var(--glow); transform: translateY(-1px);
}

/* ---------- Mesajlar ---------- */
.msg { margin: 18px 0; display: flex; animation: rise .4s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 85%; padding: 12px 18px; border-radius: 16px;
  line-height: 1.7; font-size: .97rem; overflow-wrap: break-word;
}
.user .bubble {
  background: linear-gradient(160deg, var(--lapis), var(--lapis-deep));
  color: #f1ecdd; border-bottom-right-radius: 4px;
}

/* Asistan cevabı: her biri ۞ nişanıyla açılan bir el yazması sayfası */
.msg.bot { margin-top: 26px; }
.bot .bubble {
  position: relative; width: 100%; max-width: 100%;
  background: var(--paper-raised); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px 22px 16px;
}
.bot .bubble::before { /* nişanın arkasındaki zemin, çerçeve çizgisini keser */
  content: ""; position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  width: 40px; height: 24px; background: var(--paper);
}
.bot .bubble::after {
  content: ""; position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  width: 26px; height: 26px; background: var(--gold);
  -webkit-mask: var(--star) center / contain no-repeat;
  mask: var(--star) center / contain no-repeat;
}
.bot .bubble p { margin: 0 0 .7em; }
.bot .bubble p:last-child { margin-bottom: 0; }
.bubble.thinking { color: var(--muted); font-style: italic; animation: breathe 2.2s ease-in-out infinite; }
.bubble.error { border-color: var(--error); color: var(--error); }

/* Atıflar: ayet etiketi metin içinde altın, yorum dipnotu madalyon rakam */
.cite {
  display: inline; background: none; border: none; padding: 0 2px; margin: 0;
  font: inherit; font-size: .84em; font-weight: 600; color: var(--gold-ink);
  text-decoration: underline dotted var(--gold-soft) 1px; text-underline-offset: 3px;
  cursor: pointer; border-radius: 4px;
}
.cite:hover { background: var(--glow); text-decoration-color: var(--gold); }
.cite-num, .src-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.5em; height: 1.5em; padding: 0 .3em;
  border: 1px solid var(--gold-soft); border-radius: 999px;
  font-size: .7em; font-weight: 600; color: var(--gold-ink);
  text-decoration: none; vertical-align: .25em; line-height: 1;
}
.cite-num { cursor: pointer; background: none; }
.cite-num:hover { border-color: var(--gold); background: var(--glow); }
.src-num { margin-right: 7px; vertical-align: .1em; }

/* Kaynaklar: sayfa altı dipnot bölümü */
.sources { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.sources h4, .readings h4 {
  font-family: var(--font-display); font-weight: 400; font-size: .7rem;
  letter-spacing: .2em; text-transform: uppercase; color: var(--gold-ink);
  margin-bottom: 8px;
}
.source-item { margin: 7px 0; font-size: .89rem; }
.source-item summary {
  cursor: pointer; color: var(--lapis); font-weight: 600; list-style-position: inside;
}
@media (prefers-color-scheme: dark) { .source-item summary { color: var(--turquoise); } }
.source-item summary::marker { color: var(--gold); font-size: .8em; }
.source-item .source-text {
  margin: 8px 0 4px 14px; padding: 10px 14px;
  background: var(--paper-deep); border-left: 2px solid var(--gold);
  border-radius: 0 10px 10px 0;
  white-space: pre-wrap; line-height: 1.75; color: var(--ink);
}
.source-item .source-origin { margin: 2px 0 0 14px; font-size: .76rem; font-style: italic; color: var(--muted); }

/* Okuma önerileri: niş biçimli davet kartları */
.readings { margin-top: 16px; }
.reading-chip {
  display: inline-block; margin: 3px 6px 3px 0; padding: 8px 16px;
  background: none; border: 1px solid var(--gold-soft);
  border-radius: 16px 16px 7px 7px;
  font: inherit; font-size: .86rem; color: var(--ink); cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
.reading-chip:hover { border-color: var(--gold); box-shadow: 0 2px 12px var(--glow); }
.notfound { color: var(--gold-ink); font-style: italic; font-weight: 600; margin-bottom: 8px; }

/* Cevap altı eylemler (paylaş) */
.msg-actions { margin-top: 12px; }
.share-btn {
  display: inline-block; padding: 6px 14px;
  background: none; border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-size: .82rem; color: var(--muted); cursor: pointer;
  transition: border-color .2s, color .2s;
}
.share-btn:hover { border-color: var(--gold-soft); color: var(--gold-ink); }

/* ---------- Soru alanı ---------- */
footer {
  background: linear-gradient(to top, var(--paper) 65%, transparent);
  padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
}
#ask-form { max-width: 860px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
#question {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 22px;
  background: var(--paper-raised); color: var(--ink); padding: 12px 18px;
  font: inherit; font-size: .96rem; line-height: 1.5; max-height: 140px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .04);
  transition: border-color .2s, box-shadow .2s;
}
#question::placeholder { color: var(--muted); font-style: italic; }
#question:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--glow); }
#send {
  background: linear-gradient(160deg, var(--lapis), var(--lapis-deep));
  color: #f1ecdd; border: 1px solid transparent; border-radius: 50%;
  width: 46px; height: 46px; cursor: pointer; flex-shrink: 0;
  display: grid; place-items: center;
  transition: box-shadow .2s, border-color .2s;
}
#send:hover:not(:disabled) { border-color: var(--gold); box-shadow: 0 0 14px var(--glow); }
#send:disabled { opacity: .45; cursor: default; }
.disclaimer {
  max-width: 860px; margin: 8px auto 0; font-size: .68rem; font-style: italic;
  color: var(--muted); text-align: center;
}

/* ---------- Ayet okuma penceresi: mushaf sayfası ---------- */
dialog#reader {
  border: 1px solid var(--gold-soft); border-radius: 18px;
  background: var(--paper-raised); color: var(--ink);
  max-width: 640px; width: 92vw; max-height: 80vh; padding: 0;
  box-shadow: 0 24px 60px rgba(8, 14, 30, .35);
}
dialog#reader::backdrop { background: rgba(9, 14, 26, .55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.reader-head {
  position: sticky; top: 0; background: var(--paper-raised);
  display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 12px;
}
.reader-head::after {
  content: ""; position: absolute; left: 20px; right: 20px; bottom: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft) 20%, var(--gold-soft) 80%, transparent);
}
.reader-head h3 {
  font-family: var(--font-display); font-weight: 400; letter-spacing: .04em;
  color: var(--ink); font-size: 1.1rem;
}
.reader-head button { background: none; border: none; font-size: 1.25rem; cursor: pointer; color: var(--muted); border-radius: 6px; }
.reader-head button:hover { color: var(--gold-ink); }
.reader-body { padding: 14px 22px 22px; overflow-y: auto; scrollbar-width: thin; }
.reader-body p { margin: 12px 0; line-height: 1.85; }
.reader-body .vnum {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7em; height: 1.7em; margin-right: 9px; padding: 0 .3em;
  border: 1px solid var(--gold-soft); border-radius: 999px;
  color: var(--gold-ink); font-size: .72rem; font-weight: 600; line-height: 1;
  vertical-align: .15em;
}

/* ---------- Sohbet geçmişi çekmecesi ---------- */
#drawer-overlay {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(9, 14, 26, .45);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
#drawer-overlay.open { opacity: 1; pointer-events: auto; }
#history-drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 31;
  width: min(320px, 86vw);
  background: var(--paper-raised);
  border-right: 1px solid var(--gold-soft);
  transform: translateX(-102%); transition: transform .28s ease;
  display: flex; flex-direction: column;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 12px 0 40px rgba(8, 14, 30, .18);
}
#history-drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 12px; }
.drawer-head h2 {
  font-family: var(--font-display); font-weight: 400; font-size: .82rem;
  letter-spacing: .18em; text-transform: uppercase; color: var(--gold-ink);
}
.drawer-head::after { content: none; }
#drawer-close {
  background: none; border: none; color: var(--muted); font-size: 1.1rem;
  cursor: pointer; border-radius: 6px; padding: 2px 6px;
}
#drawer-close:hover { color: var(--gold-ink); }
#new-chat {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: none; border: 1px solid var(--gold-soft);
  border-radius: 16px 16px 7px 7px;      /* niş silueti */
  padding: 10px 16px; margin-bottom: 12px;
  font: inherit; font-size: .92rem; color: var(--ink); cursor: pointer;
  transition: border-color .2s, box-shadow .2s;
}
#new-chat:hover { border-color: var(--gold); box-shadow: 0 2px 12px var(--glow); }
#new-chat .star { width: 15px; height: 15px; }
#chat-list { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--gold-soft) transparent; }
.no-history { padding: 14px 6px; font-size: .86rem; font-style: italic; color: var(--muted); text-align: center; }
.chat-item {
  display: flex; align-items: stretch; gap: 4px; margin: 4px 0;
  border: 1px solid transparent; border-radius: 12px;
  transition: border-color .2s, background .2s;
}
.chat-item:hover { border-color: var(--line); background: var(--paper-deep); }
.chat-item.active { border-color: var(--gold-soft); background: var(--paper-deep); }
.chat-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  background: none; border: none; text-align: left; cursor: pointer;
  padding: 9px 4px 9px 12px; font: inherit; color: var(--ink);
}
.chat-title {
  font-size: .89rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-date { font-size: .7rem; color: var(--muted); font-style: italic; }
.chat-del {
  background: none; border: none; color: var(--muted); cursor: pointer;
  padding: 0 10px; border-radius: 10px; font-size: .85rem; flex-shrink: 0;
}
.chat-del:hover { color: var(--error); }

/* Akan cevap: imleç kandili */
.stream-text { white-space: pre-wrap; }
.stream-text::after {
  content: ""; display: inline-block; width: .55em; height: 1em;
  margin-left: 2px; vertical-align: text-bottom;
  background: var(--gold-soft); border-radius: 2px;
  animation: breathe 1.1s ease-in-out infinite;
}

/* ---------- Hareket azaltma ---------- */
@media (prefers-reduced-motion: reduce) {
  .arch .star, .bubble.thinking, .stream-text::after { animation: none; }
  .msg { animation: none; }
  .examples button, .reading-chip, #question, #send { transition: none; }
  #history-drawer, #drawer-overlay { transition: none; }
}

/* ---------- Dar ekranlar ---------- */
@media (max-width: 480px) {
  .arch { padding: 44px 22px 28px; }
  .bubble { max-width: 92%; }
  .bot .bubble { padding: 18px 16px 14px; }
  .subtitle { display: none; }
}
