:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f5d0b8;
  --bg-soft: #fff0df;
  --text: #2f1718;
  --muted: rgba(47, 23, 24, 0.68);
  --card: rgba(255, 239, 221, 0.86);
  --border: rgba(122, 49, 57, 0.22);
  --shadow: rgba(98, 42, 35, 0.2);
  --accent: #d55a33;
  --accent-strong: #9f1f32;
  --accent-soft: rgba(245, 150, 68, 0.24);
  --field: rgba(255, 248, 237, 0.92);
  --button: #351c24;
  --button-text: #fff4e7;
  --error: #9f1f32;
  background: var(--bg);
  color: var(--text);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #071423;
  --bg-soft: #102a42;
  --text: #e8f4ff;
  --muted: rgba(232, 244, 255, 0.68);
  --card: rgba(9, 30, 51, 0.86);
  --border: rgba(142, 190, 221, 0.22);
  --shadow: rgba(0, 8, 18, 0.48);
  --accent: #7fc4ea;
  --accent-strong: #f07a3f;
  --accent-soft: rgba(127, 196, 234, 0.18);
  --field: rgba(6, 23, 39, 0.92);
  --button: #d9ecfb;
  --button-text: #071423;
  --error: #ff9b74;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, var(--accent-soft), transparent 28rem),
    radial-gradient(circle at 74% 22%, rgba(159, 31, 50, 0.18), transparent 22rem),
    linear-gradient(135deg, var(--bg-soft) 0%, var(--bg) 58%, #efb08d 100%);
  transition: background 180ms ease, color 180ms ease;
}

body[data-session="authenticated"] .hero {
  display: none;
}

:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 20% 16%, rgba(127, 196, 234, 0.2), transparent 30rem),
    radial-gradient(circle at 78% 18%, rgba(240, 122, 63, 0.2), transparent 20rem),
    linear-gradient(140deg, #020812 0%, var(--bg) 46%, #163c5b 100%);
}

.shell {
  width: min(1680px, calc(100% - 48px));
  margin: 0 auto;
  padding: max(56px, env(safe-area-inset-top)) 0 max(56px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  margin-bottom: 28px;
  min-width: 0;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.tool-menu {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--field);
}

.tool-menu button {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.tool-menu button:hover,
.tool-menu button[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.tool-content {
  min-width: 0;
}

.workspace-heading,
.modal-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.workspace-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.info-help {
  position: relative;
  display: inline-flex;
  order: 2;
}

.info-button {
  display: inline-grid;
  place-items: center;
  width: 2.45rem;
  height: 2.45rem;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--field);
  color: var(--text);
  box-shadow: none;
}

.info-button:hover,
.info-button:focus-visible {
  background: var(--button);
  color: var(--button-text);
}

.info-popover {
  position: absolute;
  z-index: 20;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, calc(100vw - 48px));
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--field);
  color: var(--text);
  box-shadow: 0 18px 48px var(--shadow);
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.info-help:hover .info-popover,
.info-help:focus-within .info-popover {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.theme-toggle {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  box-shadow: 0 14px 36px var(--shadow);
  backdrop-filter: blur(14px);
}

.theme-toggle button {
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  border: 0;
  box-shadow: none;
}

.theme-toggle button:hover,
.theme-toggle button[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.hero {
  max-width: 680px;
  margin-bottom: 28px;
}

#workspace-panel {
  width: 100%;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.7rem, 8vw, 6rem);
  max-width: 10ch;
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
}

h3 {
  font-size: clamp(1.25rem, 2vw, 1.55rem);
}

.hero p:last-child {
  max-width: 36rem;
  font-size: 1.1rem;
  line-height: 1.6;
}

.card {
  max-width: 100%;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: 0 24px 80px var(--shadow);
  padding: clamp(22px, 4vw, 36px);
  backdrop-filter: blur(14px);
}

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  min-width: 0;
}

.toolbar-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

form {
  display: grid;
  gap: 18px;
}

.pocket-login {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin: 20px 0 0;
  border-radius: 999px;
  padding: 13px 20px;
  background: var(--accent-strong);
  color: var(--button-text);
  font-weight: 800;
  text-decoration: none;
}

