/* ---------------------------------------------------------------------------
   Painting corner, opened from the easel
--------------------------------------------------------------------------- */
.paint-overlay { position: fixed; inset: 0; z-index: 50; --paint: #1f1c1a; }
.paint-overlay[hidden] { display: none; }
.paint-overlay:focus { outline: none; }

.paint-backdrop {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(28, 20, 14, 0.55), rgba(8, 6, 6, 0.88));
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.paint-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 24px 72px 24px 24px;
  pointer-events: none;
}

/* the canvas, stretched on its frame */
.paint-board {
  position: relative;
  pointer-events: auto;
  flex: none;
  border-radius: 3px;
  box-shadow:
    0 0 0 6px #e7dcc6,
    0 0 0 7px rgba(80, 60, 40, 0.35),
    0 30px 70px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  /* never wider than the space beside the panel, never taller than the window */
  width: min(calc((100vh - 64px) * 0.8), calc(100vw - 380px), 920px);
  width: min(calc((100dvh - 64px) * 0.8), calc(100vw - 380px), 920px);
  aspect-ratio: 4 / 5;
}
.paint-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}
.paint-cursor {
  position: absolute;
  left: 0;
  top: 0;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.7);
  pointer-events: none;
  opacity: 0;
}

/* the tool panel */
.paint-panel {
  pointer-events: auto;
  width: 236px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  border-radius: 16px;
  background: rgba(24, 20, 26, 0.6);
  border: 1px solid var(--glass-border);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.ready .paint-panel { opacity: 1; }

.paint-tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.paint-tool {
  all: unset;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 0 6px;
  border-radius: 10px;
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--ink-dim);
  cursor: pointer;
  border: 1px solid transparent;
}
.paint-tool:hover { color: var(--ink); background: rgba(255, 255, 255, 0.05); }
.paint-tool.active {
  color: var(--ink);
  background: rgba(255, 194, 122, 0.16);
  border-color: rgba(255, 194, 122, 0.45);
}
.paint-tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.paint-swatches {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  justify-items: center;
}
.paint-swatch {
  all: unset;
  position: relative;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--c, #888);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 1px 3px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}
.paint-swatch.active { box-shadow: 0 0 0 2px rgba(24, 20, 26, 0.9), 0 0 0 4px var(--accent); }
.paint-swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.paint-custom {
  background: conic-gradient(#e85a4f, #f2c230, #7fae3e, #5fb3c9, #3a6fb0, #7b4a9e, #e85a4f);
  overflow: hidden;
}
.paint-custom.active { background: var(--c); }
.paint-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: 0;
  padding: 0;
}

.paint-size {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-dim);
}
.paint-size input { flex: 1; accent-color: var(--accent); min-width: 0; }
.paint-size-dot {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: none;
}
.paint-size-dot i {
  display: block;
  border-radius: 50%;
  background: var(--paint);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}
.paint-overlay[data-tool="eraser"] .paint-size-dot i { background: transparent; box-shadow: 0 0 0 1.5px var(--ink); }

.paint-actions, .paint-export { display: flex; gap: 8px; }
.paint-btn {
  all: unset;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-size: 12px;
  letter-spacing: 0.06em;
  cursor: pointer;
}
.paint-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }
.paint-btn:disabled { opacity: 0.35; cursor: default; }
.paint-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.paint-export .paint-btn { background: rgba(255, 194, 122, 0.12); border-color: rgba(255, 194, 122, 0.35); }

.paint-close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(255, 236, 210, 0.22);
  background: rgba(20, 16, 24, 0.45);
  color: #fff6e8;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.ready .paint-close { opacity: 1; }
.paint-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* narrow or portrait screens: the canvas on top, a compact panel underneath */
@media (max-width: 820px), (max-aspect-ratio: 1 / 1) {
  .paint-stage {
    flex-direction: column;
    gap: 14px;
    padding: calc(60px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
    justify-content: flex-start;
  }
  .paint-board {
    width: min(calc(100vw - 32px), calc((100vh - 330px) * 0.8), 720px);
    width: min(calc(100vw - 32px), calc((100dvh - 330px) * 0.8), 720px);
  }
  .paint-panel {
    width: min(100%, 560px);
    padding: 10px 12px;
    gap: 10px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    align-items: center;
  }
  .paint-tools, .paint-swatches { grid-column: 1 / -1; }
  .paint-tool { flex-direction: row; justify-content: center; padding: 6px 0; }
  .paint-tool span { display: none; }
  .paint-swatches { grid-template-columns: repeat(15, 1fr); gap: 4px; }
  .paint-swatch { width: 24px; height: 24px; }
  .paint-size { grid-column: 1 / -1; }
}
@media (max-width: 480px) {
  .paint-swatches { grid-template-columns: repeat(8, 1fr); }
}
