:root {
  --bg: #eef1f5;
  --card-bg: #ffffff;
  --text: #1c1d22;
  --muted: #8a909c;
  --primary: #2f6fed;
  --primary-dark: #255fd1;
  --line: #e6e8ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.06);
  --shadow-hover: 0 8px 22px rgba(16, 24, 40, 0.16), 0 3px 8px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100vh;       /* fallback */
  height: 100dvh;      /* tracks the visible area as the browser UI shows/hides */
  display: flex;
  flex-direction: column;
}

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  /* Keep clear of the iOS status bar / notch (env insets are 0 elsewhere). */
  padding: calc(11px + env(safe-area-inset-top)) calc(18px + env(safe-area-inset-right)) 11px calc(18px + env(safe-area-inset-left));
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  z-index: 5;
  flex: 0 0 auto;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.2px;
}

.app-logo {
  width: 16px;
  height: 20px;
  border-radius: 3px;
  background: #fff;
  border: 1.5px solid #cfd4dc;
  box-shadow: 3px 3px 0 -1px #fff, 3px 3px 0 0.5px #cfd4dc;
  transform: rotate(-6deg);
}

.toolbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 10px;
  min-width: 0; /* allow the controls to wrap instead of overflowing the screen */
}

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.14s ease, transform 0.06s ease;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-plus { font-size: 17px; line-height: 1; font-weight: 700; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  min-width: 92px;
  justify-content: center;
}
.btn-secondary:hover { background: #f4f6f9; }
.btn-secondary:active { transform: translateY(1px); }
.btn-secondary:disabled { opacity: 0.65; cursor: default; transform: none; }
.btn-secondary.saved { background: #e9f6ee; border-color: #cfe9d8; color: #2f8a4e; }
.btn-secondary.error { background: #fdecec; border-color: #f3cccc; color: #d2433f; }
#saveBtn[hidden] { display: none; }

.notion-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #3f7d4f;
  background: #e9f6ee;
  border: 1px solid #cfe9d8;
  padding: 5px 10px;
  border-radius: 999px;
}

.notion-status[hidden] { display: none; }

.notion-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2faa5e;
  box-shadow: 0 0 0 3px rgba(47, 170, 94, 0.18);
}

.view-toggle {
  display: inline-flex;
  background: #eceef2;
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.toggle-btn {
  border: none;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  color: #5b616e;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.12s ease;
}

.toggle-btn.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.14);
}

/* ---------- Board ---------- */
/* Wrapper that fills the area below the toolbar; hosts the scroll viewport and
   the (non-scrolling) empty-state overlay. */
