*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --dock-width: 220px;
  --dock-bg: #141b24;
  --dock-surface: #1c2633;
  --dock-border: rgba(255, 255, 255, 0.08);
  --dock-text: #e8eef6;
  --dock-muted: #8b9bb0;
  --accent: #3dd6c6;
  --accent-dim: rgba(61, 214, 198, 0.18);
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --line-color: #9eb6d4;
  --paper-line: #9eb8d6;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #0d1218;
  color: var(--dock-text);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  display: flex;
  flex-direction: row;
}

/* —— Left dock shell (mânerul stă în afara panoului) —— */
.dock-shell {
  position: relative;
  flex-shrink: 0;
  height: 100%;
  height: 100dvh;
  z-index: 20;
}

.dock {
  width: var(--dock-width);
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 12px 18px;
  background:
    linear-gradient(180deg, #1a2432 0%, var(--dock-bg) 40%),
    var(--dock-bg);
  border-right: 1px solid var(--dock-border);
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
  transition: width 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
}

.dock-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 8px;
  border-bottom: 1px solid var(--dock-border);
}

/* Mâner exterior — trage/împinge panoul */
.dock-toggle {
  appearance: none;
  position: absolute;
  bottom: 20px;
  right: -40px;
  z-index: 50;
  width: 36px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--dock-border);
  border-left: none;
  border-radius: 0 10px 10px 0;
  background: #1c2633;
  color: var(--dock-text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, transform 0.15s;
}

.dock-toggle:hover {
  background: #2c3a4d;
}

.dock-toggle-icon {
  font-size: 1.35rem;
  line-height: 1;
  font-weight: 700;
}

/* —— Dock collapsed —— */
.dock-shell.collapsed .dock {
  width: 0;
  padding: 0;
  border-right: none;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}

.dock-shell.collapsed .dock-toggle-icon {
  transform: scaleX(-1);
}

.dock-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #9b59b6, #6c3483);
  box-shadow: 0 6px 16px rgba(155, 89, 182, 0.35);
}

.dock-brand strong {
  display: block;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.dock-brand small {
  color: var(--dock-muted);
  font-size: 0.72rem;
}

.dock-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--dock-surface);
  border: 1px solid var(--dock-border);
  border-radius: 12px;
}

.dock-section[hidden] {
  display: none !important;
}

.dock-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--dock-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dock-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.75rem;
}

.dock-grid {
  display: grid;
  gap: 6px;
}

.bg-grid {
  grid-template-columns: 1fr 1fr;
}

.size-grid {
  grid-template-columns: 1fr 1fr;
}

.tool-grid {
  grid-template-columns: 1fr 1fr;
}

