:root {
  --jam-font: "Sarabun", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", sans-serif;
  --jam-bg: #e8eaed;
  --jam-accent: #4285f4;
}

body { font-family: var(--jam-font); }

.brand-dot {
  display: inline-block;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: conic-gradient(#ea4335 0 25%, #fbbc04 0 50%, #34a853 0 75%, #4285f4 0);
}

/* ---------- Index ---------- */
.board-card { transition: transform .12s, box-shadow .12s; }
.board-card:hover { transform: translateY(-2px); box-shadow: 0 .5rem 1rem rgba(0,0,0,.12) !important; }
.board-thumb {
  display: flex; align-items: center; justify-content: center;
  height: 120px; font-size: 3rem; color: #b0b7c3;
  background: repeating-linear-gradient(0deg, #fff 0 23px, #eef1f5 23px 24px),
              repeating-linear-gradient(90deg, #fff 0 23px, #eef1f5 23px 24px);
  background-blend-mode: multiply;
  border-bottom: 1px solid #eee;
}

/* ---------- Board page ---------- */
html, body.board-page { height: 100%; margin: 0; overflow: hidden; }
body.board-page {
  display: flex; flex-direction: column; background: var(--jam-bg);
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
body.board-page input, body.board-page textarea { -webkit-user-select: text; user-select: text; }

.top-bar { flex: 0 0 auto; min-height: 52px; z-index: 20; }
.top-bar .title-input { border-color: transparent; font-weight: 600; max-width: 320px; background: transparent; }
.top-bar .title-input:hover, .top-bar .title-input:focus { border-color: #ced4da; background: #fff; }
.min-w-0 { min-width: 0; }
.frame-nav { flex: 0 0 auto; }

.workspace { flex: 1 1 auto; position: relative; min-height: 0; }

/* padding = safe area where the frame is fitted; toolbars overlay the padding */
.canvas-wrap {
  position: absolute; inset: 0;
  padding: 24px 24px 24px 100px;
  overflow: hidden;
}
#board {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}
#board.tool-select { cursor: default; }
#board.tool-eraser { cursor: cell; }
#board.tool-sticky, #board.tool-text { cursor: copy; }
#board.tool-laser { cursor: none; }
#board.dragging { cursor: grabbing; }

.toolbar {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 4px;
  background: #fff; border-radius: 14px; padding: 8px 6px;
  z-index: 10;
  max-height: calc(100% - 16px); overflow-y: auto; scrollbar-width: none;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool-btn:disabled { opacity: .35; }

.zoom-ctl {
  position: absolute; right: 16px; bottom: 16px; z-index: 10;
  display: flex; gap: 2px; background: #fff; border-radius: 10px; padding: 3px;
}
.zoom-ctl .zoom-label { min-width: 56px; font-variant-numeric: tabular-nums; }
.tool-btn {
  width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; font-size: 1.25rem; color: #3c4043;
  display: flex; align-items: center; justify-content: center;
}
.tool-btn:hover { background: #f1f3f4; }
.tool-btn.active { background: #e8f0fe; color: #1967d2; }
.tool-sep { height: 1px; background: #e0e0e0; margin: 4px 6px; }

.tool-options {
  position: absolute; left: 78px; top: 50%; transform: translateY(-50%);
  background: #fff; border-radius: 12px; padding: 10px;
  z-index: 10; min-width: 56px; max-width: 220px;
  display: flex; flex-direction: column; gap: 8px;
}
.tool-options:empty, .tool-options.collapsed { display: none; }
.tool-options .opt-label { font-size: .7rem; color: #70757a; text-transform: uppercase; letter-spacing: .04em; }
.swatches { display: grid; grid-template-columns: repeat(4, 28px); gap: 6px; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px #dadce0; cursor: pointer;
}
.swatch.active { box-shadow: 0 0 0 2px #1967d2; }
.widths { display: flex; gap: 6px; align-items: center; }
.width-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center;
}
.width-btn:hover { background: #f1f3f4; }
.width-btn.active { background: #e8f0fe; }
.width-btn i { display: block; border-radius: 50%; background: #3c4043; }
.kinds { display: flex; gap: 4px; flex-wrap: wrap; }
.kind-btn { width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; font-size: 1.1rem; color: #3c4043; }
.kind-btn:hover { background: #f1f3f4; }
.kind-btn.active { background: #e8f0fe; color: #1967d2; }

/* users */
.avatar {
  width: 28px; height: 28px; border-radius: 50%; color: #fff; font-size: .75rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  margin-left: -6px; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}

/* bg menu */
.bg-swatch { display: inline-block; width: 18px; height: 18px; border: 1px solid #ccc; vertical-align: -4px; margin-right: 6px; }
.bg-swatch.bg-white { background: #fff; }
.bg-swatch.bg-cream { background: #fdf6e3; }
.bg-swatch.bg-dots { background: radial-gradient(#999 1px, #fff 1px) 0 0/6px 6px; }
.bg-swatch.bg-grid { background: linear-gradient(#ddd 1px, transparent 1px) 0 0/6px 6px, linear-gradient(90deg, #ddd 1px, #fff 1px) 0 0/6px 6px; }
.bg-swatch.bg-lines { background: linear-gradient(#bbb 1px, #fff 1px) 0 0/6px 6px; }
.bg-swatch.bg-dark { background: #202124; }

/* frames panel */
.frame-item { display: flex; align-items: center; gap: 6px; padding: 8px; border-radius: 8px; border: 1px solid #e0e0e0; background: #fff; }
.frame-item.active { border-color: #1967d2; background: #e8f0fe; }
.frame-item .frame-name { flex: 1; cursor: pointer; font-weight: 500; }
.frame-item .btn { padding: 2px 6px; }

/* edit modal colors */
#editColors .swatch { width: 32px; height: 32px; }

/* ---------- Mobile / tablet (narrow screens, or short landscape phones) ---------- */
@media (max-width: 768px), (max-height: 500px) {
  .top-bar { min-height: 48px; padding-top: 4px; padding-bottom: 4px; flex-wrap: nowrap; gap: 6px; }
  .top-bar > div { flex-shrink: 1; min-width: 0; }
  .top-bar > div:last-child { flex-grow: 0 !important; flex-shrink: 0; }
  .top-bar .frame-nav { flex-shrink: 0; }
  .top-bar .title-input { max-width: 160px; min-width: 0; font-size: .9rem; padding-left: 4px; padding-right: 4px; }
  .top-bar .btn-sm { min-width: 36px; min-height: 36px; }
  .frame-nav #frameLabel { padding-left: .5rem !important; padding-right: .5rem !important; }

  /* frame fits above the bottom toolbar */
  .canvas-wrap { padding: 12px 12px 140px 12px; }

  /* bottom toolbar: big tap targets, horizontally scrollable */
  .toolbar {
    left: 0; right: 0; bottom: 0; top: auto; transform: none;
    flex-direction: row; gap: 2px; justify-content: flex-start;
    border-radius: 16px 16px 0 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    max-height: none; overflow-x: auto; overflow-y: hidden;
    box-shadow: 0 -2px 12px rgba(0,0,0,.12);
  }
  .tool-btn { flex: 0 0 auto; width: 48px; height: 48px; font-size: 1.35rem; }
  .tool-sep { width: 1px; height: 32px; align-self: center; margin: 0 4px; }

  /* options sheet sits just above the toolbar */
  .tool-options {
    left: 8px; right: 8px; top: auto; transform: none;
    bottom: calc(66px + env(safe-area-inset-bottom, 0px));
    max-width: none; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px;
    padding: 8px 10px;
  }
  .tool-options .opt-label { width: 100%; margin-bottom: -4px; }
  .tool-options .opt-label + * { width: 100%; }
  .swatches { display: flex; flex-wrap: wrap; gap: 8px; }
  .swatch { width: 32px; height: 32px; }
  .width-btn { width: 40px; height: 40px; }
  .kind-btn { width: 44px; height: 44px; }
  .tool-options .small { max-width: none !important; }

  .zoom-ctl { right: 8px; top: 8px; bottom: auto; }

  .offcanvas-start { width: 85vw !important; }
}

/* short landscape phones: keep the frame as large as possible */
@media (max-height: 500px) {
  .canvas-wrap { padding: 8px 8px 120px 8px; }
  .tool-btn { width: 44px; height: 44px; }
  .tool-options { padding: 6px 10px; gap: 6px 10px; }
  .tool-options .small { display: none; }
  .zoom-ctl { top: auto; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); right: 8px; }
}

/* QR share modal */
.qr-box { width: 256px; height: 256px; padding: 12px; background: #fff; border: 1px solid #e0e0e0; border-radius: 12px; box-sizing: content-box; }
.qr-box img, .qr-box canvas { display: block; width: 256px; height: 256px; }
