:root {
  color-scheme: light;
  --bg-base: #f6f2ea;
  --bg-soft: #f2f7fb;
  --panel: #fefcf8;
  --panel-border: #e5e0d8;
  --ink: #111827;
  --muted: #5f6b7a;
  --accent: #f97316;
  --accent-dark: #d3540c;
  --accent-cool: #2563eb;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-pill: 999px;
  --grid-line: rgba(17, 24, 39, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Avenir", "Futura", "Gill Sans", "Trebuchet MS",
    sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 10%, #fff0d5 0%, transparent 45%),
    radial-gradient(circle at 80% 20%, #dbeafe 0%, transparent 40%),
    linear-gradient(135deg, var(--bg-base), var(--bg-soft));
  position: relative;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  opacity: 0.45;
}

body::after {
  content: "";
  position: fixed;
  inset: -20% 0 0 0;
  background: radial-gradient(circle at 70% 0%, rgba(249, 115, 22, 0.12), transparent 55%);
  pointer-events: none;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: relative;
  z-index: 1;
}

.app-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  animation: fadeUp 0.8s ease forwards;
}

.logo {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  object-fit: cover;
  background: #fff;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.brand-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  margin: 0;
}

.board-section {
  display: block;
}

.board-shell {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.9s ease forwards;
  position: relative;
  overflow: hidden;
}

.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--ink);
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.2);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.color-swatch.is-active {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  transform: translateY(-1px) scale(1.05);
}

.color-swatch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.canvas-wrap {
  position: relative;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  background: repeating-linear-gradient(
      0deg,
      rgba(15, 23, 42, 0.04) 0,
      rgba(15, 23, 42, 0.04) 1px,
      transparent 1px,
      transparent 24px
    ),
    repeating-linear-gradient(
      90deg,
      rgba(15, 23, 42, 0.04) 0,
      rgba(15, 23, 42, 0.04) 1px,
      transparent 1px,
      transparent 24px
    ),
    #fff;
  height: clamp(320px, 58vh, 560px);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: contain;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.canvas-overlay {
  position: absolute;
  pointer-events: none;
  z-index: 2;
}

.canvas-overlay button {
  pointer-events: auto;
}

.toolbar-left {
  top: 14px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar-bottom {
  left: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--radius-pill);
  border: 1px solid rgba(15, 23, 42, 0.12);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.tool-icon {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: #fff;
  color: var(--ink);
  display: grid;
  place-items: center;
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tool-icon svg {
  width: 18px;
  height: 18px;
}

.tool-icon:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.16);
}

.tool-icon.is-active {
  background: var(--ink);
  color: #fff;
  border-color: transparent;
}

.tool-icon:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.busy-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: rgba(255, 255, 255, 0.75);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  font-weight: 600;
  z-index: 3;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(37, 99, 235, 0.2);
  border-top-color: var(--accent-cool);
  animation: spin 1s linear infinite;
}

.app[data-busy="true"] .busy-overlay {
  opacity: 1;
  pointer-events: all;
}

.app[data-busy="true"] canvas {
  pointer-events: none;
}

.board-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.status {
  font-size: 13px;
  color: var(--muted);
}

.status[data-tone="warn"] {
  color: #b45309;
}

.status[data-tone="error"] {
  color: #b91c1c;
}

.status[data-tone="ok"] {
  color: #047857;
}

.actions {
  display: flex;
  gap: 10px;
}

.btn {
  border-radius: var(--radius-pill);
  padding: 10px 14px;
  font-weight: 700;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn.ghost {
  background: #fff;
  border-color: var(--panel-border);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(249, 115, 22, 0.3);
}

.btn.primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.app-footer a {
  color: inherit;
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

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

.is-hidden {
  display: none !important;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 960px) {
  .brand-title {
    font-size: 18px;
  }
}

@media (max-width: 720px) {
  .app {
    padding: 24px 16px;
  }

  .app-header {
    justify-content: center;
  }

  .brand-title {
    font-size: 16px;
  }

  .board-shell {
    padding: 16px;
  }

  .actions {
    width: 100%;
    justify-content: flex-end;
  }

  .tool-icon {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .tool-icon svg {
    width: 16px;
    height: 16px;
  }

  .color-swatch {
    width: 22px;
    height: 22px;
  }

  .toolbar-left {
    top: 10px;
    left: 10px;
  }

  .toolbar-bottom {
    left: 10px;
    bottom: 10px;
    padding: 5px 8px;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
  }

  .btn-icon svg {
    width: 18px;
    height: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
