:root {
  --bg-main: #0b0f19;
  --bg-panel: #151d30;
  --bg-hover: #1f2b48;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --accent: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #273553;
  --toolbar-bg: rgba(21, 29, 48, 0.95);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* TOP STATUS BAR */
.top-bar {
  min-height: 56px;
  flex-shrink: 0;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #fff;
}

.brand-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background-color: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.center-section {
  display: flex;
  align-items: center;
  gap: 16px;
}

.pin-display {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #0f172a;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.pin-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.pin-code {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: #38bdf8;
  font-family: monospace;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
  background-color: rgba(245, 158, 11, 0.15);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
  transition: all 0.3s ease;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.connection-status.connected {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--accent);
  border-color: rgba(16, 185, 129, 0.3);
}

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

.btn-icon {
  background: var(--bg-hover);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: #283758;
  border-color: #3b82f6;
}

/* WORKSPACE & CANVAS AREA */
.board-viewport {
  flex: 1;
  position: relative;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #131b2e 0%, #090d16 100%);
}

.canvas-container-wrapper {
  position: relative;
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.8);
  border-radius: 4px;
  background-color: #ffffff;
  transform-origin: center center;
  transition: transform 0.1s ease-out;
}

#pdf-bg-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

/* Fabric.js katmanı: çizim yüzeyi her zaman en üstte olmalı */
.canvas-container {
  position: relative;
  z-index: 3;
}

#fabric-canvas {
  position: absolute;
  top: 0;
  left: 0;
}

#image-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  display: none;
}

#video-layer {
  position: absolute;
  top: 0;
  left: 0;
  max-width: 100%;
  max-height: 100%;
  z-index: 1;
  display: none;
  background: #000000;
  border-radius: 4px;
}

#unsupported-panel {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  color: #0f172a;
  background: #f8fafc;
}

#unsupported-panel strong {
  font-size: 1.15rem;
  word-break: break-word;
}

#unsupported-panel span {
  color: #475569;
}

#unsupported-panel a {
  color: #2563eb;
  font-weight: 600;
  text-decoration: underline;
}

#unsupported-panel button {
  background: var(--primary);
  color: #ffffff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

#unsupported-panel button:hover {
  background: var(--primary-hover);
}

/* FLOATING WHITEBOARD TOOLBAR */
.floating-toolbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toolbar-divider {
  width: 1px;
  height: 32px;
  background-color: var(--border-color);
  margin: 0 4px;
}

.tool-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.15s ease;
  position: relative;
}

.tool-btn:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.tool-btn.active {
  background-color: var(--primary);
  color: #fff;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.5);
  border-color: #60a5fa;
}

.tool-btn svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
}

/* COLOR PALETTE POPUP */
.color-picker-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 4px;
}

.color-dot {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.color-dot:hover {
  transform: scale(1.15);
}

.color-dot.active {
  border-color: #fff;
  transform: scale(1.2);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.stroke-width-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

/* PAGE NAVIGATION PILL */
.page-nav-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.6);
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.page-btn {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid transparent;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.page-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.page-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* INITIAL WELCOME & QR OVERLAY */
.welcome-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.3s ease;
}

.welcome-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}

.canvas-container,
#fabric-canvas,
.canvas-container-wrapper {
  touch-action: none !important;
}

.qr-card {
  background: #1e293b;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px;
  max-width: 520px;
  width: 90%;
  text-align: center;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.qr-card-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
}

.qr-card-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.qr-box {
  background: #ffffff;
  padding: 16px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  width: 250px;
  height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-img {
  width: 100%;
  height: 100%;
  display: block;
}

/* QR kütüphanesi yüklenemezse gösterilen yedek bağlantı paneli */
.qr-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  overflow: hidden;
  color: #0f172a;
}

.qr-fallback-pin {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  font-variant-numeric: tabular-nums lining-nums;
  color: #1d4ed8;
}

.qr-fallback-text {
  font-size: 0.78rem;
  line-height: 1.35;
  color: #475569;
}

.qr-fallback-link {
  font-size: 0.7rem;
  line-height: 1.3;
  color: #1d4ed8;
  text-decoration: underline;
  word-break: break-all;
  max-height: 4em;
  overflow: hidden;
}

.pin-highlight {
  background: rgba(59, 130, 246, 0.15);
  border: 1px dashed var(--primary);
  border-radius: 12px;
  padding: 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pin-highlight span {
  font-size: 0.8rem;
  color: #93c5fd;
  text-transform: uppercase;
  font-weight: 600;
}

.pin-highlight strong {
  font-size: 2rem;
  letter-spacing: 0.2em;
  color: #fff;
  font-family: monospace;
}

.dropzone-hint {
  font-size: 0.85rem;
  color: #64748b;
}

/* LIVE CAMERA TEPEGÖZ OVERLAY */
.camera-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 40;
  display: none;
  flex-direction: column;
}

.camera-overlay.active {
  display: flex;
}

.camera-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-controls {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  z-index: 45;
}

/* NOTIFICATION TOAST */
.toast-msg {
  position: fixed;
  top: 70px;
  right: 24px;
  background: #1e293b;
  border: 1px solid var(--primary);
  padding: 12px 20px;
  border-radius: 10px;
  color: #fff;
  font-size: 0.95rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  transform: translateX(120%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 48px);
  overflow-wrap: anywhere;
}

.toast-msg.show {
  transform: translateX(0);
}

