/* Firefox ESR uyumu: flex "gap", inset, aspect-ratio, :focus-visible kullanılmıyor. */
:root {
  --size: 72px;             /* dokunmatik düğme boyutu (en az 64px) */
  --bar: #111827;
  --btn: #1f2937;
  --btn-border: #4b5563;
  --fg: #f9fafb;
  --muted: #9ca3af;
  --accent: #10b981;
  --stage: #4b5563;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bar);
  color: var(--fg);
  font-family: system-ui, "Noto Sans", "DejaVu Sans", Arial, sans-serif;
  font-size: 16px;
  -moz-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- çubuklar ---- */
.bar {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  padding: 4px 8px;
  background: var(--bar);
  touch-action: manipulation;
}

.grow { flex: 1 1 auto; }

.group { display: flex; align-items: center; flex-wrap: wrap; }

.sep {
  width: 2px;
  height: 48px;
  margin: 0 12px;
  background: #374151;
}

/* ---- düğmeler ---- */
.btn {
  min-width: var(--size);
  min-height: var(--size);
  margin: 4px;
  padding: 6px 12px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  background: var(--btn);
  border: 2px solid var(--btn-border);
  border-radius: 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
}

.btn span { margin-top: 4px; white-space: nowrap; }

.btn:active { background: #374151; }

.btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: #6ee7b7;
  color: #04241a;
}

.btn[disabled] {
  opacity: 0.35;
  cursor: default;
}

.ic {
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn.big {
  min-width: 260px;
  min-height: 96px;
  margin: 12px;
  font-size: 22px;
  flex-direction: row;
}
.btn.big .ic { width: 40px; height: 40px; }
.btn.big span { margin: 0 0 0 14px; }

/* renk ve kalınlık seçicileri */
.btn.swatch {
  min-width: var(--size);
  padding: 0;
  border-radius: 50%;
}
.btn.swatch .dot {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
}
.btn.swatch[aria-checked="true"] {
  border-color: #fff;
  background: #374151;
  box-shadow: 0 0 0 4px var(--accent);
}

.btn.width { min-width: var(--size); padding: 6px 8px; }
.btn.width .sample {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  margin: 0;
}
.btn.width .stroke {
  display: block;
  width: 44px;
  margin: 0;
  background: currentColor;
  border-radius: 99px;
}
.btn.width .stroke.hl { border-radius: 2px; opacity: 0.75; }   /* fosforlu: düz uçlu, yarı saydam örnek */
.btn.width .sizeA { margin: 0; font-weight: 700; line-height: 1; }
.btn.width[aria-checked="true"] {
  background: var(--accent);
  border-color: #6ee7b7;
  color: #04241a;
}

/* ---- üst çubuk bilgi alanları ---- */
#docInfo {
  min-width: 0;
  max-width: 320px;
  margin: 0 12px;
}
#docName {
  font-size: 18px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#saveStatus {
  margin-top: 2px;
  font-size: 14px;
  color: var(--muted);
}
#saveStatus.warn { color: #fbbf24; }

.readout {
  min-width: 96px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- sahne ---- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
  touch-action: none;
  cursor: crosshair;
}

#page {
  position: absolute;
  left: 0;
  top: 0;
  visibility: hidden;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.55);
  transform-origin: 0 0;
  will-change: transform;
}

#page canvas {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}
#liveCanvas { display: none; }   /* yalnızca fosforlu çizilirken görünür */

#empty {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
#empty h1 { margin: 0 0 8px; font-size: 44px; }
#empty p { margin: 8px 0 20px; font-size: 20px; line-height: 1.5; color: #e5e7eb; }
#empty .hint { font-size: 16px; color: #d1d5db; }

#busy, #toast {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 22px;
  border-radius: 12px;
  background: rgba(17, 24, 39, 0.92);
  font-size: 20px;
  pointer-events: none;
}
#busy { top: 16px; }
#toast { bottom: 24px; max-width: 80%; text-align: center; }

/* ---- uyarı penceresi ---- */
#dialog {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.65);
  touch-action: none;
}
#dialog .card {
  max-width: 760px;
  padding: 32px 36px;
  background: #1f2937;
  border: 2px solid var(--btn-border);
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}
#dialog h2 { margin: 0 0 14px; font-size: 30px; }
#dialog p { margin: 0 0 26px; font-size: 22px; line-height: 1.5; color: #e5e7eb; }
#dialog p.warn { color: #fbbf24; font-weight: 600; }
#dialogButtons { display: flex; flex-wrap: wrap; justify-content: flex-end; }
.btn.dlg {
  min-width: 190px;
  min-height: 84px;
  margin: 6px;
  font-size: 22px;
  flex-direction: row;
}
.btn.dlg.primary {
  background: var(--accent);
  border-color: #6ee7b7;
  color: #04241a;
  font-weight: 700;
}
.btn.dlg.danger {
  border-color: #f87171;
  color: #fecaca;
}

