: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;
  }
}
