:root {
  --font-sans: "DM Sans", system-ui, sans-serif;
  --bg: #e4e4e7;
  --bg-elevated: #ffffff;
  --ink: #18181b;
  --ink-muted: #71717a;
  --accent: #2563eb;
  --border: rgba(24, 24, 27, 0.1);
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --thumbs-w: 148px;
  --thumbs-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --thumbs-duration: 0.55s;
  --controls-h: 64px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

.app {
  display: grid;
  grid-template-rows: 1fr auto;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.thumbs {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: var(--thumbs-w);
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(-104%);
  pointer-events: none;
  background:
    linear-gradient(180deg, #fafafa 0%, #f4f4f5 48%, #ececef 100%);
  border-right: 1px solid rgba(24, 24, 27, 0.08);
  box-shadow:
    8px 0 28px rgba(15, 23, 42, 0.12),
    inset -1px 0 0 rgba(255, 255, 255, 0.65);
  transition:
    transform var(--thumbs-duration) var(--thumbs-ease),
    opacity calc(var(--thumbs-duration) * 0.75) var(--thumbs-ease);
  will-change: transform, opacity;
}

.workspace.has-thumbs .thumbs {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.thumbs-head {
  position: relative;
  flex-shrink: 0;
  width: 100%;
  padding: 0.85rem 0.65rem 0.7rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #71717a;
  text-align: center;
  box-sizing: border-box;
}

.thumbs-head::after {
  content: "";
  display: block;
  width: 28px;
  height: 2px;
  margin: 0.55rem auto 0;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #2563eb, transparent);
  opacity: 0.55;
}

.thumbs-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  padding: 0.25rem 0.7rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(37, 99, 235, 0.45) transparent;
  box-sizing: border-box;
}

.thumbs-list::-webkit-scrollbar {
  width: 5px;
}

.thumbs-list::-webkit-scrollbar-track {
  margin: 0.35rem 0;
  background: transparent;
}

.thumbs-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.55), rgba(37, 99, 235, 0.28));
}

.thumbs-list::-webkit-scrollbar-thumb:hover {
  background: rgba(37, 99, 235, 0.75);
}

.thumb {
  appearance: none;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  display: block;
  color: inherit;
  border-radius: 10px;
  transition: transform 0.22s var(--ease);
}

.thumb:focus-visible {
  outline: none;
}

.thumb:focus-visible .thumb-frame {
  border-color: rgba(37, 99, 235, 0.7);
  box-shadow:
    0 0 0 3px rgba(37, 99, 235, 0.22),
    0 10px 24px rgba(15, 23, 42, 0.14);
}

.thumb-frame {
  position: relative;
  display: block;
  border-radius: 9px;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(24, 24, 27, 0.08);
  box-shadow:
    0 1px 2px rgba(24, 24, 27, 0.04),
    0 8px 18px rgba(24, 24, 27, 0.08);
  transition:
    transform 0.22s var(--ease),
    border-color 0.22s var(--ease),
    box-shadow 0.22s var(--ease);
}

.thumb-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(15, 23, 42, 0.35));
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.22s var(--ease);
}

.thumb:hover .thumb-frame {
  transform: translateY(-2px) scale(1.035);
  border-color: rgba(37, 99, 235, 0.35);
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.12),
    0 14px 28px rgba(15, 23, 42, 0.16);
}

.thumb:hover .thumb-frame::after {
  opacity: 0.75;
}

.thumb:hover img {
  transform: scale(1.06);
}

.thumb.is-active .thumb-frame {
  border-color: #2563eb;
  box-shadow:
    0 0 0 2px rgba(37, 99, 235, 0.22),
    0 10px 22px rgba(37, 99, 235, 0.18);
}

.thumb.is-active .thumb-frame::after {
  opacity: 0.7;
  background: linear-gradient(180deg, transparent 50%, rgba(37, 99, 235, 0.45));
}

.thumb.is-active:hover .thumb-frame {
  transform: translateY(-2px) scale(1.02);
}

.thumb img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: linear-gradient(145deg, #f8fafc, #e2e8f0);
  transition: transform 0.35s var(--ease);
  will-change: transform;
}

.thumb-num {
  position: absolute;
  left: 50%;
  bottom: 0.4rem;
  z-index: 1;
  transform: translateX(-50%);
  min-width: 1.55rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: rgba(15, 23, 42, 0.72);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.2);
  font-variant-numeric: tabular-nums;
  text-align: center;
  line-height: 1.25;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}

.thumb:hover .thumb-num {
  background: rgba(37, 99, 235, 0.92);
  transform: translateX(-50%) translateY(-1px);
}

.thumb.is-active .thumb-num {
  color: #fff;
  background: #2563eb;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.35);
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0.35rem 0.5rem;
  overflow: hidden;
  min-height: 0;
  height: 100%;
  background: #e4e4e7;
}

.book-wrap {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  overflow: visible;
}

