/* =========================================================
   Lousa Digital — Estilos
   Tema: claro (papel) | escuro (lousa de giz preta)
   ========================================================= */

:root {
  --bg: #f4f5f7;
  --bg-elev: #ffffff;
  --bg-canvas: #ffffff;
  --text: #0f172a;
  --text-soft: #475569;
  --border: #e2e8f0;
  --accent: #0ea5e9;
  --accent-strong: #0284c7;
  --danger: #ef4444;
  --shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
  --radius: 12px;
  --topbar-h: 56px;
  --tool-w: 72px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --bg-elev: #111a2c;
  --bg-canvas: #0a1018;
  --text: #e2e8f0;
  --text-soft: #94a3b8;
  --border: #1f2a44;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  height: var(--topbar-h);
  flex-shrink: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}
.logo {
  font-size: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
}

.topbar-actions { display: flex; gap: 6px; }

/* ---------- Botões ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  color: var(--text);
  white-space: nowrap;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.btn:hover { background: var(--bg); }
.btn.primary {
  background: var(--accent);
  color: white;
}
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { border-color: var(--border); }
.btn.hidden { display: none; }

/* ---------- Workspace ---------- */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ---------- Toolbar lateral ---------- */
.toolbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  width: var(--tool-w);
  flex-shrink: 0;
  overflow-y: auto;
  scrollbar-width: thin;
}

.tool-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.tool-group.vertical { gap: 4px; }

.divider {
  height: 1px;
  width: 80%;
  background: var(--border);
  margin: 4px 0;
}

.tool {
  width: 44px;
  height: 44px;
  font-size: 18px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 100ms, border-color 100ms, transform 100ms;
}
.tool:hover { background: var(--bg); }
.tool.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  transform: scale(1.05);
}

.action {
  width: 44px;
  height: 44px;
  font-size: 18px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
}
.action:hover { background: var(--bg); }
.action.danger { color: var(--danger); border-color: var(--danger); }
.action.danger:hover { background: var(--danger); color: white; }

/* ---------- Cores ---------- */
.swatches {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  width: 100%;
  padding: 0 4px;
}
.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
  transition: transform 80ms, border-color 80ms;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: var(--accent); border-width: 3px; }

.color-picker {
  position: relative;
  width: 44px;
  height: 28px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-soft);
}
.color-picker input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ---------- Espessura ---------- */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 44px;
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  outline: none;
  transform: rotate(-90deg);
  transform-origin: center;
  margin: 20px 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}
.size-label {
  font-size: 12px;
  color: var(--text-soft);
  font-variant-numeric: tabular-nums;
}

/* ---------- Canvas ---------- */
.canvas-wrap {
  flex: 1;
  position: relative;
  background: var(--bg-canvas);
  overflow: hidden;
  min-width: 0;
}
#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elev);
  color: var(--text-soft);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  pointer-events: none;
  opacity: 0.8;
  box-shadow: var(--shadow);
  transition: opacity 300ms;
}
.hint.fade { opacity: 0; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: fade 160ms ease-out;
}
.modal.hidden { display: none; }
@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-card.wide { max-width: 600px; }
.modal-card h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field span { font-size: 12px; color: var(--text-soft); }
.field input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---------- Lousas salvas ---------- */
.load-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  max-height: 60vh;
  overflow-y: auto;
  margin-bottom: 16px;
}
.load-list .empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-soft);
  padding: 24px;
}
.saved-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform 100ms, border-color 100ms;
  background: var(--bg);
}
.saved-item:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.saved-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: white;
  display: block;
}
.saved-item .meta {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.saved-item .meta .name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.saved-item .meta .date {
  font-size: 11px;
  color: var(--text-soft);
}
.saved-item .delete {
  position: absolute;
  margin-left: 130px;
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  cursor: pointer;
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg-elev);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 200;
  box-shadow: var(--shadow);
  animation: pop 200ms ease-out;
}
.toast.hidden { display: none; }
@keyframes pop {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Responsivo (mobile) ---------- */
@media (max-width: 640px) {
  :root { --topbar-h: 52px; --tool-w: 60px; }
  .brand h1 { font-size: 14px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .topbar-actions .btn.ghost { padding: 6px 8px; }
  .tool { width: 40px; height: 40px; font-size: 16px; }
  .action { width: 40px; height: 40px; font-size: 16px; }
  .hint { font-size: 11px; padding: 4px 10px; }
}

/* Tela muito pequena: toolbar em baixo */
@media (max-width: 480px) {
  .workspace { flex-direction: column-reverse; }
  .toolbar {
    flex-direction: row;
    width: 100%;
    height: auto;
    border-right: none;
    border-top: 1px solid var(--border);
    padding: 6px;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .tool-group { flex-direction: row; }
  .tool-group.vertical { flex-direction: row; }
  .divider { width: 1px; height: 28px; margin: 0 4px; }
  .swatches { grid-template-columns: repeat(6, 1fr); width: auto; }
  .swatch { width: 26px; aspect-ratio: 1; }
  input[type="range"] { transform: none; width: 80px; margin: 0 4px; }
  .size-label { display: none; }
  .color-picker { width: 36px; height: 28px; }
  .action { width: 36px; height: 36px; font-size: 16px; }
}
