:root {
  --bg-page: #fdf6ee;
  --bg-surface: #ffffff;
  --bg-surface-2: #fff0e6;
  --bg-surface-3: #f0ebf8;
  --accent-primary: #cc785c;
  --accent-primary-hover: #b8634a;
  --accent-secondary: #8b7ec8;
  --accent-tertiary: #5b9bd5;
  --accent-green: #6baf7a;
  --accent-yellow: #e8c547;
  --text-primary: #2d2418;
  --text-secondary: #6b5744;
  --text-muted: #a08878;
  --text-on-accent: #ffffff;
  --border: #e8d5c4;
  --border-strong: #c4a882;
  --shadow-sm: 2px 2px 0 #c4a882;
  --shadow-md: 3px 3px 0 #c4a882;
  --shadow-lg: 5px 5px 0 #c4a882;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 22px;
  --radius-pill: 999px;
  --font-display: 'Georgia', 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, sans-serif;
  --font-mono: 'Courier New', monospace;
  --transition: 0.18s ease;
  --transition-slow: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

body.dark-mode {
  --bg-page: #1e1812;
  --bg-surface: #2a2118;
  --bg-surface-2: #332920;
  --bg-surface-3: #2e2440;
  --accent-primary: #e8937a;
  --accent-primary-hover: #f0a890;
  --text-primary: #f5ede4;
  --text-secondary: #c4a882;
  --text-muted: #8a7060;
  --border: #3d3028;
  --border-strong: #6b5040;
  --shadow-sm: 2px 2px 0 #0a0806;
  --shadow-md: 3px 3px 0 #0a0806;
  --shadow-lg: 5px 5px 0 #0a0806;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
}
a { color: inherit; }
.visually-hidden { position: absolute; opacity: 0; pointer-events: none; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-surface-2); }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

#appHeader {
  height: 60px;
  background: var(--bg-surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.site-logo {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  transition: transform var(--transition);
}
.site-logo:hover { transform: scale(1.02); }
.logo-icon { margin-right: 8px; font-size: 1.2rem; }
.logo-text { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.logo-tld { color: var(--accent-primary); font-size: 1rem; }

#mainNav { display: none; align-items: center; gap: 4px; }
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all var(--transition);
}
.nav-link:hover, .nav-link:focus-visible { background: var(--bg-surface-2); color: var(--accent-primary); }
.nav-link.active { background: var(--accent-primary); color: var(--text-on-accent); box-shadow: var(--shadow-sm); }
.nav-link--small { font-size: .65rem; opacity: .7; }

.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.hamburger-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-sm);
  background: var(--bg-surface);
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
}
.hamburger-btn span {
  width: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--text-primary);
  transition: transform var(--transition), opacity var(--transition);
}
.hamburger-btn.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger-btn.is-open span:nth-child(2) { opacity: 0; }
.hamburger-btn.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 90vw);
  height: 100vh;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(0.32,0.72,0,1);
  background: var(--bg-surface-2);
  border-left: 3px solid var(--border-strong);
  box-shadow: -5px 0 20px rgba(0,0,0,.15);
  z-index: 80;
}
.mobile-drawer.open { transform: translateX(0); }
.drawer-inner { padding: 24px; display: flex; flex-direction: column; height: 100%; }
.drawer-close { align-self: flex-end; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border); background: var(--bg-surface-3); margin-bottom: 24px; }
.drawer-link { display: block; padding: 14px 16px; margin-bottom: 4px; border-radius: var(--radius-md); text-decoration: none; font-weight: 600; }
.drawer-link:hover { background: var(--bg-surface-3); color: var(--accent-primary); }
.drawer-footer { margin-top: auto; padding-top: 24px; border-top: 2px dashed var(--border); font-size: .8rem; color: var(--text-muted); text-align: center; }
.drawer-backdrop, #overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(2px);
  z-index: 70;
}
#overlay.hidden, .drawer-backdrop.hidden { display: none; }

.view { animation: view-fade .2s ease; }
@keyframes view-fade { from { opacity: 0; transform: translateY(15px);} to { opacity: 1; transform: translateY(0);} }

