:root {
  color-scheme: light;
  --paper: #ffffff;
  --ink: #152033;
  --muted: #66758b;
  --line: #d8e0ea;
  --surface: #ffffff;
  --panel: #f5f8fb;
  --accent: #0aa6c2;
  --accent-soft: #ddf7fb;
  --danger: #d04461;
  --shadow: 0 -18px 42px rgba(21, 32, 51, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
}

body {
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
.action-label,
.drawing-menu {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.action-label:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: 2px;
}

.tool-drawer button:focus-visible,
.tool-drawer .action-label:focus-visible,
.tool-drawer input:focus-visible,
.tool-drawer select:focus-visible {
  outline: 0;
  box-shadow: inset 0 0 0 2px #f59e0b;
}

.paper {
  position: fixed;
  inset: 0;
  background: var(--paper);
}

.paper canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#touchCanvas {
  touch-action: none;
  cursor: crosshair;
}

.drawer-toggle {
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 12;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(10, 166, 194, 0.42);
  border-radius: 50%;
  color: #ffffff;
  background: linear-gradient(135deg, #0aa6c2, #38b971);
  box-shadow: 0 14px 30px rgba(10, 166, 194, 0.28);
  cursor: pointer;
  transition: transform 170ms ease, box-shadow 170ms ease;
}

.drawer-toggle svg,
.icon-button svg,
.tool-button svg,
.action-grid svg,
.action-label svg,
.drawing-menu svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.15;
  flex: 0 0 auto;
}

.drawer-toggle:active {
  transform: translateY(1px) scale(0.98);
}

body.drawer-open .drawer-toggle {
  opacity: 0;
  pointer-events: none;
  transform: translateY(18px) scale(0.9);
}

.tool-drawer {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 11;
  height: 100dvh;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  background: rgba(245, 248, 251, 0.98);
  border: 0;
  border-radius: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
  transform: translateY(100%);
  transition: transform 210ms ease;
  will-change: transform;
}

body.drawer-open .tool-drawer {
  transform: translateY(0);
}

.drawer-header {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0 4px;
}

.drawer-header::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: #c7d2df;
  transform: translateX(-50%);
}

.drawer-header strong {
  font-size: 0.96rem;
  letter-spacing: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.drawer-content {
  height: calc(100% - 42px);
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: 2px;
  overscroll-behavior: contain;
  scrollbar-width: none;
}

.drawer-content::-webkit-scrollbar {
  display: none;
}

.panel {
  min-width: 0;
  padding: 0;
}

.panel h2 {
  margin: 0 0 6px;
  font-size: 0.7rem;
  letter-spacing: 0;
  color: #405069;
  text-transform: uppercase;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.tool-button,
.action-grid button,
.action-label {
  min-height: 40px;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 750;
  line-height: 1;
  text-align: center;
  cursor: pointer;
}

.tool-drawer .tool-button svg,
.tool-drawer .action-grid svg,
.tool-drawer .action-label svg,
.tool-drawer .drawing-menu svg {
  width: 18px;
  height: 18px;
}

.tool-button span,
.action-grid span,
.action-label span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-button.is-active {
  color: #075c6e;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(10, 166, 194, 0.16);
}

.color-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 8px;
}

.palette-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
  margin-bottom: 6px;
}

.palette-tabs button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: #3f4f67;
  font-size: 0.68rem;
  font-weight: 760;
  cursor: pointer;
}

.palette-tabs button.is-active {
  color: #075c6e;
  border-color: var(--accent);
  background: var(--accent-soft);
}

#colorInput {
  width: 42px;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(10, minmax(18px, 1fr));
  gap: 4px;
}

.swatch {
  min-height: 20px;
  aspect-ratio: 1;
  border: 1px solid rgba(21, 32, 51, 0.18);
  border-radius: 7px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.swatch.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 4px var(--accent);
}

.swatch.finish-lacquer::after {
  content: "";
  position: absolute;
  inset: 3px 4px auto auto;
  width: 38%;
  height: 28%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  filter: blur(1px);
}

