:root {
  color-scheme: light;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --surface: #ffffff;
  --chrome: #ffffff;
  --line: #d2d2d7;
  --accent: #0071e3;
  --danger: #d70015;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.07);
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--chrome);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(53, 102, 214, 0.28);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: -60px;
  left: 16px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
}

.topbar {
  height: 66px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 18px;
  padding: 0 max(22px, env(safe-area-inset-right)) 0 max(22px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  position: relative;
  z-index: 10;
}

.top-actions,
.history-actions,
.tool-group,
.swatches {
  display: flex;
  align-items: center;
}

.brand {
  width: max-content;
  color: var(--ink);
  text-decoration: none;
  font-size: 1rem;
  font-weight: 600;
}

.product-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 0.84rem;
  font-weight: 600;
}

.brand-mark {
  width: 31px;
  height: 31px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--ink);
  color: white;
  font-size: 0.95rem;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  text-decoration: none;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.icon-button:hover:not(:disabled) {
  border-color: #86868b;
  background: #f5f5f7;
}

svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.document-status {
  position: absolute;
  z-index: 2;
  top: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--muted);
  box-shadow: var(--shadow);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  font-size: 0.72rem;
  font-weight: 600;
  pointer-events: none;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #248a3d;
  box-shadow: 0 0 10px rgba(36, 138, 61, 0.5);
}

.top-actions {
  justify-content: flex-end;
  gap: 18px;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
}

.site-nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.75rem;
  transition: color 0.2s ease;
}

.site-nav a:hover {
  color: var(--ink);
}

.export-button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 0;
  border-radius: 980px;
  background: var(--ink);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: none;
  transition: transform 160ms ease, background 160ms ease;
}

.export-button:hover {
  background: #424245;
}

.export-button svg {
  width: 18px;
  height: 18px;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
  background: #f5f5f7;
}

.toolbar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 12px 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.tool-group {
  flex-direction: column;
  gap: 6px;
}

