/* ============ Temel değişkenler ============ */
:root {
  --font-display: 'Fraunces Variable', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Inter Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-read: 'Literata Variable', Georgia, serif;
  --font-hand: 'Caveat', 'Segoe Print', cursive;

  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
}

/* Gece (varsayılan): sıcak, loş bir okuma odası */
:root, :root[data-ui="gece"] {
  color-scheme: dark;
  --bg: #15100c;
  --bg-2: #1d1611;
  --bg-3: #261d16;
  --surface: rgba(255, 238, 214, .045);
  --surface-2: rgba(255, 238, 214, .08);
  --line: rgba(255, 233, 205, .1);
  --line-2: rgba(255, 233, 205, .18);
  --text: #f4eadc;
  --muted: #b3a28e;
  --faint: #7d6d5c;
  --accent: #e8a95e;
  --accent-ink: #2a1a0b;
  --accent-2: #d0764e;
  --good: #8fbf7f;
  --danger: #e2735f;
  --shadow: 0 18px 40px -16px rgba(0, 0, 0, .7);
  --wood-1: #5a3a22;
  --wood-2: #3d2615;
  --wood-edge: #24160c;
  --wall: radial-gradient(1200px 600px at 50% -10%, #2a1e15 0%, transparent 60%), #15100c;
}

/* Gündüz: krem kâğıt ve açık meşe */
:root[data-ui="gunduz"] {
  color-scheme: light;
  --bg: #f4ece0;
  --bg-2: #ece2d3;
  --bg-3: #e3d6c3;
  --surface: rgba(80, 50, 20, .045);
  --surface-2: rgba(80, 50, 20, .08);
  --line: rgba(60, 35, 15, .12);
  --line-2: rgba(60, 35, 15, .2);
  --text: #2b1f15;
  --muted: #6e5b48;
  --faint: #9b8873;
  --accent: #b5652b;
  --accent-ink: #fff8ef;
  --accent-2: #9c4a2c;
  --good: #4f8a3f;
  --danger: #b8432e;
  --shadow: 0 18px 40px -18px rgba(70, 40, 10, .45);
  --wood-1: #c39463;
  --wood-2: #a3764a;
  --wood-edge: #7b5532;
  --wall: radial-gradient(1200px 600px at 50% -10%, #fff7ea 0%, transparent 60%), #f4ece0;
}

/* ============ Sıfırlama ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--wall);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  transition: background-color .4s, color .4s;
}
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ico { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: color-mix(in srgb, var(--accent) 40%, transparent); }

/* ============ Görünüm geçişleri ============ */
#app { min-height: 100vh; }
.view {
  min-height: 100vh;
  transition: opacity .45s var(--ease-out), transform .45s var(--ease-out);
}
.view.entering { opacity: 0; transform: translateY(10px); }
body.with-nav .view { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 24px); }
::view-transition-old(root) { animation: vt-out .25s ease both; }
::view-transition-new(root) { animation: vt-in .4s var(--ease-out) both; }
@keyframes vt-out { to { opacity: 0; } }
@keyframes vt-in { from { opacity: 0; transform: translateY(8px); } }

/* ============ Ana gezinme ============ */
.main-nav { display: none; }
body.with-nav .main-nav {
  display: flex;
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(14px + var(--safe-bottom));
  transform: translateX(-50%);
  gap: 4px;
  padding: 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg-2) 82%, transparent);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: nav-in .6s var(--ease-spring) both;
}
@keyframes nav-in { from { transform: translate(-50%, 30px); opacity: 0; } }
.nav-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 550;
  font-size: 14px;
  transition: background .3s, color .3s;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { background: var(--accent); color: var(--accent-ink); }
@media (max-width: 420px) {
  .nav-tab { padding: 10px 14px; }
  .nav-tab span:last-child { display: none; }
  .nav-tab.active span:last-child { display: inline; }
}

