/* Muttley - editor di scrittura a mano. Solo classi .ink-*; colori e misure da app.css.
   La carta resta sempre bianca (anche in tema scuro); la barra strumenti segue il tema. */

.ink-editor {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  background: var(--surface-3);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Barra strumenti ---------------------------------------------------- */

.ink-bar {
  flex: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "title actions" "tools tools";
  align-items: center;
  gap: 2px 8px;
  padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  touch-action: manipulation;
  position: relative;
  z-index: 2;
}

.ink-title {
  grid-area: title;
  min-width: 0;
  padding-left: 4px;
  font-size: 15px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ink-actions {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 2px;
}

.ink-done {
  height: 38px;
  min-width: 68px;
  margin-left: 6px;
}

.ink-tools {
  grid-area: tools;
  min-width: 0;
  margin: 0 -10px;
  padding: 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.ink-tools::-webkit-scrollbar { display: none; }

.ink-tools-in {
  display: flex;
  align-items: center;
  gap: 2px;
  width: max-content;
  margin: 0 auto;
}

.ink-group {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
.ink-group.ink-dim { opacity: 0.45; }

.ink-sep {
  flex: none;
  width: 1px;
  height: 24px;
  margin: 0 6px;
  background: var(--border-strong);
}

.ink-tool {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  transition: background 0.12s, color 0.12s;
}
.ink-tool:hover { background: var(--surface-2); color: var(--text); }
.ink-tool:active { background: var(--surface-3); }
.ink-tool.ink-on { background: var(--accent-soft); color: var(--accent-text); }
.ink-tool:disabled { opacity: 0.35; cursor: default; background: transparent; }

.ink-size span {
  display: block;
  border-radius: 50%;
  background: currentColor;
}

.ink-swatch {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.ink-swatch::before {
  content: "";
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink-c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s;
}
.ink-swatch:hover::before { transform: scale(1.12); }
.ink-swatch.ink-on::before {
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14), 0 0 0 2.5px var(--surface), 0 0 0 5px var(--ink-c);
}

.ink-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  flex: none;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.ink-toggle:hover { background: var(--surface-2); color: var(--text); }
.ink-toggle.ink-on { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }

@media (min-width: 1180px) {
  .ink-bar {
    grid-template-columns: minmax(90px, 220px) minmax(0, 1fr) auto;
    grid-template-areas: "title tools actions";
  }
  .ink-tools { margin: 0; padding: 0; }
}

/* ---- Avviso "solo penna" ------------------------------------------------- */

.ink-hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow-2);
}
.ink-hint .btn { flex: none; }

/* ---- Pagine -------------------------------------------------------------- */

.ink-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px calc(12px + var(--safe-right)) calc(32px + var(--safe-bottom)) calc(12px + var(--safe-left));
}

.ink-sheet {
  width: min(100%, 1000px);
  margin: 0 auto 16px;
}

.ink-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
  padding: 0 2px 4px;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}

.ink-clear {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  font-weight: 600;
}
.ink-clear:hover { background: var(--surface-2); color: var(--danger); }

.ink-paper {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 3px;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(20, 20, 30, 0.14), 0 0 0 1px rgba(20, 20, 30, 0.06);
  cursor: crosshair;
  touch-action: none;
}

.ink-canvas,
.ink-live {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.ink-canvas { touch-action: none; }
.ink-live { pointer-events: none; }

/* Solo penna: il dito scorre e ingrandisce la pagina, la penna scrive (vedi Surface.onTouch). */
.ink-pen-only .ink-paper,
.ink-pen-only .ink-canvas {
  touch-action: pan-y pinch-zoom;
}

/* Tratto di evidenziatore in corso: disegnato a colore pieno e reso trasparente qui, cosi' resta uniforme. */
.ink-live.ink-hl {
  opacity: 0.36;
  mix-blend-mode: multiply;
}

.ink-ring {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  border: 1.5px solid rgba(40, 44, 52, 0.55);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

.ink-add {
  display: flex;
  height: 44px;
  margin: 2px auto 0;
  padding: 0 18px;
}
