:root {
  --surface-base: #e9eaed;
  --surface-raised: #f6f6f7;
  --surface-card: #ffffff;
  --surface-hover: #dfe0e4;
  --canvas-bg: #fafaf8;
  --border-subtle: #dcdee2;
  --border-strong: #c3c6cd;
  --text-primary: #18191c;
  --text-secondary: #474a52;
  --text-tertiary: #555962;
  --accent: #066a49;
  --accent-hover: #0a7a55;
  --accent-tint: rgba(6, 106, 73, 0.12);
  --on-accent: #ffffff;
  --danger: #b3261e;
  --ok-bg: #e6f4ee;
  --ok-fg: #045a3d;
  --err-bg: #fdecec;
  --err-fg: #8c1d18;
  --shadow-card: 0 2px 6px rgba(24, 25, 28, 0.05);
  --shadow-float: 0 8px 24px rgba(24, 25, 28, 0.12);
}
[data-theme="dark"] {
  --surface-base: #141518;
  --surface-raised: #1c1d21;
  --surface-card: #24262b;
  --surface-hover: #2b2d33;
  --canvas-bg: #fafaf8;
  --border-subtle: #26282d;
  --border-strong: #3a3d44;
  --text-primary: #edeef0;
  --text-secondary: #b9bcc4;
  --text-tertiary: #9da1aa;
  --accent: #5bd6a6;
  --accent-hover: #78e0b7;
  --accent-tint: rgba(91, 214, 166, 0.15);
  --on-accent: #0b1f17;
  --danger: #ff8a80;
  --ok-bg: #133829;
  --ok-fg: #9ef0ce;
  --err-bg: #451a18;
  --err-fg: #ffd2ce;
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.5);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--surface-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.45;
}
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }

/* Hub layout */
.fd-app { display: flex; min-height: 100vh; }
.fd-sidebar {
  width: 256px; flex: 0 0 256px; background: var(--surface-raised);
  border-right: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 6px;
}
.fd-brand-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 12px; }
.fd-brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; letter-spacing: -0.02em; }
.fd-brand-mark { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); display: inline-block; }
.fd-section-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-tertiary); padding: 12px 8px 4px;
}
.fd-ws-list, .fd-nav { display: flex; flex-direction: column; gap: 3px; }
.fd-nav-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 6px; border: 0; background: transparent; color: var(--text-secondary);
  font: inherit; font-size: 13px; font-weight: 500; text-align: left; cursor: pointer;
}
.fd-nav-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.fd-nav-item.active { background: var(--accent-tint); color: var(--accent); font-weight: 600; }
.fd-add-ws { color: var(--text-tertiary); }
.fd-inline-form { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: 8px; margin-top: 4px; }
.fd-inline-form input { padding: 7px 9px; border: 1px solid var(--border-subtle); border-radius: 6px; background: var(--surface-raised); color: var(--text-primary); font: inherit; font-size: 13px; }
.fd-form-actions { display: flex; gap: 6px; }
.fd-account-footer {
  margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 8px;
}
.fd-account-info { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.fd-avatar {
  width: 30px; height: 30px; border-radius: 9999px; background: var(--accent-tint); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex-shrink: 0;
}
.fd-account-text { min-width: 0; }
.fd-account-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fd-account-meta { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fd-footer-actions { display: flex; gap: 6px; }

/* Main area */
.fd-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fd-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 28px; border-bottom: 1px solid var(--border-subtle); background: var(--surface-raised);
}
.fd-topbar-left, .fd-topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fd-ws-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.fd-search {
  width: 220px; padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border-subtle);
  background: var(--surface-card); color: var(--text-primary); font: inherit; font-size: 13px;
}
.fd-search:focus { outline: 2px solid var(--accent-tint); border-color: var(--accent); }
.fd-content { padding: 24px 28px 40px; max-width: 1280px; width: 100%; display: flex; flex-direction: column; gap: 24px; }
.fd-block { display: flex; flex-direction: column; gap: 12px; }
.fd-block-header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.fd-block h2, .fd-card h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.fd-caption { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; }
.fd-muted { color: var(--text-secondary); margin: 4px 0 12px; font-size: 13px; }