/* ============ Düğmeler ve formlar ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px;
  border-radius: 999px;
  font-weight: 600; font-size: 14.5px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  transition: transform .2s var(--ease-out), background .2s, opacity .2s, box-shadow .2s;
  white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 70%, var(--line-2)); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 8px 24px -10px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn.wide { width: 100%; }
.btn.small { height: 36px; padding: 0 14px; font-size: 13.5px; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text);
  transition: background .2s, transform .2s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.active { color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 550; color: var(--muted); }
.field input, .field textarea, .field select, .input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--line);
  outline: none;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.field textarea { height: auto; min-height: 110px; padding: 12px 16px; resize: vertical; line-height: 1.5; }
.field input:focus, .field textarea:focus, .field select:focus, .input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.form-error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13.5px; font-weight: 550;
  transition: all .2s;
  white-space: nowrap;
}
.chip:hover { color: var(--text); border-color: var(--line-2); }
.chip.active { background: var(--text); color: var(--bg); border-color: transparent; }

.seg { display: inline-flex; padding: 4px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.seg button { height: 32px; padding: 0 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--muted); transition: all .25s; }
.seg button.active { background: var(--text); color: var(--bg); }

.switch { position: relative; width: 48px; height: 28px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line-2); transition: background .25s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text); transition: transform .3s var(--ease-spring); }
.switch input:checked + span { background: var(--accent); border-color: transparent; }
.switch input:checked + span::after { transform: translateX(20px); background: var(--accent-ink); }

/* ============ Bildirimler ============ */
#toasts {
  position: fixed; z-index: 1000;
  top: calc(16px + var(--safe-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  width: min(92vw, 440px);
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--bg-3) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow);
  font-size: 14.5px; font-weight: 500;
  opacity: 0; transform: translateY(-14px) scale(.96);
  transition: opacity .35s var(--ease-out), transform .45s var(--ease-spring);
}
.toast.in { opacity: 1; transform: none; }
.toast-emoji { font-size: 22px; }
.toast.achievement { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }

