/* BrowserNotes – design tokens & shared layout */

:root {
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-body: "Source Serif 4", "Source Serif Pro", "Iowan Old Style", Georgia, serif;
  --font-ui: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", "Consolas", "Courier New", monospace;

  --ink: #1a1f1c;
  --ink-muted: #5a635c;
  --paper: #f7f4ef;
  --paper-deep: #efe9e0;
  --surface: #fffcf7;
  --line: #d4cdc2;
  --accent: #2d6a4f;
  --accent-soft: #d8f3dc;
  --danger: #9b2226;
  --focus: #40916c;
  --shadow: 0 1px 2px rgba(26, 31, 28, 0.06), 0 8px 24px rgba(26, 31, 28, 0.06);
  --header-h: 2.5rem;
  --toolbar-h: 2.25rem;
  --footer-h: 2.25rem;
  --sidebar-w: 15rem;
  --radius: 6px;
  --transition: 160ms ease;
  color-scheme: light;
}

[data-theme="dark"] {
  --ink: #e8ebe6;
  --ink-muted: #9aa39b;
  --paper: #161a17;
  --paper-deep: #101412;
  --surface: #1c221e;
  --line: #2e3631;
  --accent: #74c69d;
  --accent-soft: #1b4332;
  --danger: #f07167;
  --focus: #95d5b2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--ink);
  background:
    radial-gradient(ellipse 120% 80% at 10% -20%, rgba(45, 106, 79, 0.08), transparent 50%),
    radial-gradient(ellipse 90% 60% at 100% 0%, rgba(26, 31, 28, 0.04), transparent 45%),
    linear-gradient(180deg, var(--paper-deep) 0%, var(--paper) 40%, var(--paper) 100%);
  background-attachment: fixed;
}

/* Editor app: lock to one viewport — note scrolls inside */
body.app {
  height: var(--app-height, 100vh);
  height: var(--app-height, 100dvh);
  max-height: var(--app-height, 100vh);
  max-height: var(--app-height, 100dvh);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

[data-theme="dark"] body {
  background:
    radial-gradient(ellipse 120% 80% at 10% -20%, rgba(116, 198, 157, 0.08), transparent 50%),
    radial-gradient(ellipse 90% 60% at 100% 0%, rgba(0, 0, 0, 0.35), transparent 45%),
    linear-gradient(180deg, var(--paper-deep) 0%, var(--paper) 40%, var(--paper) 100%);
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100%;
  z-index: 1000;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.875rem;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.site-header {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) max(0.75rem, env(safe-area-inset-right, 0px)) 0 max(0.75rem, env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

body.app .site-header {
  flex-wrap: nowrap;
}

.notes-toggle {
  flex-shrink: 0;
}

@media (min-width: 768px) {
  body.app .notes-toggle {
    display: none;
  }
}

/* Workspace: sidebar + editor column */
.workspace {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.workspace-main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.notes-sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  font-family: var(--font-ui);
  z-index: 45;
}

.notes-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
}

.notes-sidebar-title {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.notes-new {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  min-height: 1.6rem;
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0.35rem;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1 1 auto;
  min-height: 0;
}

.notes-item {
  display: flex;
  align-items: stretch;
  gap: 0.15rem;
  border-radius: var(--radius);
  margin-bottom: 0.15rem;
}

.notes-item.is-active {
  background: var(--accent-soft);
}

.notes-item-select {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.45rem 0.5rem;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius);
}

.notes-item-select:hover {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
}

.notes-item.is-active .notes-item-select:hover {
  background: transparent;
}

.notes-item-title {
  display: block;
  width: 100%;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}

.notes-item-meta {
  font-size: 0.7rem;
  color: var(--ink-muted);
}

.notes-item-delete {
  flex-shrink: 0;
  align-self: center;
  opacity: 0;
  color: var(--ink-muted);
  min-width: 1.6rem;
  min-height: 1.6rem;
  padding: 0.2rem;
}

.notes-item:hover .notes-item-delete,
.notes-item:focus-within .notes-item-delete {
  opacity: 1;
}

.notes-item-delete:hover {
  color: var(--danger);
}

.notes-backdrop {
  display: none;
}

@media (max-width: 767px) {
  .notes-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-105%);
    transition: transform var(--transition);
    box-shadow: var(--shadow);
  }

  body.notes-sidebar-open .notes-sidebar {
    transform: translateX(0);
  }

  .notes-backdrop {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 44;
    background: rgba(26, 31, 28, 0.35);
    border: none;
    padding: 0;
  }

  .notes-backdrop[hidden] {
    display: none;
  }

  .notes-item-delete {
    opacity: 1;
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  min-width: 0;
}

.brand-mark {
  width: 1.15rem;
  height: 1.15rem;
  display: block;
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-status {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: var(--ink-muted);
  white-space: nowrap;
  transition: color var(--transition), opacity var(--transition);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-status.is-saving {
  opacity: 0.7;
}

.save-status.is-saved {
  color: var(--accent);
}

.save-status.is-flash {
  animation: save-flash 0.6s ease;
}

@keyframes save-flash {
  0%,
  100% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.06);
    color: var(--accent);
  }
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-wrap: nowrap;
  justify-content: flex-end;
  min-width: 0;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  color: var(--ink-muted);
}

.btn-accent {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}

.btn-accent:hover {
  background: color-mix(in srgb, var(--accent) 18%, var(--accent-soft));
}

.btn-icon {
  padding: 0.3rem;
  min-width: 1.75rem;
  min-height: 1.75rem;
  justify-content: center;
}

.btn-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Footer */
.site-footer {
  margin-top: 0;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
  font-family: var(--font-ui);
  font-size: 0.8125rem;
  color: var(--ink-muted);
  flex-shrink: 0;
}

body.app .site-footer {
  min-height: var(--footer-h);
  height: auto;
  padding: 0.35rem 0.75rem;
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom, 0px));
  padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
  padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
}

