* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #eef1f5; color: #1f2430;
  -webkit-font-smoothing: antialiased;
  touch-action: none;
}
.hidden { display: none !important; }
.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid #d4dae3; background: #fff; color: #1f2430;
  border-radius: 8px; padding: 7px 14px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: background .12s, box-shadow .12s;
}
.btn:hover { background: #f3f6fa; }
.btn.primary { background: #2f6fed; border-color: #2f6fed; color: #fff; }
.btn.primary:hover { background: #235cd0; }
.btn.ghost { border-color: transparent; background: transparent; color: #5a6478; }
.btn.ghost:hover { background: #e7ecf3; color: #1f2430; }

/* ---------- gallery ---------- */
.gal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: #fff; border-bottom: 1px solid #e3e8ef;
}
.brand { display: flex; align-items: center; gap: 10px; color: #2f6fed; }
.brand h1 { font-size: 22px; font-weight: 700; color: #1f2430; }
.brand-sub { font-size: 13px; color: #8a93a6; margin-top: 4px; }
.board-grid {
  flex: 1; overflow-y: auto; padding: 26px 28px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px; align-content: start;
}
.board-card {
  background: #fff; border: 1px solid #e3e8ef; border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.board-card:hover { box-shadow: 0 6px 18px rgba(30,40,70,.10); transform: translateY(-2px); }
.board-thumb {
  height: 150px; background: #f6f8fb; display: flex; align-items: center; justify-content: center;
  position: relative;
}
.board-thumb img { width: 100%; height: 100%; object-fit: cover; }
.board-thumb .ph { font-size: 34px; color: #c3cbd8; }
.board-meta { padding: 10px 12px; border-top: 1px solid #eef2f7; }
.board-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.board-date { font-size: 12px; color: #8a93a6; margin-top: 3px; }
.board-actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.board-actions .btn { padding: 4px 10px; font-size: 12.5px; }
.gal-empty { text-align: center; margin-top: 80px; color: #8a93a6; font-size: 16px; }

/* ---------- editor ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: #fff; border-bottom: 1px solid #e3e8ef; z-index: 5;
}
.title-input {
  flex: 0 1 320px; font-size: 15px; font-weight: 600; border: none; outline: none;
  padding: 6px 8px; border-radius: 6px; color: #1f2430; background: transparent;
}
.title-input:hover, .title-input:focus { background: #f3f6fa; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 12.5px; color: #8a93a6; min-width: 90px; text-align: right; }
.save-status.dirty { color: #b7791f; }
.save-status.ok { color: #2e9e5b; }

/* switch */
.switch { position: relative; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; margin-right: 6px; }
.switch input { display: none; }
.switch .slider {
  width: 34px; height: 20px; background: #cfd6e0; border-radius: 20px; position: relative; transition: background .15s;
}
.switch .slider::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; top: 2px; left: 2px; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .slider { background: #2f6fed; }
.switch input:checked + .slider::after { left: 16px; }
.switch-label { font-size: 12.5px; font-weight: 600; color: #5a6478; }

/* canvas area */
.canvas-wrap { flex: 1; position: relative; overflow: hidden; }
#board {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  cursor: crosshair; touch-action: none;
}
#board.panning { cursor: grab; }
#board.panning.active { cursor: grabbing; }

/* ink strip (colors + sizes) floating top-center */
.ink-strip {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 1px solid #e3e8ef; border-radius: 12px;
  box-shadow: 0 4px 14px rgba(30,40,70,.12);
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; z-index: 4;
}
.swatches { display: flex; gap: 6px; align-items: center; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
  transition: transform .1s;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: #2f6fed; box-shadow: 0 0 0 2px #fff inset, inset 0 0 0 1px rgba(0,0,0,.08); }
.sizes { display: flex; gap: 8px; align-items: center; border-left: 1px solid #e8edf3; padding-left: 12px; }
.size-dot { border-radius: 50%; background: #1f2430; cursor: pointer; opacity: .55; transition: transform .1s; }
.size-dot:hover { transform: scale(1.2); }
.size-dot.active { opacity: 1; box-shadow: 0 0 0 2px #2f6fed; }

/* left tool rail */
.tool-rail {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  background: #fff; border: 1px solid #e3e8ef; border-radius: 14px;
  box-shadow: 0 4px 14px rgba(30,40,70,.12);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 6px; z-index: 4;
}
.tool {
  width: 40px; height: 40px; border: none; background: transparent; border-radius: 10px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; color: #414b5e;
  transition: background .1s;
}
.tool:hover { background: #eef3fb; }
.tool.active { background: #dce9ff; color: #2f6fed; }
.tool svg { width: 21px; height: 21px; }
.rail-sep { width: 26px; height: 1px; background: #e8edf3; margin: 4px 0; }
.rail-grow { flex: 1; }

/* text input overlay */
.text-input {
  position: absolute; z-index: 6; border: 1px dashed #2f6fed; outline: none;
  background: transparent; font-family: "Segoe Print", "Bradley Hand", "Comic Sans MS", cursive;
  padding: 2px 6px; min-width: 40px; min-height: 24px; border-radius: 4px;
}

/* toast */
.toast {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: rgba(28,34,48,.92); color: #fff; font-size: 13.5px; font-weight: 500;
  padding: 9px 18px; border-radius: 10px; z-index: 7; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}

/* dictation / recording states */
.btn.listening { background: #e03131; border-color: #e03131; color: #fff; animation: pulse 1.2s infinite; }
.btn.recording { background: #e03131; border-color: #e03131; color: #fff; animation: pulse 1.2s infinite; }
.title-input.dictating { border-color: #e03131; box-shadow: 0 0 0 3px rgba(224,49,49,.18); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* read-only share view */
#editor-view.ro .hide-ro,
#editor-view.ro .tool-rail,
#editor-view.ro .ink-strip { display: none !important; }
#ro-banner { display: none; position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 6; background: rgba(31,36,48,.88); color: #fff; font-size: 13px; font-weight: 500;
  padding: 8px 16px; border-radius: 10px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.2); white-space: nowrap; }
#editor-view.ro #ro-banner { display: block; }

/* countdown timer */
.timer-box { position: absolute; top: 16px; right: 16px; z-index: 6; background: rgba(28,34,48,.94);
  border-radius: 12px; padding: 10px 16px 8px; text-align: center; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
#timer-display { color: #fff; font-size: 30px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.timer-box.urgent #timer-display { color: #ff8787; animation: pulse .8s infinite; }
.timer-btns { display: flex; gap: 6px; justify-content: center; margin-top: 6px; }
.tbtn { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff;
  border-radius: 7px; width: 36px; height: 28px; font-size: 13px; cursor: pointer; }
.tbtn:hover { background: rgba(255,255,255,.12); }

/* image-annotate chip */
.img-chip {
  position: absolute; left: 14px; bottom: 16px; z-index: 5;
  display: flex; align-items: center; gap: 7px;
  background: rgba(28,34,48,.88); color: #fff; font-size: 12.5px; font-weight: 500;
  padding: 7px 10px; border-radius: 10px; max-width: 260px;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.img-chip #img-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.chip-x {
  border: none; background: rgba(255,255,255,.16); color: #fff; border-radius: 6px;
  width: 20px; height: 20px; cursor: pointer; font-size: 11px; line-height: 1;
}
.chip-x:hover { background: rgba(255,255,255,.3); }

/* version history popover */
.history-pop {
  position: absolute; top: 58px; right: 12px; z-index: 8;
  width: 350px; max-height: 400px; overflow-y: auto;
  background: #fff; border: 1px solid #e3e8ef; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(20,30,60,.22);
}
.hp-head {
  padding: 11px 14px 9px; font-size: 13.5px; font-weight: 700; color: #1f2430;
  border-bottom: 1px solid #eef1f6; position: sticky; top: 0; background: #fff;
}
.hp-sub { font-weight: 400; color: #8a93a6; font-size: 11.5px; }
.hp-empty { padding: 18px 14px; color: #8a93a6; font-size: 12.5px; line-height: 1.5; }
.hp-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid #f2f4f8;
}
.hp-item:last-child { border-bottom: none; }
.hp-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hp-meta b { font-size: 13px; color: #1f2430; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.hp-meta span { font-size: 11.5px; color: #8a93a6; }
.hp-restore { flex: 0 0 auto; font-size: 12px; padding: 5px 12px; }

/* dark mode (chrome only — the board sheet stays white) */
[data-theme="dark"] body { background: #14161b; }
[data-theme="dark"] .topbar,
[data-theme="dark"] .gal-header { background: #1b1e25; border-color: #2c323e; }
[data-theme="dark"] .title-input { color: #e8ebf2; }
[data-theme="dark"] .title-input::placeholder { color: #6b7385; }
[data-theme="dark"] .save-status { color: #8b93a5; }
[data-theme="dark"] .board-card { background: #1d2129; border-color: #2c323e; }
[data-theme="dark"] .board-card .board-title { color: #e8ebf2; }
[data-theme="dark"] .board-card .board-date { color: #8b93a5; }
[data-theme="dark"] .gal-empty, [data-theme="dark"] .gal-loading { color: #8b93a5; }
[data-theme="dark"] .tool-rail,
[data-theme="dark"] .ink-strip { background: #1d2129; border-color: #2c323e; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
[data-theme="dark"] .tool { color: #c6cddc; }
[data-theme="dark"] .tool:hover { background: #2a2f3a; }
[data-theme="dark"] .tool.active { background: #2b3a55; color: #7ea4ff; }
[data-theme="dark"] .rail-sep { background: #2c323e; }
[data-theme="dark"] .history-pop { background: #1d2129; border-color: #2c323e; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
[data-theme="dark"] .hp-head { color: #e8ebf2; border-color: #2c323e; background: #1d2129; }
[data-theme="dark"] .hp-meta b { color: #e8ebf2; }
[data-theme="dark"] .hp-item { border-color: #262b35; }
[data-theme="dark"] .hp-empty { color: #8b93a5; }
[data-theme="dark"] .btn.ghost { background: #232733; border-color: #2c323e; color: #c6cddc; }
[data-theme="dark"] .brand-sub { color: #6b7385; }
[data-theme="dark"] #ro-banner { background: rgba(20,24,32,.92); }
[data-theme="dark"] .switch-label { color: #c6cddc; }
