:root {
  --font-mono: 'SF Mono', 'Menlo', 'Monaco', 'Consolas', monospace;
  --color-highlight: #fef08a;
  --color-toolbar-bg: #1f2937;
  --color-bg: #ffffff;
  --color-text: #1f2937;
  --color-border: #e5e7eb;
  --color-gutter: #9ca3af;
  --color-error: #dc2626;
}

/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Body */
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
}

/* Landing */
.landing {
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem;
}

.landing h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.landing p.subtitle {
  color: var(--color-gutter);
  margin-bottom: 1.5rem;
}

.landing input[type="text"] {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  outline: none;
}

.landing input[type="text"]:focus {
  border-color: var(--color-toolbar-bg);
}

.landing .divider {
  text-align: center;
  color: var(--color-gutter);
  margin: 1.25rem 0;
  font-size: 0.875rem;
}

.landing textarea {
  width: 100%;
  min-height: 200px;
  padding: 0.625rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  resize: vertical;
  outline: none;
}

.landing textarea:focus {
  border-color: var(--color-toolbar-bg);
}

.landing button {
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.625rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--color-toolbar-bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.landing button:hover {
  opacity: 0.9;
}

.landing .error {
  color: var(--color-error);
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: 6px;
  padding: 2rem;
  text-align: center;
  color: var(--color-gutter);
  font-size: 0.875rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.drop-zone--active {
  border-color: var(--color-toolbar-bg);
  color: var(--color-text);
}

/* Recent sessions */
.recent-sessions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.recent-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.recent-btn {
  flex: 1;
  text-align: left;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: #f9fafb;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--color-text);
}

.recent-btn:hover {
  background: var(--color-border);
}

.recent-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-gutter);
  font-size: 0.875rem;
  padding: 4px;
}

.recent-delete:hover {
  color: var(--color-error);
}

/* Viewer */
.viewer {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
}

.viewer .lines {
  padding: 0.5rem 0;
}

.viewer .line {
  display: flex;
}

.viewer .gutter {
  min-width: 3em;
  padding-right: 1em;
  text-align: right;
  color: var(--color-gutter);
  user-select: none;
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  align-items: baseline;
  gap: 2px;
}

.gutter-dot {
  color: #3b82f6;
  font-size: 0.5rem;
  line-height: 1;
}

.viewer .text {
  white-space: pre-wrap;
  word-break: break-all;
  flex: 1;
}

/* Toolbar */
.toolbar {
  position: fixed;
  background: var(--color-toolbar-bg);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 1000;
}

.toolbar button {
  color: #ffffff;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  font-size: 0.875rem;
}

.toolbar button:hover {
  opacity: 0.8;
}

.toolbar-more {
  position: relative;
  display: inline-block;
}

.toolbar-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--color-toolbar-bg);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  padding: 4px 0;
  min-width: 140px;
  z-index: 1001;
}

.toolbar-dropdown--open {
  display: flex;
  flex-direction: column;
}

.toolbar-dropdown-item {
  text-align: left;
  padding: 6px 12px;
  white-space: nowrap;
}

/* Highlight */
mark {
  background: var(--color-highlight);
  padding: 0;
}

/* Export */
.export {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem;
}

.export .summary {
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  background: #f9fafb;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 1rem;
  overflow-x: auto;
}

