/* ─────────────────────────────────────────────────────────
   DrawOnline — single stylesheet
   Dark-leaning neutral palette, focused on canvas tools.
   ───────────────────────────────────────────────────────── */

*,*::before,*::after { box-sizing: border-box; }

:root {
  --bg:           #15171c;
  --bg-elev:      #1c1f25;
  --bg-elev-2:    #232730;
  --panel:        #1a1d23;
  --border:       #2c313b;
  --border-soft:  #232730;
  --text:         #e5e7eb;
  --text-dim:     #a3a8b2;
  --text-muted:   #71757d;
  --accent:       #6c8cff;
  --accent-hov:   #88a2ff;
  --accent-soft:  rgba(108,140,255,0.12);
  --danger:       #ef5a6a;
  --ok:           #34c47a;
  --warn:         #f0b441;
  --radius:       6px;
  --radius-sm:    4px;
  --shadow:       0 2px 14px rgba(0,0,0,0.35);
  --mono:         ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans:         system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hov); text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.85rem; letter-spacing: -.01em; }
h2 { font-size: 1.35rem; letter-spacing: -.005em; }
h3 { font-size: 1.1rem; }
p  { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--border-soft); margin: 2rem 0; }

::selection { background: var(--accent-soft); color: var(--text); }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; }

/* ── HEADER ───────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(21,23,28,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
}
.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -.01em;
}
.logo:hover { color: var(--text); text-decoration: none; }
.logo img { display: block; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.site-nav a {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
}
.site-nav a:hover {
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 38px; height: 38px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
}
.nav-toggle span {
  display: block;
  width: 18px; height: 2px;
  margin: 0 auto;
  background: var(--text);
  border-radius: 1px;
}

@media (max-width: 720px) {
  .nav-toggle { display: flex; }
  .site-nav {
    position: absolute;
    top: 58px; left: 0; right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border-soft);
    padding: 8px;
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s, transform .15s, visibility .15s;
  }
  .site-nav.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
  .site-nav a { padding: 12px 14px; }
}

/* ── INTRO / HERO ─────────────────────────────────────── */
.intro {
  padding: 28px 0 14px;
}
.intro h1 {
  margin-bottom: .35em;
}
.intro .lede {
  color: var(--text-dim);
  max-width: 720px;
  font-size: 1rem;
}
.intro__row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.intro__row a {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: .9rem;
}
.intro__row a:hover {
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
  border-color: var(--accent);
}

/* ── DRAWING APP LAYOUT ────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 64px 1fr 280px;
  gap: 14px;
  margin: 14px 0 28px;
  min-height: 520px;
}
.app--narrow {
  grid-template-columns: 64px 1fr;
}
.app--single {
  display: block;
}
@media (max-width: 980px) {
  .app, .app--narrow {
    grid-template-columns: 1fr;
  }
}

.toolbar {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-self: start;
  position: sticky;
  top: 70px;
}
@media (max-width: 980px) {
  .toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
  }
}

.tool-btn {
  width: 46px; height: 46px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .12s, color .12s, border-color .12s;
}
.tool-btn:hover {
  background: var(--bg-elev);
  color: var(--text);
}
.tool-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.tool-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.tool-btn svg { width: 22px; height: 22px; }
.tool-btn[disabled] { opacity: .35; cursor: not-allowed; }

.tool-sep {
  display: block;
  height: 1px;
  background: var(--border-soft);
  margin: 4px 6px;
}
@media (max-width: 980px) {
  .tool-sep { width: 1px; height: 24px; margin: 0 4px; align-self: center; }
}

/* ── CANVAS STAGE ──────────────────────────────────────── */
.stage {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 520px;
  position: relative; /* anchor .stage__hint */
}
.stage__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  color: var(--text-dim);
  font-size: .88rem;
}
.stage__bar .group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.stage__bar .pill {
  background: var(--bg-elev);
  padding: 4px 8px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.stage__bar button {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  font-size: .85rem;
}
.stage__bar button:hover { color: var(--text); border-color: var(--accent); }

.stage__viewport {
  flex: 1;
  position: relative;
  overflow: auto;
  background:
    linear-gradient(45deg, #1a1d23 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d23 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d23 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d23 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-color: #16181d;
  padding: 24px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.stage__inner {
  position: relative;
  display: inline-block;
  background: #fff;
  box-shadow: 0 4px 22px rgba(0,0,0,0.45);
  transform-origin: 0 0;
}
.stage__inner canvas {
  display: block;
  cursor: crosshair;
  touch-action: none;
}
.stage__overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.stage__overlay canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.stage__text-input {
  position: absolute;
  background: rgba(255,255,255,0.96);
  color: #111;
  border: 1px dashed #6c8cff;
  outline: none;
  padding: 2px 4px;
  font-family: var(--sans);
  min-width: 80px;
  min-height: 1.4em;
  white-space: pre;
}

.stage__hint {
  position: absolute;
  left: 12px; bottom: 12px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  pointer-events: none;
  opacity: .85;
}

/* ── SIDEBAR / SETTINGS PANEL ──────────────────────────── */
.sidebar {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  align-self: start;
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 90px);
  overflow: auto;
}
@media (max-width: 980px) {
  .sidebar { position: static; max-height: none; }
}
.sidebar h3 {
  margin: 0 0 .6em;
  font-size: .82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}
.sidebar section { margin-bottom: 18px; }
.sidebar section:last-child { margin-bottom: 0; }

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: .8rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
}
.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-row > * { flex: 1; }
.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-dim);
}
.range-val {
  font-variant-numeric: tabular-nums;
  width: 38px;
  text-align: right;
  color: var(--text);
}