body.app .site-footer p {
  margin: 0;
  font-size: 0.7rem;
}

.footer-inner {
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
}

.footer-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.footer-nav a {
  color: var(--ink-muted);
  text-decoration: none;
}

.footer-nav a:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Static pages */
.page {
  max-width: 40rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.page h1 {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin: 0 0 1rem;
}

.page h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin: 2rem 0 0.75rem;
}

.page p,
.page li {
  color: var(--ink);
}

.page ul {
  padding-left: 1.25rem;
}

.page-lead {
  font-size: 1.2rem;
  color: var(--ink-muted);
  margin-top: 0;
}

.kofi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
  margin-left: 0.25rem;
  flex-shrink: 0;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--radius);
}

.kofi-badge {
  display: block;
  height: 36px;
  width: auto;
  border: 0;
}

.kofi-icon {
  display: none;
  width: 1.1rem;
  height: 1.1rem;
}

.menu {
  position: relative;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  min-width: 10rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  display: none;
  z-index: 60;
}

.menu-panel.is-open {
  display: block;
}

.menu-panel button {
  width: 100%;
  justify-content: flex-start;
}

.search-bar {
  display: none;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.search-bar.is-open {
  display: flex;
}

.search-bar input {
  flex: 1;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
}

@media (max-width: 640px) {
  :root {
    --header-h: 2.75rem;
    --toolbar-h: 2.75rem;
    --footer-h: 1.75rem;
  }

  body.app .btn-label {
    display: none;
  }

  body.app .brand-text {
    display: none;
  }

  body.app .save-status {
    font-size: 0.65rem;
    max-width: 4.5rem;
  }

  body.app .site-header {
    gap: 0.25rem;
    padding-left: max(0.4rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.4rem, env(safe-area-inset-right, 0px));
  }

  body.app .header-actions {
    gap: 0.05rem;
  }

  body.app .btn-icon,
  body.app .mode-toggle,
  body.app .notes-toggle {
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.45rem;
  }

  body.app .kofi-badge {
    display: none;
  }

  body.app .kofi-icon {
    display: block;
  }

  body.app .kofi-btn {
    margin-left: 0;
    min-width: 2.5rem;
    min-height: 2.5rem;
  }

  body.app .kofi-btn:hover {
    background: color-mix(in srgb, var(--ink) 6%, transparent);
  }

  body.app .site-footer p {
    display: none;
  }

  body.app .footer-nav {
    gap: 0.75rem;
    width: 100%;
    justify-content: center;
  }

  body.app .footer-nav a {
    padding: 0.35rem 0.5rem;
    min-height: 2.5rem;
    display: inline-flex;
    align-items: center;
  }

  body.app .notes-new {
    min-height: 2.25rem;
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
  }

  body.app .notes-item-select {
    padding: 0.65rem 0.55rem;
    min-height: 2.75rem;
  }

  body.app .notes-item-delete {
    min-width: 2.5rem;
    min-height: 2.5rem;
  }
}

@media (max-width: 380px) {
  body.app .save-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media print {
  .site-header,
  .toolbar,
  .drawing-tools,
  .site-footer,
  .search-bar,
  .skip-link,
  .notes-sidebar,
  .notes-backdrop,
  .notes-toggle,
  #draw-canvas {
    display: none !important;
  }

  body,
  body.app {
    background: white;
    color: black;
    height: auto;
    overflow: visible;
    display: block;
  }

  .workspace,
  .workspace-main {
    display: block;
    overflow: visible;
    height: auto;
  }

  .editor-shell {
    border: none !important;
    box-shadow: none !important;
    height: auto !important;
    overflow: visible !important;
  }
}