.export button {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #ffffff;
  background: var(--color-toolbar-bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.export button:hover {
  opacity: 0.9;
}

/* Editor header */
.editor-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.save-indicator {
  font-size: 0.75rem;
  color: var(--color-gutter);
}

/* Annotation input */
.annotation-input {
  width: 100%;
  min-height: 60px;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  resize: vertical;
  outline: none;
}

.annotation-input:focus {
  border-color: var(--color-toolbar-bg);
}

/* Editor layout */
.editor-layout {
  display: flex;
  height: calc(100vh - 41px);
}

.editor-layout .viewer {
  flex: 1;
  overflow-y: auto;
}

/* Notes panel */
.notes-panel {
  width: 300px;
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  background: #f9fafb;
  flex-shrink: 0;
}

.notes-header {
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: #f9fafb;
}

.notes-empty {
  padding: 1.5rem 1rem;
  color: var(--color-gutter);
  font-size: 0.8125rem;
  text-align: center;
}

.notes-list {
  padding: 0.5rem;
}

.note-card {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  margin-bottom: 0.5rem;
  background: #ffffff;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: box-shadow 0.15s;
}

.note-card:hover {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.note-card--active {
  box-shadow: 0 0 0 2px var(--color-toolbar-bg);
}

.note-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.note-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.note-badge--comment {
  background: #dbeafe;
  color: #1e40af;
}

.note-badge--suggest {
  background: #dcfce7;
  color: #166534;
}

.note-badge--delete {
  background: #fee2e2;
  color: #991b1b;
}

.note-badge--question {
  background: #f3e8ff;
  color: #6b21a8;
}

.note-badge--expand {
  background: #fef3c7;
  color: #92400e;
}

.note-badge--keep {
  background: #ccfbf1;
  color: #115e59;
}

.note-badge--unclear {
  background: #f3f4f6;
  color: #4b5563;
}

.note-line {
  font-size: 0.6875rem;
  color: var(--color-gutter);
  margin-left: auto;
}

.note-edit {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-gutter);
  font-size: 0.75rem;
  padding: 0 2px;
  line-height: 1;
}

.note-edit:hover {
  color: var(--color-toolbar-bg);
}

.note-edit-input {
  width: 100%;
  min-height: 40px;
  padding: 0.375rem 0.5rem;
  font-size: 0.8125rem;
  border: 1px solid var(--color-toolbar-bg);
  border-radius: 3px;
  resize: vertical;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}

.note-delete {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-gutter);
  font-size: 0.75rem;
  padding: 0 2px;
  line-height: 1;
}

.note-delete:hover {
  color: var(--color-error);
}

.note-snippet {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-gutter);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.note-text {
  font-size: 0.8125rem;
  line-height: 1.4;
}

/* Highlight active */
mark.mark--active {
  outline: 2px solid var(--color-toolbar-bg);
  outline-offset: 1px;
}

/* Keyboard navigation */
.viewer--focused {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

.line--current {
  background: #eff6ff;
}

/* Search */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 4px 1rem;
  border-bottom: 1px solid var(--color-border);
  background: #f9fafb;
}

.search-input {
  flex: 1;
  padding: 4px 8px;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  outline: none;
}

.search-input:focus {
  border-color: var(--color-toolbar-bg);
}

.search-count {
  font-size: 0.75rem;
  color: var(--color-gutter);
  white-space: nowrap;
  min-width: 3em;
}

mark.search-match {
  background: #fdba74;
  border-radius: 2px;
}

mark.search-match--current {
  background: #f97316;
  color: #ffffff;
  outline: 2px solid #ea580c;
  outline-offset: 0px;
}

/* Command palette */
.palette-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  z-index: 2000;
}

.palette-panel {
  background: #ffffff;
  border-radius: 8px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.palette-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: none;
  border-bottom: 1px solid var(--color-border);
  outline: none;
  font-family: inherit;
}

.palette-list {
  max-height: 320px;
  overflow-y: auto;
}

.palette-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.palette-item--active {
  background: #eff6ff;
}

.palette-label {
  flex: 1;
}

.palette-kbd {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--color-gutter);
  background: #f3f4f6;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 0.5rem;
}

/* Help overlay */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.help-panel {
  background: #ffffff;
  border-radius: 8px;
  padding: 1.5rem 2rem;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.help-panel h2 {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.help-dismiss {
  display: block;
  font-size: 0.75rem;
  color: var(--color-gutter);
  margin-bottom: 1rem;
}

.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.help-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-gutter);
  padding: 0.75rem 0 0.25rem;
  border-bottom: 1px solid var(--color-border);
}

.help-table td {
  padding: 0.25rem 0;
}

.help-key {
  width: 120px;
  white-space: nowrap;
}

.help-key kbd {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: #f3f4f6;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 6px;
}

/* Tutorial start button */
.landing .tutorial-start {
  width: auto;
  display: block;
  margin: 0 auto 1.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #3b82f6;
  background: none;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
}

.landing .tutorial-start:hover {
  background: #eff6ff;
  border-color: #3b82f6;
}