/* ── COLOR PICKERS ─────────────────────────────────────── */
.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.color-swatch {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  position: relative;
  background: #000;
}
.color-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
}
.color-swatch.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.color-hex {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: .85rem;
  text-transform: uppercase;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.swatches button {
  aspect-ratio: 1;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.25);
  padding: 0;
  cursor: pointer;
  transition: transform .1s;
}
.swatches button:hover { transform: scale(1.08); }
.swatches button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.recent {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  margin-top: 8px;
}
.recent button {
  aspect-ratio: 1;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.08);
  padding: 0;
  cursor: pointer;
}

/* ── BUTTONS (sidebar/general) ─────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .9rem;
  text-decoration: none;
}
.btn:hover {
  border-color: var(--accent);
  color: var(--text);
  text-decoration: none;
}
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn--primary:hover {
  background: var(--accent-hov);
  border-color: var(--accent-hov);
  color: #fff;
}
.btn--danger {
  border-color: rgba(239,90,106,0.45);
  color: var(--danger);
}
.btn--danger:hover {
  background: rgba(239,90,106,0.1);
  border-color: var(--danger);
}
.btn--block { display: flex; width: 100%; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.btn-row .btn { flex: 1; }

/* ── SEGMENTED CONTROL ─────────────────────────────────── */
.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented button {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  padding: 6px 10px;
  font-size: .85rem;
}
.segmented button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ── FILE DROP ZONE (draw-on-image) ────────────────────── */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  transition: background .15s, border-color .15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone.is-drag {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

/* ── CONTENT SECTIONS ──────────────────────────────────── */
.section { padding: 36px 0; }
.section + .section { border-top: 1px solid var(--border-soft); }
.section h2 { margin-bottom: .5em; }
.section .lede { color: var(--text-dim); max-width: 720px; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--text);
  text-decoration: none;
  transition: border-color .15s, transform .15s;
}
.card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}
.card h3 { margin: 0 0 .4em; }
.card p { color: var(--text-dim); margin: 0; font-size: .92rem; }

.faq-item {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  margin-bottom: 8px;
  padding: 0;
}
.faq-item summary {
  cursor: pointer;
  list-style: none;
  padding: 14px 16px;
  font-weight: 500;
  position: relative;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
  content: '+';
  position: absolute;
  right: 16px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.2rem;
}
.faq-item[open] summary::after { content: '–'; }
.faq-item .faq-body,
.faq-item > p {
  padding: 0 16px 14px;
  color: var(--text-dim);
  margin: 0;
}

/* ── BREADCRUMB ────────────────────────────────────────── */
.breadcrumb {
  color: var(--text-muted);
  font-size: .85rem;
  margin: 18px 0 0;
}
.breadcrumb a { color: var(--text-dim); }
.breadcrumb .sep { margin: 0 6px; }