.pocket-login:hover {
  background: var(--button);
}

.divider {
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.tiny-button {
  padding: 7px 10px;
  font-size: 0.78rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--field);
  color: inherit;
  font: inherit;
  font-size: 16px;
}

.markdown-editor {
  min-height: 12rem;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--field);
}

.markdown-editor.compact {
  min-height: 8rem;
}

.section-markdown-editor {
  min-height: 16rem;
}

.cm-editor {
  min-height: inherit;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 16px;
}

.cm-editor.cm-focused {
  outline: 3px solid var(--accent-soft);
}

.cm-scroller {
  min-height: inherit;
  font-family: inherit;
  line-height: 1.5;
}

.cm-content {
  padding: 14px 16px;
}

.cm-gutters {
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}

.markdown-preview {
  display: grid;
  gap: 0.55rem;
  color: var(--text);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.markdown-preview > * {
  margin: 0;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  margin-top: 0.25rem;
  line-height: 1.15;
}

.markdown-preview h1 {
  max-width: none;
  font-size: 1.45rem;
}

.markdown-preview h2 {
  font-size: 1.25rem;
}

.markdown-preview h3,
.markdown-preview h4,
.markdown-preview h5,
.markdown-preview h6 {
  font-size: 1.05rem;
}

.markdown-preview ul,
.markdown-preview ol {
  display: grid;
  gap: 0.25rem;
  padding-left: 1.35rem;
}

.markdown-preview blockquote {
  padding-left: 0.9rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}

.markdown-preview code {
  padding: 0.1rem 0.3rem;
  border-radius: 0.35rem;
  background: var(--accent-soft);
}

.markdown-preview a {
  color: var(--accent-strong);
  font-weight: 700;
}

.markdown-preview hr {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--border);
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid var(--accent-soft);
  border-color: var(--accent);
}

textarea {
  resize: vertical;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 13px 20px;
  background: var(--button);
  color: var(--button-text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

button.danger {
  background: var(--error);
  color: var(--button-text);
}

.card-heading-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.card-heading-row > :first-child {
  min-width: 0;
}

.overflow-menu {
  position: relative;
  justify-self: end;
}

.overflow-menu summary {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  list-style: none;
}

.overflow-menu summary::-webkit-details-marker {
  display: none;
}

.overflow-menu summary:hover,
.overflow-menu[open] summary {
  background: var(--button);
  color: var(--button-text);
}

.overflow-menu-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  min-width: 9rem;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--field);
  box-shadow: 0 18px 48px var(--shadow);
}

.overflow-menu-panel button {
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.overflow-menu-panel button:hover {
  background: var(--button);
  color: var(--button-text);
}

.overflow-menu-panel .danger-menu-item {
  color: var(--error);
}

.overflow-menu-panel .danger-menu-item:hover {
  background: var(--error);
  color: var(--button-text);
}

.idea-workspace,
.note-workspace,
.brainstorming-workspace,
.project-workspace,
.placeholder-workspace {
  display: grid;
  gap: 20px;
}

.brainstorming-actions {
  flex-wrap: wrap;
}

.brainstorming-intro {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
}

.brainstorming-editor {
  min-height: 28rem;
}

.brainstorming-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.idea-list,
.note-list,
.project-list,
.member-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.project-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.7fr) minmax(520px, 1.7fr);
  gap: 24px;
  align-items: start;
}

.project-detail-layout {
  display: grid;
  gap: 18px;
}

.project-side {
  display: grid;
  gap: 18px;
  align-content: start;
}

.project-pane,
.active-project-pane,
.section-editor {
  display: grid;
  gap: 18px;
}

.active-project-pane {
  min-height: 16rem;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255, 248, 237, 0.36);
}

:root[data-theme="dark"] .active-project-pane {
  background: rgba(6, 23, 39, 0.36);
}

.idea-card,
.note-card,
.project-card,
.member-card {
  display: grid;
  min-width: 0;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--field);
}

.project-select {
  display: grid;
  gap: 8px;
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  box-shadow: none;
}

.project-select:hover {
  background: transparent;
  color: inherit;
}