[hidden], .pin-display, .pin-highlight, .brand-badge { display: none !important; }
body.pairing .top-bar, body.pairing .floating-toolbar { display: none; }
body.pairing .canvas-container-wrapper { visibility: hidden; }
.qr-card { background: transparent; border: 0; box-shadow: none; }
.qr-box { width: min(340px, 70vw, 65dvh); height: min(340px, 70vw, 65dvh); border-radius: 12px; }
.qr-card-subtitle { color: #e2e8f0; font-size: clamp(1rem, 2vw, 1.3rem); }
#save-status { font-size: .75rem; color: var(--text-muted); max-width: 180px; }
.floating-toolbar { max-width: calc(100vw - 24px); width: max-content; flex-wrap: wrap; justify-content: center; bottom: 12px; padding: 8px; gap: 6px; }
.toolbar-group { flex-shrink: 0; }
.color-dot { border: 3px solid #64748b; }
.color-dot.active { transform: none; outline: 2px solid var(--primary); outline-offset: 2px; }
.stroke-control { display: flex; flex-direction: column; gap: 4px; font-size: .75rem; color: var(--text-muted); }
#stroke-width { width: 100px; min-height: 32px; accent-color: var(--primary); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid #93c5fd; outline-offset: 3px; }
@media (max-width: 1100px) {
  .toolbar-divider { display: none; }
  .floating-toolbar { gap: 10px; }
}
@media (max-width: 700px) {
  .top-bar { flex-wrap: wrap; gap: 8px; padding: 8px; }
  .brand-title { font-size: 1rem; }
  .brand-logo { display: none; }
  .center-section { order: 3; width: 100%; }
  .connection-status { font-size: .75rem; padding: 4px 8px; }
  .btn-icon { min-height: 44px; }
  .color-picker-wrap { flex-wrap: wrap; justify-content: center; }
  #save-status { max-width: 110px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Belge görünümü: büyüt / döndür / tam ekran */
.board-viewport { overflow: hidden; touch-action: none; }
/* YouTube katmanı: belgenin üstünde, araç çubuğunun altında */
.yt-overlay { position: absolute; inset: 0; z-index: 55; background: #000; display: flex; align-items: center; justify-content: center; }
.yt-frame { width: 100%; height: 100%; border: 0; }
.yt-close { position: absolute; top: 12px; left: 12px; min-height: 48px; padding: 0 18px; border: 0; border-radius: 24px; background: rgba(15, 23, 42, 0.85); color: #fff; font: inherit; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.yt-close:hover { background: var(--primary); }
.view-controls { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px; background: var(--toolbar-bg); border: 1px solid var(--border-color); border-radius: 14px; box-shadow: var(--shadow-lg); }
.view-btn { width: 48px; height: 48px; min-width: 44px; min-height: 44px; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-hover); color: var(--text-main); font-size: 1.4rem; line-height: 1; cursor: pointer; touch-action: manipulation; }
.view-btn:hover, .view-btn[aria-pressed="true"] { background: var(--primary); }
.view-zoom-label { font-size: 0.8rem; color: var(--text-muted); min-height: 1.2em; }
body.pairing .view-controls { display: none; }
/* Belgeyi tam ekran göster: üst çubuk gizlenir, belge alanı doldurur */
body.doc-fullscreen .top-bar { display: none; }
body.doc-fullscreen .board-viewport { position: fixed; inset: 0; z-index: 10; }
@media (max-width: 640px) {
  .view-controls { flex-direction: row; top: auto; right: 50%; bottom: 84px; transform: translateX(50%); max-width: calc(100vw - 16px); }
  .view-btn { width: 44px; height: 44px; }
}

#btn-camera-sound[hidden] { display: none; }
#image-layer, #pdf-bg-canvas { image-rendering: auto; }

.qr-link { margin-top: 10px; text-align: center; font-size: 0.95rem; color: var(--text-muted); overflow-wrap: anywhere; word-break: break-word; user-select: text; -webkit-user-select: text; }

/* QR Kartı ve Telefon Kamerası İle Doğrudan Bağlanma */
.qr-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(37, 99, 235, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
  padding: 8px 18px;
  border-radius: 9999px;
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.qr-manual-box {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(15, 23, 42, 0.7);
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.qr-manual-label {
  font-size: 0.82rem;
  color: #94a3b8;
}
.qr-manual-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.qr-pin-pill {
  background: #2563eb;
  color: #ffffff;
  font-family: monospace;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 4px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

/* BEKLEME MODU KATMANI */
.standby-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.88);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
  cursor: pointer;
  transition: opacity 0.3s ease;
}

.standby-overlay.hidden {
  opacity: 0;
  pointer-events: none;
  display: none !important;
}

.standby-card {
  text-align: center;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.standby-card h2 {
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  font-weight: 700;
  color: #fff;
}

.standby-card p {
  font-size: clamp(1rem, 2vw, 1.25rem);
  color: var(--text-muted);
}

/* Sayfa küçük resimleri */
.thumb-strip { position: fixed; left: 50%; transform: translateX(-50%); bottom: 96px; z-index: 999; max-width: calc(100vw - 24px);
  display: flex; gap: 8px; padding: 8px; overflow-x: auto; background: var(--toolbar-bg); backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 14px; box-shadow: var(--shadow-lg); }
.thumb-strip[hidden] { display: none; }
.thumb { flex: none; min-width: 56px; min-height: 64px; padding: 4px; border: 2px solid transparent; border-radius: 8px; background: rgba(255,255,255,.06);
  color: var(--text-muted, #94a3b8); font: inherit; font-size: .75rem; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.thumb canvas { max-width: 96px; max-height: 72px; background: #fff; border-radius: 3px; }
.thumb[aria-selected="true"] { border-color: var(--primary, #2563eb); color: #fff; }