/* ── LEGAL / PROSE PAGES ───────────────────────────────── */
.prose {
  max-width: 760px;
  padding: 24px 0 48px;
}
.prose h2 { margin-top: 2em; }
.prose ul { padding-left: 1.2em; }
.prose li { margin-bottom: .4em; color: var(--text); }
.prose a { color: var(--accent); }

/* ── FOOTER ────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border-soft);
  background: var(--bg-elev);
  margin-top: 40px;
  padding: 28px 0 14px;
}
.footer-inner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 24px;
}
.footer-col { display: flex; flex-direction: column; }
.footer-col strong {
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.footer-col a {
  color: var(--text-dim);
  text-decoration: none;
  padding: 3px 0;
  font-size: .92rem;
}
.footer-col a:hover { color: var(--text); }
.footer-col--about p { color: var(--text-dim); font-size: .92rem; margin: 0; }

.footer-bottom {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

/* ── TOAST ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 80;
  font-size: .9rem;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── DIALOG / MODAL ────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.modal[hidden] { display: none; }
.modal__box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.modal__box h3 { margin: 0 0 .5em; }
.modal__box p { color: var(--text-dim); margin: 0 0 16px; }
.modal__actions {
  display: flex; gap: 8px; justify-content: flex-end;
}

/* ── PIXEL ART ─────────────────────────────────────────── */
.pixel-stage {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  min-height: 460px;
  display: flex;
  flex-direction: column;
}
.pixel-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  overflow: auto;
  background-color: #16181d;
  background-image:
    linear-gradient(45deg, #1a1d23 25%, transparent 25%),
    linear-gradient(-45deg, #1a1d23 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1d23 75%),
    linear-gradient(-45deg, transparent 75%, #1a1d23 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.pixel-inner {
  position: relative;
  display: inline-block;
  background-image:
    linear-gradient(45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(-45deg, #d8d8d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8d8d8 75%),
    linear-gradient(-45deg, transparent 75%, #d8d8d8 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #fff;
  box-shadow: 0 6px 30px rgba(0,0,0,0.4);
  image-rendering: pixelated;
}
.pixel-inner canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
  cursor: crosshair;
}
.pixel-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, rgba(0,0,0,0.18) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(0,0,0,0.18) 1px, transparent 1px);
  background-repeat: repeat;
}

/* ── HELP / TIPS ───────────────────────────────────────── */
.section-pad { padding: 36px 0; }
.section-pad + .section-pad { border-top: 1px solid var(--border-soft); }

.tips {
  background: var(--bg-elev);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text-dim);
  font-size: .9rem;
  margin-top: 16px;
}
.tips strong { color: var(--text); }
.tips ul { margin: .4em 0 0; padding-left: 1.2em; }
.tips li { margin-bottom: .3em; }

/* ── MOBILE / RESPONSIVE ───────────────────────────────── */
@media (max-width: 680px) {
  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.15rem; }
  .container { padding: 0 12px; }

  .app {
    gap: 8px;
    margin: 8px 0 16px;
  }

  .stage {
    min-height: 300px;
  }
  .stage__viewport {
    padding: 10px;
    min-height: 240px;
  }
  /* stage bar: horizontal scroll when many buttons */
  .stage__bar {
    padding: 6px 8px;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .stage__bar .group {
    flex-shrink: 0;
  }
  .stage__bar button,
  .stage__bar .pill {
    padding: 4px 7px;
    font-size: .78rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .stage__hint {
    font-size: .75rem;
    padding: 4px 8px;
  }
  .tool-btn { width: 40px; height: 40px; }

  /* sidebar: two-column grid on mobile for compact layout */
  .sidebar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 10px;
    position: static;
    max-height: none;
  }
  .sidebar .section:last-child { margin-bottom: 0; }

  .section-pad { padding: 22px 0; }
  .cards { grid-template-columns: 1fr; }

  /* modal: full-width on phone */
  .modal { padding: 12px; }
  .modal__box { padding: 16px; }
  .btn-row--wrap { flex-direction: column; }
  .btn-row--wrap .btn { flex: none; }
}

/* ── UTIL ──────────────────────────────────────────────── */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); }
.tabular { font-variant-numeric: tabular-nums; }
.kbd {
  font-family: var(--mono);
  background: var(--bg);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: .82em;
  color: var(--text);
}