.dock-btn {
  appearance: none;
  border: 1px solid transparent;
  background: #243040;
  color: var(--dock-text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 9px 8px;
  border-radius: 9px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.dock-btn:hover {
  background: #2c3a4d;
}

.dock-btn:active {
  transform: scale(0.97);
}

.dock-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px rgba(61, 214, 198, 0.35);
}

.dock-btn-wide {
  width: 100%;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 58px;
}

.tool-icon {
  font-size: 1.05rem;
  line-height: 1;
  opacity: 0.9;
}

.tool-btn[data-tool="eraser"].active {
  border-color: #f0a500;
  background: rgba(240, 165, 0, 0.16);
  box-shadow: inset 0 0 0 1px rgba(240, 165, 0, 0.35);
}

/* Buton flotant Gumă / Instrument — mereu pe dreapta */
/* Undo / Redo — colț dreapta-sus */
.history-bar {
  position: fixed;
  top: 16px;
  right: 18px;
  z-index: 60;
  display: flex;
  gap: 8px;
}

.history-btn {
  appearance: none;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  background: rgba(28, 38, 51, 0.72);
  backdrop-filter: blur(8px);
  color: #e8eef6;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}

.history-btn:hover:not(:disabled) {
  background: rgba(44, 58, 77, 0.9);
}

.history-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.history-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.geo-btn.active {
  border-color: #7aa2ff;
  background: rgba(122, 162, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(122, 162, 255, 0.35);
}

.fab-switch {
  appearance: none;
  position: fixed;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 72px;
  min-height: 72px;
  padding: 12px 8px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  background: #1c2633;
  color: #e8eef6;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.fab-switch:hover {
  background: #2c3a4d;
}

.fab-switch:active {
  transform: translateY(-50%) scale(0.96);
}

.fab-switch.is-eraser {
  border-color: #f0a500;
  background: #4a3a1a;
}

.fab-switch.is-eraser .fab-switch-icon {
  color: #f0a500;
}

.fab-switch-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.fab-switch-label {
  letter-spacing: 0.02em;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.color-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
  background: var(--swatch);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.15s;
}

.color-btn:hover {
  transform: scale(1.08);
}

.color-btn.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.custom-color {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px dashed rgba(255, 255, 255, 0.35);
  cursor: pointer;
  position: relative;
  background:
    conic-gradient(
      from 0deg,
      #ff0000,
      #ffff00,
      #00ff00,
      #00ffff,
      #0000ff,
      #ff00ff,
      #ff0000
    );
}

.custom-color input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
}

.custom-color.active-ring {
  box-shadow: 0 0 0 2px var(--accent);
  border-style: solid;
  border-color: #fff;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 0.85rem;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-ui {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #314155;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s;
}

.switch-row input:checked + .switch-ui {
  background: var(--accent);
}

.switch-row input:checked + .switch-ui::after {
  transform: translateX(18px);
}

.slider-label {
  font-size: 0.78rem;
  color: var(--dock-muted);
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
}

.dock-actions {
  margin-top: auto;
}

.danger-btn {
  background: var(--danger);
  border-color: transparent;
}

.danger-btn:hover {
  background: var(--danger-hover);
}

/* —— Board —— */
.board-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #0d1218;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: none;
  overflow: hidden;
  cursor: none;
  /* Scale 1 = Mediu (referință pentru alinierea desenelor) */
  --paper-scale: 1;
  --paper-margin: calc(80px * var(--paper-scale));
  --math-cell: calc(48px * var(--paper-scale));
  --tip-tile-w: calc(200px * var(--paper-scale));
  --tip-tile-h: calc(120px * var(--paper-scale));
  --tip-oblique: calc(20px * var(--paper-scale));
  --caiet-line: calc(56px * var(--paper-scale));
}

.board.paper-size-sm {
  --paper-scale: 0.6666667;
}

.board.paper-size-md {
  --paper-scale: 1;
}

.board.paper-size-lg {
  --paper-scale: 1.5;
}

.board.paper-size-xl {
  --paper-scale: 2;
}

.board canvas {
  background: transparent !important;
}

/* —— Backgrounds —— */
.bg-white {
  background-color: #ffffff;
}

.bg-math {
  background-color: #fafcff;
  background-image:
    linear-gradient(to right, var(--line-color) 1px, transparent 1px),
    linear-gradient(to bottom, var(--line-color) 1px, transparent 1px);
  background-size: var(--math-cell) var(--math-cell);
}

/* Tip I — oblice la 105deg */
.bg-tip-i {
  background-color: #ffffff;
  background-image:
    repeating-linear-gradient(
      105deg,
      transparent,
      transparent calc(var(--tip-oblique) - 1px),
      var(--paper-line) calc(var(--tip-oblique) - 1px),
      var(--paper-line) var(--tip-oblique)
    ),
    url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="60"><line x1="0" y1="0" x2="100" y2="0" stroke="%239eb8d6" stroke-width="1" stroke-dasharray="5,5"/><line x1="0" y1="20" x2="100" y2="20" stroke="%239eb8d6" stroke-width="1"/><line x1="0" y1="40" x2="100" y2="40" stroke="%239eb8d6" stroke-width="1"/></svg>');
  background-size: 100% 100%, var(--tip-tile-w) var(--tip-tile-h);
  background-position: top left, 0 var(--paper-margin);
  background-repeat: repeat;
}

.bg-tip-ii {
  background-color: #ffffff;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="60"><line x1="0" y1="0" x2="100" y2="0" stroke="%239eb8d6" stroke-width="1" stroke-dasharray="5,5"/><line x1="0" y1="20" x2="100" y2="20" stroke="%239eb8d6" stroke-width="1"/><line x1="0" y1="40" x2="100" y2="40" stroke="%239eb8d6" stroke-width="1"/></svg>');
  background-size: var(--tip-tile-w) var(--tip-tile-h);
  background-position: 0 var(--paper-margin);
  background-repeat: repeat;
}

.bg-caiet {
  background-color: #ffffff;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent calc(var(--caiet-line) - 1px),
    var(--paper-line) calc(var(--caiet-line) - 1px),
    var(--paper-line) var(--caiet-line)
  );
  background-position: 0 var(--paper-margin);
  background-repeat: repeat;
}

/* Fullscreen: dock remains; board fills remaining space.
   When the whole document is fullscreened from board-wrapper, stretch it. */
.board-wrapper:fullscreen,
.board-wrapper:-webkit-full-screen {
  width: 100%;
  height: 100%;
  background: #fff;
}

@media (max-width: 720px) {
  :root {
    --dock-width: 168px;
  }

  .dock {
    padding: 10px 8px;
    gap: 10px;
  }

  .dock-section {
    padding: 8px;
  }

  .dock-btn {
    font-size: 0.72rem;
    padding: 8px 6px;
  }

  .tool-btn {
    min-height: 52px;
  }
}