/* Tutorial panel */
.tutorial-panel {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 520px;
  background: #ffffff;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 3000;
  overflow: hidden;
}

.tutorial-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #f9fafb;
  border-bottom: 1px solid var(--color-border);
}

.tutorial-dots {
  display: flex;
  gap: 4px;
  flex: 1;
}

.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-border);
}

.tutorial-dot--active {
  background: #3b82f6;
}

.tutorial-dot--done {
  background: #86efac;
}

.tutorial-step-count {
  font-size: 0.75rem;
  color: var(--color-gutter);
}

.tutorial-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-gutter);
  font-size: 1rem;
  padding: 0 4px;
  line-height: 1;
}

.tutorial-close:hover {
  color: var(--color-text);
}

.tutorial-body {
  padding: 1rem;
}

.tutorial-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.tutorial-message {
  font-size: 0.875rem;
  line-height: 1.5;
  color: #4b5563;
  margin-bottom: 0.75rem;
}

.tutorial-message code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
}

.tutorial-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tutorial-btn {
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: #ffffff;
  color: var(--color-text);
}

.tutorial-btn:hover {
  background: #f9fafb;
}

.tutorial-btn--primary {
  background: #3b82f6;
  color: #ffffff;
  border-color: #3b82f6;
}

.tutorial-btn--primary:hover {
  background: #2563eb;
}

.tutorial-hint {
  font-size: 0.8125rem;
  color: #3b82f6;
  font-weight: 500;
}

/* Tutorial highlight */
.tutorial-highlight {
  outline: 2px solid #3b82f6 !important;
  outline-offset: 2px;
  animation: tutorial-pulse 1.5s ease-in-out infinite;
}

@keyframes tutorial-pulse {
  0%, 100% { outline-color: #3b82f6; }
  50% { outline-color: #93c5fd; }
}

/* ─── Responsive / Mobile ─── */
@media (max-width: 640px) {
  /* Landing page */
  .landing {
    padding: 1rem;
  }

  .landing h1 {
    font-size: 1.5rem;
  }

  /* Editor: stack viewer and notes vertically */
  .editor-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 41px);
  }

  .editor-layout .viewer {
    flex: none;
    overflow-y: visible;
  }

  .notes-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border);
    max-height: 50vh;
    overflow-y: auto;
  }

  .apply-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border);
    max-height: 50vh;
  }

  /* Viewer: smaller gutter, allow horizontal scroll */
  .viewer .gutter {
    min-width: 2em;
    padding-right: 0.5em;
  }

  .viewer .text {
    font-size: 0.75rem;
  }

  .viewer {
    font-size: 0.75rem;
  }

  /* Editor header: wrap and shrink */
  .editor-header {
    padding: 0.375rem 0.5rem;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .editor-header span {
    font-size: 0.8125rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
  }

  /* Toolbar: keep on screen */
  .toolbar {
    left: 0.5rem !important;
    right: 0.5rem;
    width: auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
  }

  /* Search bar */
  .search-bar {
    padding: 4px 0.5rem;
  }

  /* Help panel */
  .help-panel {
    padding: 1rem;
  }

  .help-key {
    width: auto;
  }

  /* Export */
  .export {
    padding: 1rem;
  }

  /* Annotation input */
  .annotation-input {
    font-size: 0.8125rem;
  }

  /* Status bar */
  .status-bar {
    padding: 4px 0.5rem;
    font-size: 0.6875rem;
  }
}

/* Apply view */
.apply-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 3px;
  text-transform: uppercase;
  background: #dbeafe;
  color: #1e40af;
  margin-right: auto;
}

.apply-panel {
  width: 320px;
  border-left: 1px solid var(--color-border);
  overflow-y: auto;
  background: #f9fafb;
  flex-shrink: 0;
}

.apply-card {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  margin-bottom: 0.5rem;
  background: #ffffff;
  cursor: pointer;
  font-size: 0.8125rem;
  transition: box-shadow 0.15s;
}

.apply-card:hover {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Status bar */
.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 1rem;
  font-size: 0.75rem;
  color: var(--color-gutter);
  background: #f9fafb;
  border-top: 1px solid var(--color-border);
}
