:root {
  color-scheme: light;
  --page: #f6f7f9;
  --panel: #ffffff;
  --line: #d7dbe3;
  --ink: #151922;
  --muted: #667085;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 10px clamp(14px, 3vw, 32px);
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: grid;
  gap: 1px;
  min-width: 160px;
}

.brand strong {
  font-size: 15px;
  line-height: 1.2;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.tool-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 11px;
  background: transparent;
  color: var(--ink);
  font: 650 13px/1 system-ui, sans-serif;
  cursor: pointer;
}

button:hover {
  border-color: #b8c2d3;
  background: #ffffff;
}

button[aria-pressed="true"] {
  border-color: #9ab7f7;
  background: var(--accent-soft);
  color: #1d4ed8;
}

button:disabled {
  color: #98a2b3;
  cursor: not-allowed;
  background: transparent;
  border-color: transparent;
}

button[data-role="clear"]:hover {
  border-color: #f3b6b0;
  color: var(--danger);
}

label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

input[type="range"] {
  width: 128px;
  accent-color: var(--accent);
}

.switch {
  gap: 9px;
}

.switch input {
  width: 36px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.spacer {
  flex: 1;
}

.surface {
  min-height: 0;
  padding: clamp(12px, 2.4vw, 26px);
}

.paper {
  position: relative;
  height: 100%;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(rgba(148, 163, 184, .18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .18) 1px, transparent 1px),
    #ffffff;
  background-size: 28px 28px;
  box-shadow: 0 18px 45px rgba(31, 41, 55, .12);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  cursor: crosshair;
  touch-action: none;
}

.storage-meter {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, .9);
  color: var(--muted);
  font: 600 12px/1.3 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.storage-meter:empty {
  display: none;
}

canvas[data-tool="eraser"],
canvas[data-tool="stroke-eraser"] {
  cursor: cell;
}

@media (max-width: 840px) {
  .toolbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .brand {
    flex-basis: 100%;
  }

  .spacer {
    display: none;
  }

  input[type="range"] {
    width: 110px;
  }
}
