:root {
  /* Default canvas state. Treatments overwrite these CSS variables. */
  --bg: white;
  --font-color: black;
  --font-size: 20vw;
  --font-family: 'Roboto Flex', sans-serif;
  --text-align: left;
  --font-variation-settings: 'wght' 400;
}

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
}

textarea {
  position: fixed;
  inset: 0;              /* fills the entire viewport */
  width: 100%;
  height: 100%;
  border: none;          /* no border */
  outline: none;         /* kills the focus ring, the most-forgotten one */
  resize: none;          /* removes the drag handle in the bottom-right corner */
  background: transparent;/* page background shows through */
  padding: 4vh 5vw;      /* breathing room */
  margin: 0;
  box-shadow: none;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent; /* no tap flash on mobile */

  font-family: var(--font-family);
  font-size: var(--font-size);
  color: var(--font-color);
  text-align: var(--text-align);
  font-variation-settings: var(--font-variation-settings);
  line-height: 1.3;
}

textarea::placeholder {
  color: #9a9a9a;
  opacity: 0.8;
}

/* ---------------------------------------------------------------------------
   Draw experience. body.drawing makes the document two viewports tall: the
   writing page on top, the drawing surface below. (vh lines are fallbacks for
   browsers without dvh.)
--------------------------------------------------------------------------- */

body.drawing {
  height: 200vh;
  height: 200dvh;
  overflow-x: hidden;
}

body.drawing textarea {
  position: absolute;
  inset: auto;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
}

.draw-section {
  position: absolute;
  top: 100vh;
  top: 100dvh;
  left: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* Mirror of the written page: same box, padding, and font treatments as the
   textarea (all driven by the shared CSS variables). */
.draw-mirror {
  position: absolute;
  inset: 0;
  padding: 4vh 5vw;
  box-sizing: border-box;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;

  font-family: var(--font-family);
  font-size: var(--font-size);
  color: var(--font-color);
  text-align: var(--text-align);
  font-variation-settings: var(--font-variation-settings);
  line-height: 1.3;
}

.draw-canvas,
.draw-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.draw-canvas {
  touch-action: none; /* drawing never fights page scroll */
  cursor: crosshair;
}

.draw-overlay {
  pointer-events: none;
  opacity: 0.85; /* in-progress pencil stroke shows at pencil translucency */
}

/* Floating pill toolbar at the bottom of the drawing viewport. */
.draw-toolbar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  background: #fff;
  border-radius: 26px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.08),
    0 8px 32px rgba(0, 0, 0, 0.16),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  max-width: calc(100vw - 20px);
  box-sizing: border-box;
}

.draw-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.draw-toolbar button {
  appearance: none;
  border: none;
  background: transparent;
  width: 44px;   /* comfortable touch target */
  height: 44px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  padding: 0;
  cursor: pointer;
  color: #444;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.draw-toolbar button:hover { background: rgba(0, 0, 0, 0.05); }
.draw-toolbar button:disabled { opacity: 0.4; cursor: default; }

.draw-tool.active,
.draw-tool.active:hover {
  background: #7c4dff;
  color: #fff;
}

.draw-swatch span {
  display: block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.draw-swatch.selected { background: rgba(0, 0, 0, 0.06); }

.draw-swatch.selected span {
  width: 22px;
  height: 22px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #7c4dff;
}

.draw-divider {
  width: 1px;
  height: 26px;
  background: rgba(0, 0, 0, 0.12);
  margin: 0 6px;
}

/* Narrow screens: swatches wrap onto their own row so touch targets never
   shrink. */
@media (max-width: 640px) {
  .draw-group-swatches {
    order: 3;
    flex-basis: 100%;
    justify-content: center;
    margin-top: 2px;
  }
}