.swatch.finish-glitter {
  background-image:
    radial-gradient(circle at 22% 28%, rgba(255, 255, 255, 0.95) 0 2px, transparent 2.5px),
    radial-gradient(circle at 72% 35%, rgba(255, 255, 255, 0.82) 0 1.5px, transparent 2px),
    radial-gradient(circle at 52% 76%, rgba(255, 255, 255, 0.9) 0 2px, transparent 2.5px);
}

.rgb-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-top: 6px;
}

.rgb-row label {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 3px;
  min-height: 32px;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: #405069;
  font-size: 0.75rem;
  font-weight: 780;
}

.rgb-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 760;
  text-align: right;
}

.compact-panel {
  min-width: 0;
}

.range-row {
  min-height: 34px;
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 38px;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.range-row output {
  min-width: 0;
  width: 100%;
  text-align: right;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(24px, 1fr));
  gap: 4px;
}

.emoji-grid button {
  width: auto;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem;
  cursor: pointer;
}

.emoji-grid button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 5px;
}

.drawing-menu {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 6px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}

.drawing-menu:focus-within,
.drawing-menu:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drawing-menu select {
  min-width: 0;
  flex: 1 1 auto;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 780;
}

.pdf-row {
  min-height: 34px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

.legal-links {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 780;
}

.legal-links a {
  color: #405069;
  text-decoration: none;
  white-space: nowrap;
}

.legal-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

#pdfStatus {
  min-width: 0;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden-input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 70px);
  z-index: 20;
  max-width: min(320px, calc(100vw - 32px));
  padding: 10px 13px;
  border-radius: 12px;
  background: #172033;
  color: #ffffff;
  box-shadow: 0 14px 36px rgba(21, 32, 51, 0.24);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.drawer-open .toast {
  bottom: max(12px, env(safe-area-inset-bottom));
}

@media (max-height: 700px) {
  .tool-drawer {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .drawer-content {
    gap: 6px;
  }

  .panel h2 {
    margin-bottom: 4px;
    font-size: 0.66rem;
  }

  .tool-button,
  .action-grid button,
  .action-label {
    min-height: 34px;
  }

  .palette-tabs button {
    min-height: 28px;
  }

  #colorInput {
    width: 38px;
    height: 38px;
  }

  .color-row {
    grid-template-columns: 38px minmax(0, 1fr);
  }

  .rgb-row label {
    min-height: 30px;
  }

  .range-row {
    min-height: 30px;
  }

  .emoji-grid button {
    height: 28px;
  }

  .pdf-row {
    min-height: 30px;
  }

  .drawing-menu {
    min-height: 30px;
    margin-top: 5px;
  }

  .drawing-menu select {
    height: 28px;
  }
}

/* Open Design draft: pocket sketchbook for ages 7-10. */
:root {
  --paper: #fffafd;
  --ink: #241833;
  --muted: #675d78;
  --line: #eadcf4;
  --surface: #ffffff;
  --panel: #fff4fb;
  --accent: #ff5fa2;
  --accent-soft: #fff0f8;
  --violet: #7c5cff;
  --cyan: #1db9e8;
  --lime: #68cf72;
  --yellow: #ffd85f;
  --danger: #d83f68;
}

