/* ============================================================
   Giấy Nháp Online — giao diện
   Phong cách: sáng, gọn; giấy trắng rộng tối đa
   ============================================================ */
:root {
  --bar:       #ffffff;
  --bar-line:  #e6e9ef;
  --ink:       #1c2530;
  --ink-2:     #5a6675;
  --muted:     #f1f3f7;
  --muted-2:   #e9edf3;
  --primary:   #2f6bff;
  --primary-l: #e7efff;
  --danger:    #e5484d;
  --danger-l:  #fdecec;

  --paper:     #ffffff;
  --paper-edge:#dfe3ea;
  --grid:      #e4e9f2;
  --line:      #e0e7f5;

  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #eef1f6;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}

/* ---------- Thanh công cụ ---------- */
.bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bar);
  border-bottom: 1px solid var(--bar-line);
  padding: 8px 10px;
  box-shadow: 0 1px 4px rgba(28,37,48,.05);
  z-index: 10;
}

.back {
  flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font); font-size: 14px; font-weight: 800;
  color: var(--ink-2);
  background: var(--muted);
  border: none; border-radius: 9px;
  padding: 9px 13px 9px 10px; cursor: pointer;
  transition: color .15s, background .15s;
}
.back:hover { color: var(--primary); background: var(--primary-l); }
.back:active { transform: scale(.97); }

.bar__scroll {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin;
  padding-bottom: 2px;
  flex: 1;
}
.bar__scroll::-webkit-scrollbar { height: 5px; }
.bar__scroll::-webkit-scrollbar-thumb { background: var(--muted-2); border-radius: 3px; }

.grp {
  display: inline-flex; align-items: center; gap: 3px;
  padding-right: 6px; margin-right: 2px;
  border-right: 1px solid var(--bar-line);
  flex-shrink: 0;
}
.grp:last-child { border-right: none; }

.tool, .btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px;
  border: none; border-radius: 9px;
  background: transparent; color: var(--ink-2);
  cursor: pointer;
  transition: background .15s, color .15s, transform .04s;
}
.tool:hover, .btn:hover { background: var(--muted); color: var(--ink); }
.tool:active, .btn:active { transform: scale(.92); }
.tool.is-on { background: var(--primary); color: #fff; }
.btn--danger:hover { background: var(--danger-l); color: var(--danger); }

/* Màu */
.swatch {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: 9px; cursor: pointer;
  overflow: hidden; position: relative;
}
.swatch input[type="color"] {
  width: 30px; height: 30px; border: none; border-radius: 8px;
  padding: 0; background: none; cursor: pointer;
}
.swatch input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type="color"]::-webkit-color-swatch { border: 2px solid #fff; border-radius: 7px; box-shadow: 0 0 0 1px var(--bar-line); }

.colors { display: inline-flex; gap: 3px; }
.dot {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--bar-line);
  cursor: pointer; transition: transform .1s;
}
.dot:hover { transform: scale(1.15); }
.dot.is-on { box-shadow: 0 0 0 2px var(--primary); }

/* Độ dày */
.grp--size { gap: 8px; }
#size { width: 92px; accent-color: var(--primary); cursor: pointer; }
.size-val { font-size: 13px; font-weight: 800; color: var(--ink-2); min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; }

/* Con trỏ vẽ dạng chấm to dần theo cỡ nét */
.brush-cursor {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  left: 0; top: 0;
  display: none;
  z-index: 4;
}

.grp--page { gap: 2px; }
.page-label { font-size: 13px; font-weight: 800; color: var(--ink-2); min-width: 38px; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Vùng giấy ---------- */
.stage {
  flex: 1; min-height: 0;
  display: flex; align-items: stretch; justify-content: stretch;
  padding: 14px;
  overflow: hidden;
}
.paper {
  position: relative;
  flex: 1;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(28,37,48,.08);
  overflow: hidden;
}
.paper.grid {
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
}
.paper.lined {
  background-image: repeating-linear-gradient(0deg, transparent, transparent 31px, var(--line) 31px, var(--line) 32px);
}

#board, #overlay {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
#board { cursor: crosshair; touch-action: none; }
#overlay { pointer-events: none; }

/* Ô nhập chữ tạm */
.text-edit {
  position: absolute;
  min-width: 40px;
  background: rgba(255,255,255,.9);
  border: 1px dashed var(--primary);
  border-radius: 4px;
  font-family: var(--font);
  outline: none; resize: none;
  padding: 2px 4px;
  overflow: hidden;
  z-index: 5;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .back__txt { display: none; }
  .back { padding: 9px 11px; }
  .stage { padding: 8px; }
  .tool, .btn { width: 36px; height: 36px; }
  #size { width: 70px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool, .btn, .back, .dot { transition: none; }
}