#homeView { max-width: 1200px; margin: 0 auto; padding: 30px 24px 60px; }
.home-hero { margin-bottom: 32px; }
.hero-title { font-family: var(--font-display); font-size: clamp(3rem, 8vw, 6rem); line-height: 1.05; margin: 0; }
.hero-title span:nth-child(1) { color: var(--accent-primary); }
.hero-title span:nth-child(2) { color: var(--accent-secondary); }
.hero-title span:nth-child(3) { color: var(--accent-tertiary); }
.hero-sub { font-size: 1.1rem; color: var(--text-secondary); max-width: 400px; margin-top: 16px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 32px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font: 600 .85rem var(--font-body);
  text-transform: uppercase;
  letter-spacing: .04em;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary, .btn.accent { background: var(--accent-primary); color: #fff; border-color: var(--accent-primary-hover); }
.btn-primary:hover, .btn.accent:hover { background: var(--accent-primary-hover); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.btn-secondary { background: transparent; color: var(--accent-primary); border-color: var(--accent-primary); }
.btn-secondary:hover { background: var(--bg-surface-2); box-shadow: var(--shadow-sm); }
.btn-ghost, .btn:not(.btn-primary):not(.btn-secondary):not(.accent) { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover, .btn:not(.btn-primary):not(.btn-secondary):not(.accent):hover { background: var(--bg-surface-2); color: var(--text-primary); }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-sm { padding: 6px 14px; font-size: .7rem; }

.home-features { display: grid; gap: 16px; }
.feature-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}
.feature-card:hover { box-shadow: var(--shadow-md); transform: translateY(-3px); border-color: var(--border-strong); }
.feature-icon { font-size: 2rem; display: block; margin-bottom: 12px; }
.feature-card h3 { font-family: var(--font-display); font-size: 1.1rem; margin: 0 0 8px; }
.feature-card p { margin: 0; color: var(--text-secondary); font-size: .9rem; }

#editorView { min-height: calc(100vh - 60px); display: flex; flex-direction: column; position: relative; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  background: var(--bg-surface);
}
.canvas-title { font-family: var(--font-display); font-style: italic; font-size: 1.1rem; background: var(--bg-surface-2); border: 2px dashed var(--border); border-radius: var(--radius-pill); padding: 5px 12px; min-width: 120px; }
.topbar-actions { display: flex; gap: 6px; }
.chip { border: 2px solid var(--border); background: var(--bg-surface-2); border-radius: var(--radius-pill); padding: 6px 12px; font-size: .75rem; }

.editor-shell { display: flex; flex: 1; min-height: 0; }
.sidebar.left { width: 72px; background: var(--bg-surface-2); border-right: 2px solid var(--border); padding: 12px 8px; display: none; flex-direction: column; }
.sidebar.left .logo { font-size: 0; margin-bottom: 10px; }
.tool-list { display: flex; flex-direction: column; gap: 8px; }
.tool-btn { width: 52px; height: 52px; padding: 0; border-radius: var(--radius-md); background: transparent; border: 2px solid transparent; font-size: 0; position: relative; box-shadow: none; }
.tool-btn::before { content: attr(aria-label); display: none; }
.tool-btn::after {
  content: attr(aria-label);
  position: absolute;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--text-primary);
  color: var(--bg-page);
  font-size: .7rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}
.tool-btn:hover::after { opacity: 1; }
.tool-btn:hover { background: var(--bg-surface-3); border-color: var(--border); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.tool-btn.active { background: var(--accent-primary); border-color: var(--accent-primary-hover); box-shadow: var(--shadow-md); color: #fff; transform: scale(1.05); }
.tool-btn span { display: none; }

.sidebar .panel { background: transparent; border: 0; padding: 0; }
.brush-settings label { display: block; font-size: .65rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; margin: 10px 0 4px; }
input[type='range'] { width: 100%; accent-color: var(--accent-primary); }
input[type='range']::-webkit-slider-thumb { width: 20px; height: 20px; border-radius: 50%; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }

.workspace {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 20px;
}
.workspace.checkerboard {
  background-image: linear-gradient(45deg, #f0ebe3 25%, transparent 25%), linear-gradient(-45deg, #f0ebe3 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e8ddd4 75%), linear-gradient(-45deg, transparent 75%, #e8ddd4 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}
body.dark-mode .workspace.checkerboard { background: var(--bg-surface-2); }
.canvas-container { position: relative; border: 2px solid var(--border); box-shadow: var(--shadow-lg); background: #fff; transform-origin: top left; }
.canvas-container canvas { position: absolute; top: 0; left: 0; }
.shape-tooltip { position: absolute; font-size: .72rem; background: var(--text-primary); color: var(--bg-page); padding: 4px 8px; border-radius: var(--radius-sm); }

.sidebar.right { width: 260px; background: var(--bg-surface); border-left: 2px solid var(--border); padding: 16px; overflow-y: auto; display: none; }
.active-swatch { width: 100%; height: 64px; border: 2px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-md); }
#nativeColorInput, #mobileColorInput { width: 100%; height: 36px; margin: 8px 0; }
.swatch-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.swatch-row button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); }
.palette-group { margin: 12px 0; border-top: 1px dashed var(--border); padding-top: 12px; }
.palette-group h5 { font-size: .65rem; letter-spacing: .08em; color: var(--text-muted); margin: 0 0 6px; text-transform: uppercase; }
.palette-swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.palette-swatches button { width: 28px; height: 28px; border-radius: var(--radius-sm); border: 2px solid transparent; }
.palette-swatches button:hover { border-color: var(--border-strong); transform: scale(1.15); box-shadow: var(--shadow-sm); }
.palette-swatches button.active { border-color: var(--text-primary); transform: scale(1.2); box-shadow: var(--shadow-md); }

.bottom-toolbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  border-top: 2px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.bottom-toolbar .icon-btn { width: 48px; height: 48px; box-shadow: none; border-color: transparent; }
.bottom-toolbar .icon-btn.active { background: var(--accent-primary); color: #fff; }

#galleryView { padding: 24px; max-width: 1300px; margin: 0 auto; }
.gallery-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gallery-header h2 { font-family: var(--font-display); font-size: 2rem; margin: 0; }
.gallery-grid { display: grid; gap: 20px; padding-top: 20px; grid-template-columns: 1fr; }
.drawing-card {
  background: var(--bg-surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}
.drawing-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-4px); border-color: var(--border-strong); }

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(45,36,24,.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg-surface);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: min(440px, 90vw);
  box-shadow: var(--shadow-lg);
  animation: modal-in .25s var(--transition-slow);
}
@keyframes modal-in { from { opacity: 0; transform: scale(.92) translateY(8px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.toast {
  position: fixed;
  right: 24px;
  bottom: 80px;
  background: var(--text-primary);
  color: var(--bg-page);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 12px 18px;
  font-size: .85rem;
  z-index: 2000;
}
.toast.hidden { display: none; }

#siteFooter {
  background: var(--bg-surface-2);
  border-top: 2px solid var(--border);
  padding: 40px 0 24px;
}
.footer-inner { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.footer-brand .site-logo { font-family: var(--font-display); font-size: 1.2rem; }
.footer-brand .site-logo span { color: var(--accent-primary); }
.footer-brand p { margin-top: 8px; font-size: .85rem; color: var(--text-muted); }
.footer-nav { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 24px 0; }
.footer-nav a { font-size: .8rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; text-decoration: none; color: var(--text-secondary); }
.footer-nav a:hover { color: var(--accent-primary); }
.footer-copy { font-size: .75rem; color: var(--text-muted); border-top: 1px dashed var(--border); padding-top: 16px; margin-top: 8px; }

.page-hero { background: var(--bg-surface-2); padding: 60px 24px; text-align: center; }
.page-hero h1 { font-family: var(--font-display); font-size: clamp(2rem, 5vw, 3.5rem); margin: 0; }
.page-hero p { margin: 10px 0 0; color: var(--text-secondary); }
.page-content { max-width: 720px; margin: 0 auto; padding: 48px 24px; }
.page-content h2 { font-family: var(--font-display); font-size: 1.5rem; color: var(--accent-primary); margin-top: 40px; padding-bottom: 8px; border-bottom: 2px dashed var(--border); }
.page-content p { color: var(--text-secondary); line-height: 1.75; margin-bottom: 16px; }
.page-content ul { list-style: none; padding: 0; }
.page-content li { border-left: 3px solid var(--accent-primary); padding: 8px 16px; border-radius: var(--radius-sm); background: var(--bg-surface-2); margin-bottom: 8px; }
.email-card { background: var(--bg-surface); border: 2px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 20px; }
.email-block { font: 700 clamp(1.1rem, 3vw, 1.6rem) var(--font-mono); margin: 0 0 10px; word-break: break-all; }

@media (min-width: 640px) {
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .home-features { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  #mainNav { display: flex; }
  .hamburger-btn { display: none; }
  .sidebar.left, .sidebar.right { display: flex; }
  .mobile-only, .bottom-toolbar { display: none !important; }
  .editor-shell { height: calc(100vh - 108px); }
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
  .toast { bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; transform: none !important; }
  .view { animation: none; }
}