.book-surface {
  position: relative;
  width: max-content;
  max-width: 100%;
  transform-origin: center center;
  transition: transform 0.25s var(--ease);
}

.book {
  transform-origin: center center;
  box-shadow: var(--shadow);
}

.annotate-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 8;
  pointer-events: none;
  touch-action: none;
}

.stage.is-annotating .annotate-canvas {
  pointer-events: auto;
  cursor: crosshair;
}

.stage.is-annotating[data-annotate-tool="eraser"] .annotate-canvas {
  cursor: cell;
}

.stage.is-annotating[data-annotate-tool="text"] .annotate-canvas {
  cursor: text;
}

.stage.is-annotating .book {
  /* Çizim sırasında sayfa çevirmeyi engelle */
  pointer-events: none;
}

.annotate-text-layer {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
}

.annotate-text-input {
  position: absolute;
  z-index: 10;
  min-width: 8rem;
  max-width: 70%;
  margin: 0;
  padding: 0.2rem 0.35rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: #18181b;
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  outline: none;
  pointer-events: auto;
  resize: none;
  overflow: hidden;
}

.btn-icon.is-active {
  background: rgba(37, 99, 235, 0.9);
  border-color: rgba(147, 197, 253, 0.45);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

/* Öğretmen araç çubuğu */
.annotate-toolbar {
  position: absolute;
  /* Sağda: soldan açılan sayfalar panelinin arkasında kalmasın */
  right: clamp(0.35rem, 1.2vw, 0.85rem);
  top: 0.75rem;
  z-index: 18;
  transform: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem 0.45rem;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 36px rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(14px);
  color: #fff;
  max-height: calc(100% - 1.5rem);
  overflow-y: auto;
  scrollbar-width: thin;
  touch-action: none;
  user-select: none;
}

.annotate-toolbar.is-dragging {
  opacity: 0.92;
  box-shadow: 0 16px 44px rgba(15, 23, 42, 0.4);
  cursor: grabbing;
}

.tool-drag {
  appearance: none;
  display: grid;
  place-items: center;
  width: 100%;
  height: 22px;
  padding: 0;
  margin: 0 0 0.1rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(226, 232, 240, 0.55);
  cursor: grab;
  touch-action: none;
}

.tool-drag:hover {
  color: #e2e8f0;
  background: rgba(255, 255, 255, 0.08);
}

.annotate-toolbar.is-dragging .tool-drag {
  cursor: grabbing;
}

.tool-drag svg {
  display: block;
  pointer-events: none;
}

.tool-btn {
  appearance: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: #e2e8f0;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.tool-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.12);
}

.tool-btn.is-active {
  background: rgba(37, 99, 235, 0.9);
  border-color: rgba(147, 197, 253, 0.45);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.tool-btn svg {
  display: block;
  pointer-events: none;
}

.tool-sep {
  width: 22px;
  height: 1px;
  margin: 0.15rem 0;
  background: rgba(255, 255, 255, 0.14);
}

.tool-colors {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.1rem 0;
}

.color-swatch {
  appearance: none;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: var(--swatch, #fff);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.color-swatch:hover {
  transform: scale(1.12);
}

.color-swatch.is-active {
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.9), 0 0 0 4px var(--swatch);
}

/* Kitap sağı/solu sayfa okları */
.nav-side {
  position: absolute;
  top: 50%;
  z-index: 16;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  padding: 0;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  background: rgba(15, 23, 42, 0.72);
  box-shadow: 0 8px 28px rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(10px);
  transform: translateY(-50%);
  /* left: viewer.js kitabın kenarına göre hesaplar; panel açılışıyla aynı hızda kayar */
  transition: background 0.18s var(--ease), transform 0.18s var(--ease), opacity 0.18s var(--ease),
    left var(--thumbs-duration) var(--thumbs-ease);
}

.nav-side:hover:not(:disabled) {
  background: rgba(15, 23, 42, 0.92);
  transform: translateY(-50%) scale(1.06);
}

.nav-side:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.nav-side--prev {
  left: clamp(0.4rem, 1.5vw, 1.1rem);
}

.nav-side--next {
  right: clamp(0.4rem, 1.5vw, 1.1rem);
}

.nav-side svg {
  display: block;
  pointer-events: none;
}

/* Yakınlaştırıldığında sahne el imleci ile kaydırılabilir */
.stage.is-pannable {
  cursor: grab;
  touch-action: none;
}

.stage.is-panning {
  cursor: grabbing;
}

.stage.is-panning .book-surface {
  transition: none;
}

.book .stf__item,
.book .stf__block {
  background: #fff;
}

.book .page {
  background: #fff;
  overflow: hidden;
}

/* Görseli henüz yüklenmemiş sayfa için hafif iskelet */
.book .page:not(.is-loaded) {
  background: linear-gradient(180deg, #fff, #f4f4f5);
}

/* Görsel inene kadar yükleniyor göstergesi */
.book .page:not(.is-loaded)::before,
.thumb-frame:not(.is-loaded)::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border: 3px solid rgba(37, 99, 235, 0.18);
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: viewer-spin 0.8s linear infinite;
  pointer-events: none;
}

.thumb-frame:not(.is-loaded)::before {
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-width: 2px;
}

@keyframes viewer-spin {
  to {
    transform: rotate(360deg);
  }
}

.book .page img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

.controls {
  position: relative;
  z-index: 25;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  min-height: var(--controls-h);
  width: 100%;
  padding: 0.65rem clamp(0.75rem, 2vw, 1.5rem);
  border-top: 1px solid rgba(255,255,255,.12);
  background: rgba(15,23,42,.94);
  color: #fff;
  box-shadow: 0 -8px 30px rgba(15,23,42,.18);
  backdrop-filter: blur(18px);
}

.controls-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.controls-group--start { justify-self: start; }
.controls-group--center { justify-self: center; }
.controls-group--end { justify-self: end; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  cursor: pointer;
  background: rgba(255,255,255,.08);
  color: #fff;
  transition: transform 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.btn:hover {
  transform: translateY(-1px);
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.22);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-icon {
  width: 42px;
  height: 42px;
  font-size: 1.25rem;
  line-height: 1;
}

.btn-icon svg {
  display: block;
  pointer-events: none;
}

.controls-nav {
  gap: 0.35rem;
  padding: 0.2rem;
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
}

.btn-nav {
  background: rgba(255,255,255,.1);
  border-color: rgba(255,255,255,.14);
}

.btn-nav:hover:not(:disabled) {
  background: rgba(37, 99, 235, 0.85);
  border-color: rgba(147, 197, 253, 0.55);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
}

.btn-nav--first,
.btn-nav--last {
  background: rgba(255,255,255,.07);
}

.btn-reset {
  height: 42px;
  padding: 0 0.85rem;
  font-size: 0.78rem;
  font-weight: 600;
}

.page-indicator {
  margin: 0;
  min-width: 7.5rem;
  padding: 0 0.55rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #e2e8f0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: center;
}

.zoom-label {
  min-width: 3.25rem;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
  font-variant-numeric: tabular-nums;
}

.app:fullscreen .stage,
.app:-webkit-full-screen .stage {
  background-color: var(--bg);
}

@media (max-width: 640px) {
  :root {
    --thumbs-w: 104px;
    --controls-h: auto;
  }

  .stage {
    padding: 0.2rem 0.15rem;
  }

  .nav-side {
    width: 36px;
    height: 36px;
    background: rgba(15, 23, 42, 0.55);
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
  }

  .nav-side svg {
    width: 18px;
    height: 18px;
  }

  .nav-side--prev {
    left: 0.15rem;
  }

  .nav-side--next {
    right: 0.15rem;
  }

  .controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "nav nav nav"
      "start mid end";
    align-items: center;
    gap: 0.4rem 0.35rem;
    min-height: 0;
    padding: 0.45rem 0.55rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
  }

  .controls-group--start {
    grid-area: start;
    justify-self: start;
    gap: 0.35rem;
  }

  .controls-group--center {
    grid-area: nav;
    justify-self: center;
    width: 100%;
    max-width: 22rem;
    justify-content: space-between;
    gap: 0.2rem;
    padding: 0.25rem 0.35rem;
    border-radius: 14px;
  }

  .controls-group--end {
    grid-area: end;
    justify-self: end;
    gap: 0.35rem;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
  }

  .btn-icon svg {
    width: 17px;
    height: 17px;
  }

  .controls-nav .btn-icon {
    width: 38px;
    height: 38px;
  }

  .zoom-label {
    display: none;
  }

  .btn-reset {
    height: 36px;
    padding: 0 0.5rem;
    font-size: 0.68rem;
  }

  .page-indicator {
    flex: 1;
    min-width: 0;
    margin: 0 0.15rem;
    padding: 0 0.2rem;
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
  }

  .annotate-toolbar {
    left: auto;
    right: 0.35rem;
    top: 0.55rem;
    padding: 0.3rem;
    gap: 0.25rem;
    border-radius: 12px;
    max-height: calc(100% - 1.1rem);
  }

  .tool-btn {
    width: 36px;
    height: 36px;
  }

  .tool-btn svg {
    width: 15px;
    height: 15px;
  }

  .tool-drag {
    height: 20px;
  }

  .color-swatch {
    width: 15px;
    height: 15px;
  }

  .thumbs {
    box-shadow: 10px 0 32px rgba(15, 23, 42, 0.22);
  }
}

@media (max-width: 380px) {
  .controls-group--start #btn-zoom-out,
  .controls-group--start #btn-zoom-in {
    display: none;
  }

  .btn-icon {
    width: 38px;
    height: 38px;
  }

  .page-indicator {
    font-size: 0.74rem;
  }
}