.idea-card h4,
.note-card h4,
.project-card h4,
.member-card h4 {
  margin: 0 0 8px;
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.idea-card > p,
.note-card > p,
.project-card > p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.empty-state {
  color: var(--muted);
  font-weight: 700;
}

.section-editor-project {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.section-list {
  display: grid;
  gap: 16px;
}

.project-links {
  display: grid;
  gap: 12px;
}

.project-links h4 {
  margin: 0;
}

.inline-form {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
}

.section-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--field);
}

.section-card h4 {
  margin: 0;
}

.section-lenses {
  color: var(--muted);
}

.section-lenses summary {
  cursor: pointer;
  font-weight: 800;
}

.section-lenses ul {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-left: 20px;
}

.section-note-links {
  display: grid;
  gap: 12px;
}

.modal-card {
  width: min(720px, calc(100% - 32px));
  max-height: min(88vh, 840px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: clamp(20px, 4vw, 32px);
  background: var(--card);
  color: var(--text);
  box-shadow: 0 24px 80px var(--shadow);
  backdrop-filter: blur(14px);
}

.modal-card::backdrop {
  background: rgba(47, 23, 24, 0.36);
  backdrop-filter: blur(6px);
}

.modal-close {
  white-space: nowrap;
}

.confirm-card {
  width: min(460px, calc(100% - 32px));
}

.confirm-card p {
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.section-note-links h5 {
  margin: 0;
  font-size: 0.95rem;
}

#status {
  min-height: 1.5rem;
  font-weight: 700;
}

#status.error {
  color: var(--error);
}

[hidden] {
  display: none !important;
}

@media (max-width: 980px) {
  .workspace-shell {
    grid-template-columns: 1fr;
  }

  .tool-menu {
    position: static;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    grid-template-columns: none;
    max-width: 100%;
    overflow-x: auto;
  }

  .project-layout {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1200px) {
  .idea-workspace > .idea-list,
  .note-workspace > .note-list {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .project-detail-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    align-items: start;
  }

  .project-side {
    position: sticky;
    top: 18px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(1680px, calc(100% - 24px));
    padding: max(32px, env(safe-area-inset-top)) 0 max(32px, env(safe-area-inset-bottom));
  }

  .topbar {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace-shell {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .toolbar-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace-heading,
  .modal-heading {
    display: grid;
  }

  .workspace-actions {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
  }

  .info-popover {
    right: auto;
    left: 0;
  }

  .project-layout {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  .inline-form button,
  .workspace-heading button {
    width: 100%;
  }

  .workspace-heading .info-button {
    width: 2.45rem;
  }

}

.book-workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.book-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--field);
}

.book-toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.book-toolbar-grow {
  margin-left: auto;
}

.book-font-size {
  min-width: 3.2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.book-selection {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  padding: 14px 16px;
  box-shadow: 0 14px 36px var(--shadow);
}

.book-selection-quote {
  margin: 0 0 12px;
  font-style: italic;
}

.book-selection-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

.book-copy-hint {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.9rem;
}

.book-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.book-layout[data-panel="contents"],
.book-layout[data-panel="search"] {
  grid-template-columns: minmax(0, 320px) minmax(0, 1fr);
}

.book-panel {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--field);
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}

.book-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.book-panel li button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  box-shadow: none;
  padding: 8px 10px;
}

.book-panel li button:hover {
  background: var(--button);
  color: var(--button-text);
}

.book-search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.book-search-form input {
  flex: 1;
  min-width: 0;
}

.book-search-hit {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}

.book-search-title {
  margin: 0;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--accent-strong);
}

.book-search-excerpt {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.book-search-actions {
  display: inline-flex;
  gap: 8px;
}

.book-stage {
  min-width: 0;
}

.book-status {
  margin: 0 0 12px;
  color: var(--muted);
}

.book-status.error {
  color: var(--error);
}

.book-viewport {
  position: relative;
  width: 100%;
  height: 70vh;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--bg-soft);
  overflow: hidden;
}

.book-viewport iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

@media (max-width: 720px) {
  .book-layout[data-panel="contents"],
  .book-layout[data-panel="search"] {
    grid-template-columns: minmax(0, 1fr);
  }

  .book-toolbar-grow {
    margin-left: 0;
  }
}