.board-area {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

/* The scroll viewport. */
.board {
  position: absolute;
  inset: 0;
}

.view-board {
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: none; /* JS drives pan + pinch-zoom on the canvas */
}

.view-list {
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The large virtual canvas that holds the cards. */
.board-canvas {
  position: relative;
}

/* Board view: .board-canvas is the (zoom-sized) scroll area; .canvas-zoom is the
   actual surface, scaled from its top-left by --zoom. Scaling an inner layer
   keeps the scrollable size in sync with the zoom. */
.view-board .board-canvas {
  width: calc(var(--canvas-size, 20000px) * var(--zoom, 1));
  height: calc(var(--canvas-size, 20000px) * var(--zoom, 1));
}
.view-board .canvas-zoom {
  position: relative;
  width: var(--canvas-size, 20000px);
  height: var(--canvas-size, 20000px);
  transform: scale(var(--zoom, 1));
  transform-origin: 0 0;
  background-image: radial-gradient(rgba(16, 24, 40, 0.07) 1px, transparent 1px);
  background-size: 22px 22px;
}

/* While a zoom gesture is in progress, scale the existing GPU texture instead
   of repainting every frame — stops the cards flickering. */
.canvas-zoom.zooming { will-change: transform; }

/* In list view the canvas becomes a centred column and the zoom layer dissolves
   (display: contents) so the cards flow as its children — never scaled. */
.view-list .board-canvas {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 24px 16px 80px;
  min-height: 100%;
}
.view-list .canvas-zoom { display: contents; }

/* Floating zoom widget (board view only). */
.zoom-controls {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 6;
  display: inline-flex;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.zoom-controls[hidden] { display: none; }
.zoom-btn,
.zoom-reset {
  border: none;
  background: #fff;
  font: inherit;
  cursor: pointer;
  color: var(--text);
}
.zoom-btn {
  width: 34px;
  height: 34px;
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.zoom-reset {
  min-width: 58px;
  font-size: 13px;
  font-weight: 600;
  padding: 0 8px;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.zoom-btn:hover,
.zoom-reset:hover { background: #f4f6f9; }
.zoom-btn:active,
.zoom-reset:active { background: #eceff3; }

/* ---------- Cards ---------- */
.card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.16s ease, transform 0.16s ease;
  user-select: none;
  -webkit-user-select: none;
}

.view-board .card {
  position: absolute;
  width: 224px;
  cursor: grab; /* the whole card is the drag handle */
  touch-action: none; /* we drive dragging in JS; stops the browser panning the board on touch */
  -webkit-touch-callout: none; /* no iOS long-press menu mid-drag */
}

/* While editing, hand touch back to the browser so the textarea behaves normally. */
.view-board .card.editing { touch-action: auto; }

.view-list .card {
  position: static;
  width: min(640px, 100%);
  cursor: default;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
}

.view-board .card.dragging { cursor: grabbing; }
.view-board .card.editing { cursor: default; }

.card.dragging {
  box-shadow: var(--shadow-hover);
  transform: scale(1.03);
  transition: none;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  padding: 6px 8px 2px 10px;
  color: #bcc1ca;
  min-height: 18px;
}

.card-delete {
  border: none;
  background: transparent;
  color: #bcc1ca;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: background 0.12s ease, color 0.12s ease;
}

.card-delete:hover { background: #ffe9e9; color: #e5484d; }

/* "Find on board" — only shown in list view. */
.card-focus {
  display: none;
  border: none;
  background: transparent;
  color: #9aa0ab;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  place-items: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.card-focus svg { display: block; }
.card-focus:hover { background: #eaf0ff; color: var(--primary); }
.view-list .card-focus { display: grid; }

/* "Open in Notion" — only in list view, and only when the card is synced. */
.card-link {
  display: none;
  border: none;
  background: transparent;
  color: #9aa0ab;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  place-items: center;
  transition: background 0.12s ease, color 0.12s ease;
}
.card-link svg { display: block; }
.card-link:hover { background: #eaf0ff; color: var(--primary); }
.view-list .card-link[href] { display: grid; }

/* Brief highlight when a card is focused from the list. */
@keyframes cardFlash {
  0%, 100% { box-shadow: var(--shadow); }
  18% { box-shadow: 0 0 0 4px rgba(47, 111, 237, 0.5), var(--shadow-hover); }
}
.card.flash { animation: cardFlash 1.3s ease; }

.card-text {
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  line-height: 1.45;
  padding: 0 14px 14px;
  width: 100%;
  min-height: 54px;
  overflow: hidden;
  box-sizing: border-box;
  pointer-events: none; /* clicks fall through to the card so it can be dragged */
  user-select: text;
  -webkit-user-select: text;
}

.card.editing .card-text {
  pointer-events: auto; /* double-click unlocks editing */
  cursor: text;
}

.card-text::placeholder { color: #aeb3bb; }

/* ---------- Empty state ---------- */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.empty-state[hidden] { display: none; }
.empty-state .es-title { font-size: 18px; font-weight: 650; color: #6b7280; }
.empty-state .es-sub { font-size: 14px; }

/* ---------- Login overlay ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(28, 31, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.login-overlay[hidden] { display: none; }

.login-card {
  width: 100%;
  max-width: 340px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, 0.35);
  padding: 28px 26px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  text-align: center;
}
.login-logo {
  width: 28px;
  height: 34px;
  margin: 0 auto 4px;
  border-radius: 5px;
  background: #fff;
  border: 2px solid #cfd4dc;
  box-shadow: 5px 5px 0 -1px #fff, 5px 5px 0 1px #cfd4dc;
  transform: rotate(-6deg);
}
.login-title { margin: 6px 0 0; font-size: 19px; font-weight: 700; }
.login-sub { margin: 0 0 6px; font-size: 13.5px; color: var(--muted); }
.login-input {
  font: inherit;
  font-size: 15px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.login-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}
.login-error {
  min-height: 16px;
  font-size: 13px;
  color: #d2433f;
  text-align: left;
}
.login-error:empty { min-height: 0; }
.login-submit { justify-content: center; margin-top: 2px; }

.btn-icon { padding: 9px 12px; }

/* ---------- Floating action button (bottom-left) ---------- */
.fab {
  position: fixed;
  left: calc(16px + env(safe-area-inset-left));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 40;
}
.fab[hidden] { display: none; }

/* Action pills sit above the main button; they never affect its position. */
.fab-actions {
  position: absolute;
  left: 0;
  bottom: calc(100% + 12px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  pointer-events: none;
}

.fab-main {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-hover);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.14s ease, transform 0.08s ease;
}
.fab-main:hover { background: var(--primary-dark); }
.fab-main:active { transform: scale(0.95); }
.fab-main-icon { transition: transform 0.22s ease; }
.fab[data-open="true"] .fab-main-icon { transform: rotate(135deg); }

.fab-action {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 7px 18px 7px 7px;
  box-shadow: var(--shadow);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  /* collapsed */
  opacity: 0;
  transform: translateY(14px) scale(0.92);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.fab[data-open="true"] .fab-action {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.fab-action[hidden] { display: none; }
.fab-action:hover { background: #f7f8fa; }
.fab[data-open="true"] .fab-action:nth-of-type(1) { transition-delay: 0.08s; }
.fab[data-open="true"] .fab-action:nth-of-type(2) { transition-delay: 0.04s; }
.fab[data-open="true"] .fab-action:nth-of-type(3) { transition-delay: 0s; }
.fab[data-open="true"] .fab-action:disabled { opacity: 0.7; cursor: default; }

.fab-ic {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eceff4;
  color: #5b616e;
}
.fab-ic svg { display: block; }
.fab-action--add .fab-ic { background: var(--primary); color: #fff; }
.fab-action--save .fab-ic { background: #e9f6ee; color: #2f8a4e; }
.fab-action--save.saved .fab-ic { background: #2faa5e; color: #fff; }
.fab-action--save.error { color: #d2433f; }
.fab-action--save.error .fab-ic { background: #fdecec; color: #d2433f; }

/* ---------- Small screens / phones ---------- */
@media (max-width: 600px) {
  .toolbar {
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 10px calc(12px + env(safe-area-inset-left));
    column-gap: 10px;
    row-gap: 8px;
  }
  .app-title { font-size: 16px; }

  .toolbar-right {
    justify-content: flex-end;
    gap: 8px;
  }

  /* The sync pill is just an indicator — hide it to save room. */
  .notion-status { display: none; }

  .btn { padding: 9px 12px; font-size: 14px; }
  .btn-secondary { min-width: 0; }
  .toggle-btn { padding: 7px 12px; font-size: 12.5px; }
  .view-list { padding: 16px 12px 72px; }
}
