* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-color: #272822;
  --gutter-bg: #272822;
  --gutter-text: #8f908a;
  --editor-bg: #272822;
  --editor-text: #f8f8f2;
  --line-highlight: #3e3d32;
  --cursor-color: #f8f8f0;
  --selection-bg: #49483e;
  --accent-color: #a6e22e;
  --font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
  --font-size: 13px;
  --line-height: 1.6;
  --gutter-width: 70px;
  --auth-bar-height: 36px;
}

html, body {
  height: 100%;
  background: var(--bg-color);
  overflow: hidden;
}

/* Auth bar */
.auth-bar {
  height: var(--auth-bar-height);
  background: #1e1f1c;
  border-bottom: 1px solid #3e3d32;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-family: var(--font-family);
  font-size: 12px;
}

.auth-status {
  color: var(--gutter-text);
}

.auth-status.synced {
  color: var(--accent-color);
}

.auth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.login-form input {
  background: #3e3d32;
  border: 1px solid #4e4d42;
  color: var(--editor-text);
  padding: 4px 8px;
  font-family: var(--font-family);
  font-size: 11px;
  border-radius: 3px;
  width: 140px;
}

.login-form input[type="password"] {
  width: 80px;
}

.login-form input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.login-form input::placeholder {
  color: #75715e;
}

.login-form button,
.logout-btn {
  background: #3e3d32;
  border: 1px solid #4e4d42;
  color: var(--editor-text);
  padding: 4px 10px;
  font-family: var(--font-family);
  font-size: 11px;
  border-radius: 3px;
  cursor: pointer;
}

.login-form button:hover,
.logout-btn:hover {
  background: #4e4d42;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #3e3d32;
  color: var(--editor-text);
  padding: 10px 16px;
  border-radius: 4px;
  font-family: var(--font-family);
  font-size: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.editor-container {
  display: flex;
  height: calc(100% - var(--auth-bar-height));
  font-family: var(--font-family);
  font-size: var(--font-size);
  line-height: var(--line-height);
}

.gutter {
  width: var(--gutter-width);
  min-width: var(--gutter-width);
  background: var(--gutter-bg);
  color: var(--gutter-text);
  text-align: right;
  padding: 10px 8px 10px 0;
  user-select: none;
  overflow: hidden;
  border-right: 1px solid #3e3d32;
}

.gutter-line {
  height: calc(var(--font-size) * var(--line-height));
  padding-right: 8px;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
}

.editor {
  flex: 1;
  background: var(--editor-bg);
  color: var(--editor-text);
  padding: 10px 10px 10px 16px;
  outline: none;
  overflow-y: auto;
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  caret-color: var(--cursor-color);
}

.editor:focus {
  outline: none;
}

.editor::selection {
  background: var(--selection-bg);
}

.editor div {
  min-height: calc(var(--font-size) * var(--line-height));
  color: var(--editor-text); /* Ensure new lines don't inherit gray from styled spans */
}

/* Scrollbar styling */
.editor::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

.editor::-webkit-scrollbar-track {
  background: var(--bg-color);
}

.editor::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 6px;
  border: 3px solid var(--bg-color);
}

.editor::-webkit-scrollbar-thumb:hover {
  background: #5a5a5a;
}

/* Sync gutter scroll with editor */
.gutter {
  overflow-y: hidden;
}

/* Links */
.link {
  color: #66d9ef;
  text-decoration: underline;
  text-decoration-color: #66d9ef50;
  cursor: pointer;
  position: relative;
}

.link:hover {
  text-decoration-color: #66d9ef;
}

/* Markdown syntax highlighting - Monokai theme */
.md-h1 {
  color: #f92672; /* Pink - H1 */
}

.md-h2 {
  color: #fd971f; /* Orange - H2 */
}

.md-h3 {
  color: #e6db74; /* Yellow - H3 */
}

.md-h4 {
  color: #a6e22e; /* Green - H4 */
}

.md-h5 {
  color: #66d9ef; /* Blue - H5 */
}

.md-h6 {
  color: #ae81ff; /* Purple - H6 */
}

.md-bold-marker {
  color: #75715e; /* Gray - syntax markers */
}

.md-bold {
  color: #f8f8f2; /* White - keep text normal */
  font-weight: bold;
}

.md-italic-marker {
  color: #75715e; /* Gray */
}

.md-italic {
  color: #f8f8f2;
  font-style: italic;
}

.md-code-marker {
  color: #75715e; /* Gray */
}

.md-code {
  color: #e6db74; /* Yellow - code */
  background: #3e3d32;
  padding: 1px 4px;
  border-radius: 3px;
}

.md-list-marker {
  color: #f92672; /* Pink - list bullets */
}

.md-quote-marker {
  color: #fd971f; /* Orange - blockquote */
}

.md-strike-marker {
  color: #75715e; /* Gray */
}

.md-strike {
  text-decoration: line-through;
  color: #75715e;
}

.link:hover::after {
  content: "⌘+click to open";
  position: absolute;
  left: 0;
  top: 100%;
  margin-top: 4px;
  padding: 3px 6px;
  background: #1e1f1c;
  border: 1px solid #3e3d32;
  color: #8f908a;
  font-size: 10px;
  white-space: nowrap;
  border-radius: 3px;
  z-index: 100;
  pointer-events: none;
}

/* Mobile styles */
@media (max-width: 600px) {
  :root {
    --gutter-width: 52px;
    --font-size: 16px; /* Match editor to prevent iOS zoom */
    --line-height: 1.5;
    --auth-bar-height: 48px;
  }

  .auth-bar {
    padding: 6px 8px;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .auth-status {
    font-size: 11px;
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .login-form {
    flex: 1;
    min-width: 0;
    gap: 4px;
  }

  .login-form input[type="email"] {
    flex: 1;
    min-width: 80px;
    width: auto;
    padding: 8px;
    font-size: 16px;
  }

  .login-form input[type="password"] {
    width: 70px;
    min-width: 70px;
    padding: 8px;
    font-size: 16px;
  }

  .login-form button,
  .logout-btn {
    padding: 8px 12px;
    font-size: 12px;
    white-space: nowrap;
  }

  .gutter {
    padding: 8px 4px 8px 4px;
  }

  .gutter-line {
    font-size: 11px;
    padding-right: 4px;
    height: calc(16px * 1.5); /* Match editor line height exactly */
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }

  .editor {
    padding: 8px 8px 8px 10px;
    font-size: 16px;
    line-height: 1.5;
  }

  .editor div {
    min-height: calc(16px * 1.5);
    line-height: 1.5;
  }

  .toast {
    left: 10px;
    right: 10px;
    bottom: 10px;
    text-align: center;
  }
}

/* Touch-friendly: larger tap targets */
@media (pointer: coarse) {
  .login-form input,
  .login-form button,
  .logout-btn {
    min-height: 36px;
  }

  .gutter-line {
    min-height: 24px;
  }
}

/* Prevent horizontal scroll on mobile */
@media (max-width: 600px) {
  .editor {
    word-break: break-word;
    overflow-wrap: anywhere;
  }
}