.paper {
  background:
    linear-gradient(90deg, rgba(124, 92, 255, 0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(29, 185, 232, 0.07) 1px, transparent 1px),
    #fffafd;
  background-size: 30px 30px;
}

.drawer-toggle {
  width: 64px;
  height: 64px;
  border: 2px solid rgba(36, 24, 51, 0.18);
  background:
    linear-gradient(135deg, #ff5fa2 0%, #7c5cff 48%, #1db9e8 100%);
  box-shadow: 0 12px 0 rgba(36, 24, 51, 0.14), 0 18px 36px rgba(124, 92, 255, 0.26);
}

.tool-drawer {
  background:
    linear-gradient(90deg, rgba(255, 216, 95, 0.13) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 95, 162, 0.1) 1px, transparent 1px),
    rgba(255, 250, 253, 0.98);
  background-size: 28px 28px;
}

.drawer-header strong {
  color: var(--ink);
  font-size: 1.06rem;
}

.drawer-header::before {
  background: linear-gradient(90deg, var(--pink, #ff5fa2), var(--yellow), var(--cyan));
}

.panel {
  padding: 7px;
  border: 1px solid rgba(36, 24, 51, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.panel h2 {
  color: #6f3c83;
  font-size: 0.72rem;
}

.tool-button,
.action-grid button,
.action-label,
.palette-tabs button,
.emoji-grid button,
.drawing-menu,
.rgb-row label,
#colorInput,
.icon-button {
  border: 2px solid rgba(36, 24, 51, 0.12);
  border-radius: 8px;
  box-shadow: 2px 2px 0 rgba(36, 24, 51, 0.1);
}

.tool-button.is-active,
.palette-tabs button.is-active,
.emoji-grid button.is-active {
  color: #6e2450;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(255, 95, 162, 0.2), 2px 2px 0 rgba(36, 24, 51, 0.12);
}

.swatch {
  border-radius: 8px;
  border-width: 2px;
}

.range-row {
  color: #5b4f6b;
  font-weight: 760;
}

.toast {
  border-radius: 8px;
  background: #2a1c3b;
}

@media (min-width: 760px) {
  .tool-drawer {
    left: auto;
    width: min(452px, calc(100vw - 28px));
    border-left: 2px solid rgba(36, 24, 51, 0.12);
    box-shadow: -18px 0 42px rgba(36, 24, 51, 0.18);
    transform: translateX(110%);
  }

  body.drawer-open .tool-drawer {
    transform: translateX(0);
  }

  .drawer-content {
    gap: 10px;
  }

  .tool-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .palette-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .swatches {
    grid-template-columns: repeat(5, minmax(32px, 1fr));
  }

  .emoji-grid {
    grid-template-columns: repeat(5, minmax(34px, 1fr));
  }

  .action-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

/* Open Design v2 polish: proper tool surface instead of a recolored drawer. */
.tool-drawer {
  border-left: 0;
}

.drawer-header {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 52px;
  padding: 10px 8px 8px;
  background: rgba(255, 250, 253, 0.92);
  backdrop-filter: blur(12px);
}

.drawer-header strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.drawer-header strong::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 14px 0 0 var(--accent), 28px 0 0 var(--cyan);
}

.drawer-content {
  align-content: start;
}

.panel {
  box-shadow: 3px 3px 0 rgba(36, 24, 51, 0.1);
}

.panel h2 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel h2::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.tool-grid,
.action-grid {
  align-items: stretch;
}

.tool-button,
.action-grid button,
.action-label {
  min-height: 46px;
  position: relative;
  overflow: hidden;
  background: #ffffff;
}

.tool-button::after,
.action-grid button::after,
.action-label::after {
  content: "";
  position: absolute;
  inset: auto 8px 5px;
  height: 3px;
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.16);
}

.tool-button.is-active::after {
  background: linear-gradient(90deg, var(--accent), var(--yellow));
}

.color-row {
  align-items: start;
}

#colorInput {
  width: 50px;
  height: 50px;
}

.swatches {
  align-items: stretch;
}

.swatch {
  min-height: 30px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.36), 2px 2px 0 rgba(36, 24, 51, 0.08);
}

.swatch.is-active {
  transform: translateY(-2px);
  box-shadow: inset 0 0 0 2px #ffffff, inset 0 0 0 5px var(--accent), 2px 4px 0 rgba(36, 24, 51, 0.12);
}

.range-row input {
  accent-color: var(--violet);
}

.rgb-row input,
.drawing-menu select {
  font-weight: 850;
}

@media (min-width: 760px) {
  .tool-drawer {
    padding: 0 12px 12px;
  }

  .drawer-content {
    height: calc(100% - 58px);
  }

  .panel {
    padding: 10px;
  }
}