/* Buttons & pills */
.fd-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 13px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface-card); color: var(--text-primary); font: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
}
.fd-btn:hover { border-color: var(--accent); }
.fd-btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.fd-btn.primary:hover { background: var(--accent-hover); }
.fd-btn.danger { border-color: var(--danger); color: var(--danger); }
.fd-btn.sm { padding: 5px 10px; font-size: 12px; }
.fd-icon-btn { border: 1px solid var(--border-subtle); background: var(--surface-card); color: var(--text-primary); border-radius: 6px; width: 32px; height: 32px; font-size: 18px; cursor: pointer; }
.fd-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 9999px; font-size: 11px; font-weight: 500; }
.fd-pill.neutral { background: var(--surface-base); color: var(--text-secondary); }
.fd-pill.accent { background: var(--accent-tint); color: var(--accent); }
.fd-banner { margin: 14px 28px 0; padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.fd-banner.ok { background: var(--ok-bg); color: var(--ok-fg); }
.fd-banner.error { background: var(--err-bg); color: var(--err-fg); }

/* Templates */
.fd-templates { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.fd-template-card {
  display: flex; flex-direction: column; gap: 6px; padding: 10px; text-align: left; cursor: pointer;
  background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: 10px; color: var(--text-primary); font: inherit;
}
.fd-template-card:hover { border-color: var(--accent); box-shadow: var(--shadow-card); }
.fd-tpl-preview { height: 64px; border-radius: 8px; background: var(--canvas-bg); border: 1px solid var(--border-subtle); display: block; background-image: radial-gradient(#c3c6cd 1px, transparent 1px); background-size: 12px 12px; }
.fd-tpl-name { font-size: 13px; font-weight: 600; }
.fd-tpl-desc { font-size: 11px; color: var(--text-tertiary); }

/* Boards grid */
.fd-boards-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.fd-board-card {
  background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: 10px;
  padding: 8px; display: flex; flex-direction: column; gap: 8px; transition: border-color 0.12s ease;
}
.fd-board-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-card); }
.fd-board-thumb-link {
  display: block; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden;
  background: var(--canvas-bg); border: 1px solid var(--border-subtle);
}
.fd-board-thumb { width: 100%; height: 100%; object-fit: contain; display: block; }
.fd-board-foot { display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 4px 4px 2px; min-width: 0; }
.fd-board-foot > div:first-child { min-width: 0; }
.fd-board-title { font-size: 14px; font-weight: 600; line-height: 1.3; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.fd-board-meta { font-size: 11px; color: var(--text-tertiary); display: flex; align-items: center; gap: 6px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.fd-board-actions { display: flex; flex-wrap: wrap; gap: 4px; }

/* Members & Invites */
.fd-card { background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.fd-invite-row { display: flex; gap: 8px; flex-wrap: wrap; }
.fd-invite-row input { flex: 1; min-width: 220px; padding: 8px 10px; border-radius: 6px; border: 1px solid var(--border-subtle); background: var(--surface-raised); color: var(--text-primary); font: inherit; }
.fd-invite-row select, .fd-row-select { padding: 7px 10px; border-radius: 6px; border: 1px solid var(--border-subtle); background: var(--surface-raised); color: var(--text-primary); font: inherit; font-size: 13px; }
.fd-invite-result { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; background: var(--ok-bg); color: var(--ok-fg); border-radius: 6px; font-size: 12px; word-break: break-all; }
.fd-list { display: flex; flex-direction: column; gap: 8px; }
.fd-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: 8px; }
.fd-row-main { min-width: 0; }
.fd-row-title { font-weight: 600; font-size: 13px; }
.fd-row-sub { font-size: 12px; color: var(--text-tertiary); }
.fd-row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Phone Companion */
.cp-app { display: flex; flex-direction: column; height: 100dvh; background: var(--surface-base); overflow: hidden; }
.cp-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; background: var(--surface-card); border-bottom: 1px solid var(--border-subtle);
}
.cp-title-wrap { min-width: 0; flex: 1; display: flex; align-items: center; gap: 8px; }
.cp-title { margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cp-stage {
  flex: 1; position: relative; overflow: hidden; touch-action: none;
  background: var(--canvas-bg); background-image: radial-gradient(#d5d8de 1px, transparent 1px); background-size: 18px 18px;
}
.cp-viewport { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; transform-origin: center center; }
.cp-svg { max-width: 92%; max-height: 92%; user-select: none; pointer-events: none; }
.cp-zoom-controls { position: absolute; left: 12px; bottom: 14px; display: flex; align-items: center; gap: 6px; }
.cp-dock {
  display: flex; align-items: center; justify-content: space-around; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface-card); border-top: 1px solid var(--border-subtle);
}
.cp-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 75dvh; z-index: 30;
  background: var(--surface-card); border-top: 1px solid var(--border-strong); border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-float); display: flex; flex-direction: column;
}
.cp-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border-subtle); }
.cp-sheet-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.cp-sheet-body { padding: 14px 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.cp-sheet-body textarea, .cp-comment-form input {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border-subtle);
  background: var(--surface-raised); color: var(--text-primary); font: inherit;
}
.cp-swatches { display: flex; gap: 10px; }
.cp-swatch { width: 28px; height: 28px; border-radius: 9999px; border: 2px solid var(--border-strong); cursor: pointer; }
.cp-swatch[data-color="#FFF3B0"] { background: #fff3b0; }
.cp-swatch[data-color="#D8F3DC"] { background: #d8f3dc; }
.cp-swatch[data-color="#DBEAFE"] { background: #dbeafe; }
.cp-swatch[data-color="#FCE7F3"] { background: #fce7f3; }
.cp-swatch[data-color="#FFEDD5"] { background: #ffedd5; }
.cp-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }
.cp-comment-form { display: flex; gap: 8px; }

[hidden] { display: none !important; }
.fd-mobile-only { display: none; }
.fd-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 19; }
.fd-modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.fd-modal.hidden { display: none; }
.fd-modal-card { width: min(560px, 100%); max-height: 85vh; overflow: auto; background: var(--surface-card); border: 1px solid var(--border-subtle); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2); }
.fd-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--surface-base); color: var(--text-primary); }
.fd-top-actions { display: flex; gap: 8px; align-items: center; }
.sh-main { width: min(1100px, 100%); margin: 0 auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; flex: 1; }
.fd-card-title { margin: 0 0 6px; font-size: 1rem; }
.sh-inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.fd-input { flex: 1; min-width: 220px; padding: 9px 12px; border: 1px solid var(--border-subtle); border-radius: 8px; background: var(--surface-base); color: var(--text-primary); font: inherit; }
.fd-status { padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; border: 1px solid var(--border-subtle); background: var(--surface-card); }
.fd-status.error { border-color: #ef4444; color: #b91c1c; background: #fef2f2; }
.fd-stage-wrap { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 60vh; overflow: auto; }
.fd-stage { width: 100%; display: flex; align-items: center; justify-content: center; overflow: auto; padding: 12px; }
.fd-stage-img { max-width: 100%; height: auto; transform-origin: center center; transition: transform 0.12s ease; }

@media (max-width: 1023px) {
  .fd-mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .fd-sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 20; transform: translateX(-100%); transition: transform 0.16s ease; }
  .fd-sidebar.open { transform: translateX(0); }
  .fd-templates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fd-boards-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fd-topbar, .fd-content { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 640px) {
  .fd-boards-grid { grid-template-columns: 1fr; }
  .fd-search { width: 100%; }
}