/* Paint — styles. No inline styles are used (strict CSP). */
:root {
  --bg: #e8ecf3;
  --panel: #f7f8fb;
  --ink: #1d2433;
  --muted: #5b6577;
  --line: #c9d0dc;
  --accent: #2f6fde;
  --accent-ink: #fff;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #b26a00;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; }
.hidden { display: none !important; }
.view { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#loading { align-items: center; justify-content: center; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink); font: inherit; font-size: 14px; line-height: 1.2;
  cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none;
}
.btn:hover { border-color: #9aa6ba; background: #f2f5fa; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #255bbb; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: #fdecec; border-color: var(--danger); }
.btn.big { padding: 12px 28px; font-size: 17px; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 5px 10px; font-size: 18px; min-width: 38px; }

input, button { font: inherit; }
input[type=text], input:not([type]), input[type=number] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0;
}

/* Sign-in */
#signin { align-items: center; justify-content: center; background: linear-gradient(135deg, #dfe9ff, #fdf0e3); }
.welcome {
  max-width: 520px; padding: 40px 44px; background: #fff; border-radius: 16px; text-align: center;
  box-shadow: 0 10px 40px rgba(30, 50, 90, .15);
}
.welcome-logo { width: 88px; height: 88px; }
.welcome h1 { margin: 12px 0 4px; font-size: 34px; }
.lead { color: var(--muted); font-size: 17px; margin: 0 0 20px; }
.features { text-align: left; margin: 0 auto 28px; padding-left: 22px; color: var(--ink); line-height: 1.7; max-width: 380px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; flex-wrap: wrap;
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.brand img { width: 28px; height: 28px; }
.spacer { flex: 1; }
.me { color: var(--muted); font-size: 14px; }
.title-btn {
  border: 1px solid transparent; background: none; font: inherit; font-weight: 600; font-size: 16px;
  padding: 5px 8px; border-radius: 6px; cursor: text; max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.title-btn:hover { border-color: var(--line); background: #fff; }
.save-status { font-size: 13px; color: var(--muted); padding: 3px 8px; border-radius: 12px; white-space: nowrap; }
.save-status.ok { color: var(--ok); }
.save-status.dirty, .save-status.saving { color: var(--warn); }
.save-status.error, .save-status.conflict { color: #fff; background: var(--danger); }

/* Dashboard */
.dash { flex: 1; overflow: auto; padding: 22px 28px 40px; }
.dash-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.dash-head h2 { margin: 0; }
.msg { padding: 8px 12px; border-radius: 6px; background: #e7f2e8; color: var(--ok); margin: 6px 0 12px; }
.msg.error { background: #fdecec; color: var(--danger); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.card { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(30, 50, 90, .1); overflow: hidden; display: flex; flex-direction: column; }
.thumb {
  display: flex; align-items: center; justify-content: center; height: 160px; padding: 8px;
  background: repeating-conic-gradient(#eef1f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; text-decoration: none;
}
.thumb img { max-width: 100%; max-height: 100%; box-shadow: 0 0 0 1px var(--line); background: #fff; }
.noimg { color: var(--muted); font-size: 14px; }
.card-info { padding: 10px 12px 4px; }
.card-title { margin: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 12px; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }

/* Editor */
.workspace { flex: 1; display: flex; min-height: 0; }
.toolbar {
  width: 112px; flex: none; padding: 10px 8px; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 14px; overflow-y: auto;
}
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.tools button {
  height: 42px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 19px; cursor: pointer; padding: 0;
}
.tools button:hover { border-color: #9aa6ba; }
.tools button.active { background: #d9e6ff; border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.opt { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.opt input[type=range] { width: 100%; }
.opt label { display: flex; align-items: center; gap: 4px; }
.opt.zoom { flex-direction: row; align-items: center; gap: 3px; }
.opt.zoom .btn { padding: 3px 7px; }
#zoom-val { flex: 1; min-width: 0; padding: 3px 2px; font-size: 12px; }

.viewport {
  flex: 1; overflow: auto; position: relative; min-width: 0;
  background: #aab3c3; display: flex; padding: 16px;
}
.stage {
  position: relative; margin: auto; flex: none; background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage.pixelated canvas { image-rendering: pixelated; }
#overlay { touch-action: none; cursor: crosshair; }
.stage[data-tool=text] #overlay { cursor: text; }
.stage[data-tool=fill] #overlay, .stage[data-tool=picker] #overlay { cursor: cell; }
.text-input {
  position: absolute; z-index: 2; min-width: 120px; padding: 0 2px; margin: 0;
  border: 1px dashed var(--accent); background: rgba(255, 255, 255, .6); font-family: sans-serif; line-height: 1.2;
  outline: none;
}

/* Palette */
.palette-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--panel);
  border-top: 1px solid var(--line); flex-wrap: wrap;
}
.current { position: relative; width: 44px; height: 40px; flex: none; }
.swatch { width: 22px; height: 22px; border: 1px solid #556; border-radius: 3px; padding: 0; cursor: pointer; }
.swatch:hover { transform: scale(1.12); }
.current .swatch { position: absolute; width: 28px; height: 28px; }
.primary-sw { left: 0; top: 0; z-index: 1; box-shadow: 0 0 0 2px #fff; }
.secondary-sw { right: 0; bottom: 0; }
.palette { display: grid; grid-template-columns: repeat(10, 22px); grid-auto-rows: 22px; gap: 3px; }
.palette-bar input[type=color] { width: 28px; height: 24px; border: none; padding: 0; background: none; cursor: pointer; }
.pos { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 90px; text-align: right; }

/* Dialogs */
dialog {
  border: none; border-radius: 12px; padding: 22px 24px; width: min(520px, 94vw);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); color: var(--ink);
}
dialog::backdrop { background: rgba(20, 30, 50, .45); }
dialog h3 { margin: 0 0 12px; }
dialog label { display: block; margin: 10px 0 4px; font-size: 14px; }
menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 18px 0 0; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row input { flex: 1; }
.row label { margin: 0; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.hint { color: var(--muted); font-size: 13px; }
.share-new { background: #eef4ff; border-radius: 8px; padding: 6px 12px; margin: 10px 0; }
.share-new p { margin: 6px 0 0; font-size: 14px; }
.share-list { list-style: none; padding: 0; margin: 12px 0 0; max-height: 240px; overflow: auto; }
.share-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid #e4e8ef; }
.share-list li.revoked { opacity: .55; }
.share-info { flex: 1; min-width: 0; font-size: 14px; }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; }
.keys td { padding: 5px 8px; border-bottom: 1px solid #e4e8ef; }
.keys td:first-child { font-family: ui-monospace, monospace; white-space: nowrap; color: var(--accent); }

/* Public share page */
body.share { overflow: auto; display: flex; flex-direction: column; min-height: 100vh; }
.share-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.share-head h1 { margin: 0; font-size: 20px; }
.share-head p { margin: 0; color: var(--muted); font-size: 14px; }
.share-body { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; background: #aab3c3; }
.share-img { max-width: 100%; height: auto; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .35); }
.share-foot { text-align: center; padding: 10px; color: var(--muted); font-size: 13px; }

@media (max-width: 720px) {
  .workspace { flex-direction: column; }
  .toolbar { width: auto; flex-direction: row; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--line); gap: 8px; }
  .tools { grid-template-columns: repeat(9, 38px); }
  .tools button { height: 36px; font-size: 17px; }
  .opt { min-width: 110px; }
  .palette { grid-template-columns: repeat(10, 20px); grid-auto-rows: 20px; }
  .title-btn { max-width: 40vw; }
}
