:root {
  --brand: #c8102e;
  --brand-dark: #8b0000;
  --bg: #0f1216;
  --panel: #1a1f26;
  --panel-2: #242b34;
  --border: #2e3742;
  --text: #eef2f7;
  --muted: #8a94a3;
  --accent: #3b82f6;
  --success: #16a34a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Auth pages */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #1c2330 0%, var(--bg) 70%);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.auth-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.auth-logo img { max-width: 180px; height: auto; }
.auth-card h1 { margin: 0 0 8px; text-align: center; font-size: 22px; }
.auth-card p.sub { text-align: center; color: var(--muted); margin-top: 0; }

.form-row { display: flex; flex-direction: column; margin-bottom: 14px; }
.form-row label { font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.form-row input, .form-row textarea, .form-row select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border .15s;
}
.form-row input:focus, .form-row textarea:focus { border-color: var(--brand); }

.btn {
  background: var(--brand);
  color: #fff;
  border: 0;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background .15s;
}
.btn:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.danger { background: #b91c1c; }
.btn.small { width: auto; padding: 8px 12px; font-size: 13px; }

.error { color: #ff6868; font-size: 14px; margin-top: 8px; min-height: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.center { text-align: center; }
.mt-16 { margin-top: 16px; }

/* Layout */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}
.topbar .brand img { height: 36px; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }
.topbar .user { color: var(--muted); font-size: 13px; }

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

.h-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 8px; flex-wrap: wrap; }
.h-row h2 { margin: 0; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card h3 { margin: 0; font-size: 16px; }
.card .thumb {
  background: #fff;
  border-radius: 6px;
  aspect-ratio: 16/10;
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
}
.card .meta { color: var(--muted); font-size: 12px; }
.card .row { display: flex; gap: 6px; }
.card .row .btn { flex: 1; }

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* Drawing page */
.draw-wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.draw-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px;
}
.tool-group {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.tool-btn {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  min-width: 40px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 500;
}
.tool-btn:hover { background: var(--border); }
.tool-btn.active { background: var(--brand); color: #fff; }
.tool-btn svg { width: 20px; height: 20px; }

.spacer { flex: 1; }

.canvas-container-wrap {
  flex: 1;
  background: #cfd6de;
  overflow: auto;
  position: relative;
  /* Allow native two-finger pan/pinch on touch devices */
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
}
/* Custom, more visible scrollbars (especially on Windows) */
.canvas-container-wrap::-webkit-scrollbar { width: 14px; height: 14px; }
.canvas-container-wrap::-webkit-scrollbar-track { background: #a9b2bb; }
.canvas-container-wrap::-webkit-scrollbar-thumb {
  background: #5b6673;
  border-radius: 4px;
  border: 2px solid #a9b2bb;
}
.canvas-container-wrap::-webkit-scrollbar-thumb:hover { background: #3f4a57; }

#canvasHost {
  /* Width/height are set by JS based on zoom, so scrollbars appear when needed */
  padding: 24px;
  min-width: 100%;
  min-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}
.canvas-page {
  background: #ffffff;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  position: relative;
  flex-shrink: 0;
}
.canvas-page canvas { display: block; }

.bottom-bar {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  align-items: center;
  flex-wrap: wrap;
}
.bottom-bar label { font-size: 12px; color: var(--muted); }
.bottom-bar input[type="text"], .bottom-bar input[type="number"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 14px;
}
.bottom-bar input[type="color"] {
  background: transparent;
  border: 1px solid var(--border);
  width: 44px;
  height: 36px;
  padding: 2px;
  border-radius: 6px;
}
.bottom-bar input[type="range"] { width: 100px; }
.stroke-preview {
  width: 24px; height: 24px; border-radius: 50%; background: #111;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border);
}

/* Modal */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 16px;
}
.modal-back.show { display: flex; }
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 460px;
}
.modal h3 { margin-top: 0; }
.modal .row-btns { display: flex; gap: 8px; margin-top: 12px; }
.modal .row-btns .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #111;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 300;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; }

/* Mobile tweaks */
@media (max-width: 720px) {
  .topbar .brand span { display: none; }
  .tool-btn { padding: 6px 8px; font-size: 12px; min-width: 36px; min-height: 36px; }
  .tool-btn .tool-label { display: none; }
  .bottom-bar { padding: 6px; }
  .bottom-bar input[type="range"] { width: 80px; }
}