/* ============ Pencereler ============ */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(8, 5, 3, 0);
  backdrop-filter: blur(0);
  transition: background .35s, backdrop-filter .35s;
}
.sheet-backdrop.in { background: rgba(8, 5, 3, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.sheet {
  width: 100%; max-width: 560px;
  max-height: 88vh; overflow: auto;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 26px 26px 0 0;
  padding: 26px 22px calc(22px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .45s var(--ease-out);
  box-shadow: 0 -20px 60px -20px rgba(0, 0, 0, .6);
}
.sheet-backdrop.in .sheet { transform: none; }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 26px; transform: translateY(30px) scale(.96); opacity: 0; transition: transform .45s var(--ease-spring), opacity .3s; }
  .sheet-backdrop.in .sheet { transform: none; opacity: 1; }
}
.sheet.small { max-width: 420px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.sheet-head h2 { font-size: 24px; }
.dialog h3 { font-size: 21px; margin-bottom: 8px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }

.empty { text-align: center; padding: 80px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty h2 { font-size: 26px; }

.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }
.shake { animation: shake .5s; }

/* Yasal sayfalardaki formlar da kullanır; giriş ekranı: css/auth.css */
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-form .btn { margin-top: 6px; height: 50px; }

/* Hareket azaltma tercihi */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ============ Açılış animasyonu ============ */
.intro {
  position: fixed; inset: 0; z-index: 2000;
  display: grid; place-items: center;
  background: radial-gradient(ellipse at 50% 45%, #2b1d13 0%, #120c08 60%, #070504 100%);
  opacity: 0; transition: opacity .8s ease;
  cursor: pointer; overflow: hidden;
}
.intro.in { opacity: 1; }
.intro.leave { opacity: 0; transition: opacity 1s ease .1s; }
.intro.leave .intro-stage { transform: scale(1.8); opacity: 0; filter: blur(6px); transition: transform 1.1s cubic-bezier(.6,0,.4,1), opacity .9s ease, filter 1s; }
.intro.leave-fast { opacity: 0; transition: opacity .4s ease; }
.intro-light {
  position: absolute; width: 900px; height: 900px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 190, 110, .22), transparent 60%);
  animation: lamp 5s ease-in-out infinite alternate;
}
@keyframes lamp { from { transform: scale(.9); opacity: .7; } to { transform: scale(1.08); opacity: 1; } }
.intro-stage { --w: min(42vw, 280px, 34vh); perspective: 2000px; transition: transform 1.4s var(--ease-out); transform: translateX(calc(var(--w) * -.5)); }
.intro.open .intro-stage { transform: translateX(0); }
.intro-book {
  position: relative; width: var(--w); height: calc(var(--w) * 1.45);
  margin-left: var(--w);
  transform-style: preserve-3d;
  transform: translateY(40px) rotateX(12deg) scale(.85); opacity: 0;
  transition: transform 1.2s var(--ease-out), opacity 1s;
}
.intro.in .intro-book { transform: rotateX(4deg); opacity: 1; }
.intro.open .intro-book { transform: none; }
.intro-page {
  position: absolute; inset: 0;
  background: #f6ecd8;
  border-radius: 0 6px 6px 0;
  box-shadow: inset 14px 0 24px -14px rgba(0,0,0,.35), 0 30px 60px -20px rgba(0,0,0,.8);
  padding: 14% 12%;
  color: #3a2a1c;
}
.intro-note { font-family: var(--font-hand); font-size: calc(var(--w) * .1); line-height: 1.25; white-space: pre-wrap; }
.intro-note::after { content: '|'; animation: blink .8s steps(1) infinite; opacity: .6; }
.intro.signed .intro-note::after { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.intro-sign { position: absolute; right: 14%; bottom: 10%; font-size: calc(var(--w) * .12); color: #c0392b; opacity: 0; transform: scale(0); transition: all .6s var(--ease-spring); }
.intro.signed .intro-sign { opacity: 1; transform: scale(1) rotate(-10deg); }
.intro-cover {
  position: absolute; inset: 0; transform-origin: left center; transform-style: preserve-3d;
  transition: transform 1.5s cubic-bezier(.45,.05,.2,1);
}
.intro.open .intro-cover { transform: rotateY(-178deg); }
.intro-front, .intro-inside { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: 0 6px 6px 0; }
.intro-front {
  background:
    linear-gradient(90deg, rgba(0,0,0,.35), rgba(255,255,255,.08) 3%, transparent 7%),
    radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.08), transparent 60%),
    linear-gradient(160deg, #7a2e22, #4a1912);
  box-shadow: 0 30px 60px -20px rgba(0,0,0,.85), inset 0 0 0 1px rgba(255,255,255,.05);
  display: grid; place-items: center; padding: 10%;
}
.intro-frame {
  width: 100%; height: 100%;
  border: 2px solid rgba(232, 190, 120, .55); outline: 1px solid rgba(232, 190, 120, .3); outline-offset: 5px;
  border-radius: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  color: #e9c487; padding: 10%;
}
.intro-frame h1 { font-size: calc(var(--w) * .13); font-weight: 600; text-shadow: 0 1px 0 rgba(0,0,0,.4); }
.intro-frame h2 { font-size: calc(var(--w) * .1); font-weight: 400; font-style: italic; }
.intro-orn { font-size: calc(var(--w) * .07); opacity: .8; margin: 6px 0; }
.intro-inside {
  transform: rotateY(180deg);
  background: linear-gradient(270deg, rgba(0,0,0,.25), transparent 8%), #efe2c8;
  border-radius: 6px 0 0 6px;
  display: grid; place-items: center;
}
.ex-libris { border: 1px solid rgba(90,60,30,.4); padding: 14px 20px; border-radius: 4px; text-align: center; color: #6b4a2b; display: flex; flex-direction: column; gap: 4px; }
.ex-libris small { letter-spacing: .3em; font-size: 10px; }
.ex-libris b { font-family: var(--font-hand); font-size: calc(var(--w) * .11); font-weight: 600; }
.intro-skip { position: absolute; right: 22px; bottom: calc(22px + var(--safe-bottom)); color: rgba(255,240,220,.55); font-size: 14px; padding: 8px 14px; border-radius: 99px; border: 1px solid rgba(255,240,220,.15); }