/* ---- tam ekran: yalnızca sayfa + yanda araç paneli ---- */
.fs-only { display: none; }

body.fs { --size: 64px; }
body.fs #topbar { display: none; }
body.fs .fs-only { display: contents; }

body.fs #app { flex-direction: row; }
body.fs.fs-left #app { flex-direction: row-reverse; }

body.fs #stage { min-width: 0; }

body.fs #toolbar {
  flex: 0 0 auto;
  width: 304px;                 /* 4 sütun x (64px düğme + 2x4px kenar boşluğu) + kenarlar */
  height: 100%;
  flex-direction: row;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  padding: 6px 4px;
  overflow-y: auto;             /* çok kısa ekranlarda panel kayar */
  border-left: 2px solid #374151;
}
body.fs.fs-left #toolbar {
  border-left: 0;
  border-right: 2px solid #374151;
}

body.fs #toolbar .group { display: contents; }   /* renk/kalınlık düğmeleri panele aynı ızgarada akar */
body.fs #toolbar .sep {
  width: 100%;
  height: 2px;
  margin: 6px 0;
}

body.fs #toolbar .btn {
  width: 64px;                  /* sabit genişlik: 3 sütun tutsun, uzun etiketler satıra sarılsın */
  padding: 3px 2px;
  font-size: 12px;
  line-height: 1.1;
}
body.fs #toolbar .btn .ic {   /* iki satırlı etiketli düğmeler 64px'i aşmasın: 768px yüksekliğe sığmalı */
  width: 24px;
  height: 24px;
}
body.fs #toolbar .btn span {
  margin-top: 2px;
  white-space: normal;
  text-align: center;
}
body.fs #toolbar .btn.swatch { padding: 0; }

body.fs #toolbar .readout {
  min-width: 0;
  width: 64px;
  margin: 4px;
  font-size: 17px;
}

/* ---- metin editörü ---- */
#textEditor {
  --key: 60px;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 22;
  padding: 6px 10px 10px;
  background: var(--bar);
  border-top: 2px solid var(--btn-border);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.5);
  touch-action: none;
}
#teTop { display: flex; align-items: stretch; }
#tePreview {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 72px;
  max-height: 132px;
  margin: 4px;
  padding: 8px 12px;
  overflow: auto;
  background: #fff;
  color: #111;
  border-radius: 12px;
  font-size: 26px;
  line-height: 1.3;
  white-space: pre-wrap;
  word-break: break-word;
}
#tePreview .ph { color: #9ca3af; }
#tePreview .caret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin: 0 1px -0.2em;
  background: #2563eb;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
#teActions { display: flex; flex: 0 0 auto; align-items: stretch; }
#teActions .btn.dlg { min-width: 110px; min-height: 72px; margin: 4px; font-size: 20px; }
#teOpts { justify-content: center; }
#teOpts .btn { min-width: 64px; min-height: 64px; margin: 2px 4px; }
#teOpts .btn.swatch .dot { width: 34px; height: 34px; }
.krow { display: flex; }
.key {
  flex: 1 1 0;
  min-width: 0;
  height: var(--key);
  margin: 3px;
  padding: 0;
  color: var(--fg);
  background: var(--btn);
  border: 2px solid var(--btn-border);
  border-radius: 10px;
  font: inherit;
  font-size: 24px;
  cursor: pointer;
  touch-action: manipulation;
}
.key.wide { flex: 1.5 1 0; }
.key.space { flex: 6 1 0; font-size: 18px; color: var(--muted); }
.key.on { background: var(--accent); border-color: #6ee7b7; color: #04241a; }
.key:active { background: #374151; }
.key[disabled] { opacity: 0.35; }
@media (max-height: 820px) {
  #textEditor { --key: 50px; }
  #tePreview { min-height: 56px; font-size: 22px; }
  #teActions .btn.dlg { min-height: 60px; }
}

.icons { position: absolute; }   /* simge takımı (satır içi style yerine: CSP style-src 'self') */

/* ---- tanı paneli (?tani=1) ---- */
#tani {
  position: fixed;
  left: 8px;
  top: 8px;
  z-index: 30;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font: 14px/1.35 monospace;
  pointer-events: none;
}
#tani .th { margin-bottom: 4px; opacity: 0.8; }
#tani .ok { color: #86efac; }
#tani .warn { color: #fbbf24; }
#tani .bad { color: #f87171; }

#ring {
  position: fixed;
  left: 0;
  top: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 2px #000;
  pointer-events: none;
  z-index: 5;
}