.tool-button {
  width: 100%;
  min-height: 62px;
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tool-button:hover {
  background: #f5f5f7;
  color: var(--ink);
}

.tool-button.active {
  border-color: #d2d2d7;
  background: #f5f5f7;
  color: var(--accent);
}

.tool-button span {
  font-size: 0.68rem;
  font-weight: 700;
}

.toolbar-divider {
  height: 1px;
  flex: 0 0 auto;
  background: #e8e8ed;
}

.control-label {
  display: flex;
  justify-content: space-between;
  margin: 0 2px 8px;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.control-label output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.swatches {
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
}

.swatch,
.custom-color {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #d5d2cb;
  cursor: pointer;
}

.swatch.selected,
.custom-color.selected {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink);
}

.custom-color {
  background: conic-gradient(#df5b57, #e4a937, #2d9b74, #3566d6, #8b5cf6, #df5b57);
}

.custom-color input {
  width: 100%;
  height: 100%;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.size-control input {
  width: 100%;
  height: 4px;
  accent-color: var(--ink);
  cursor: pointer;
}

.history-actions {
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.toolbar .icon-button {
  width: 36px;
  height: 36px;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.32;
}

.icon-button.danger:not(:disabled) {
  color: var(--danger);
}

.board-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background-color: #ffffff;
  box-shadow: var(--shadow);
}

.board-wrap.show-grid {
  background-image: radial-gradient(circle, rgba(110, 110, 115, 0.22) 1px, transparent 1.2px);
  background-position: 0 0;
  background-size: 24px 24px;
}

#drawing-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

#drawing-canvas[data-tool="eraser"] {
  cursor: cell;
}

.empty-state {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  display: grid;
  justify-items: center;
  transform: translate(-50%, -50%);
  color: var(--muted);
  text-align: center;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.empty-state.hidden {
  opacity: 0;
}

.gesture-mark svg {
  width: 112px;
  height: 70px;
  stroke: #86868b;
  stroke-width: 3;
}

.empty-state p {
  margin: 3px 0 5px;
  color: var(--ink);
  font-family: inherit;
  font-weight: 600;
  font-size: clamp(1.45rem, 3vw, 2rem);
  letter-spacing: -0.02em;
}

.empty-state span {
  font-size: 0.82rem;
}

.board-tip {
  position: absolute;
  z-index: 2;
  right: 14px;
  bottom: 12px;
  padding: 7px 10px;
  border: 1px solid rgba(210, 210, 215, 0.9);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 650;
  pointer-events: none;
  backdrop-filter: blur(8px);
  transition: opacity 300ms ease;
}

.board-tip.hidden {
  opacity: 0;
}

dialog {
  width: min(390px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 80px rgba(23, 34, 59, 0.22);
}

dialog::backdrop {
  background: rgba(23, 34, 59, 0.26);
  backdrop-filter: blur(3px);
}

dialog form {
  padding: 28px;
  text-align: center;
}

.dialog-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin: 0 auto 15px;
  border-radius: 50%;
  background: #faeceb;
  color: var(--danger);
}

dialog h2 {
  margin: 0 0 8px;
  font-family: inherit;
  font-size: 1.45rem;
  font-weight: 600;
}

dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 24px;
}

.dialog-actions button {
  min-height: 42px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.dialog-secondary {
  border: 1px solid var(--line);
  background: white;
}

.dialog-danger {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: white;
}

@media (max-width: 760px) {
  .topbar {
    height: 60px;
    grid-template-columns: 1fr auto auto;
    gap: 12px;
    padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  }

  .brand {
    font-size: 0.82rem;
  }

  .product-brand {
    font-size: 0.74rem;
  }

  .brand-mark {
    width: 27px;
    height: 27px;
    border-radius: 8px;
  }

  .export-button {
    width: 34px;
    padding: 0;
    justify-content: center;
  }

  .export-button span {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 9px;
    padding: 9px max(9px, env(safe-area-inset-right)) calc(9px + env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
  }

  .board-wrap {
    grid-row: 1;
    border-radius: 14px;
  }

  .document-status {
    top: 11px;
    left: 11px;
    padding: 7px 10px;
    font-size: 0.64rem;
  }

  .toolbar {
    grid-row: 2;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 7px;
    overflow-x: auto;
    overflow-y: hidden;
    border-radius: 14px;
  }

  .tool-group {
    flex-direction: row;
    flex: 0 0 auto;
  }

  .tool-button {
    width: 52px;
    min-height: 48px;
    padding: 4px;
  }

  .tool-button svg {
    width: 19px;
    height: 19px;
  }

  .toolbar-divider {
    width: 1px;
    height: 36px;
  }

  .color-controls {
    flex: 0 0 104px;
  }

  .control-label {
    display: none;
  }

  .swatches {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow: hidden;
    padding: 4px;
  }

  .swatch,
  .custom-color {
    width: 25px;
    height: 25px;
    flex: 0 0 auto;
  }

  .swatches .swatch:nth-of-type(n+4) {
    display: none;
  }

  .size-control {
    width: 76px;
    flex: 0 0 auto;
  }

  .history-actions {
    flex-wrap: nowrap;
    flex: 0 0 auto;
  }

  .toolbar .icon-button {
    width: 38px;
    height: 38px;
  }

  .board-tip {
    display: none;
  }
}

@media (max-width: 1100px) {
  .site-nav {
    display: none;
  }
}

@media (max-width: 430px) {
  .tool-button span {
    display: none;
  }

  .tool-button {
    width: 42px;
    min-height: 40px;
  }

  .color-controls {
    flex-basis: 70px;
  }

  .swatches .swatch:nth-of-type(n+3) {
    display: none;
  }

  .size-control {
    width: 62px;
  }

  .toolbar .icon-button {
    width: 34px;
    height: 34px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
