*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body[data-theme="light"] {
  --page-bg: #f3eedb;
  --editor-bg: #fffaf0;
  --editor-text: #222222;
  --border: #d7ccb2;
  --button-bg: #efe6ca;
  --button-hover: #e4d8b6;
  --muted-text: #6b675b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --line-color: rgba(120, 110, 80, 0.12);
}

body[data-theme="dark"] {
  --page-bg: #171717;
  --editor-bg: #242424;
  --editor-text: #f2f2f2;
  --border: #3a3a3a;
  --button-bg: #2d2d2d;
  --button-hover: #3a3a3a;
  --muted-text: #b9b9b9;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  --line-color: rgba(255, 255, 255, 0.07);
}

body {
  background: var(--page-bg);
  color: var(--editor-text);
}

button {
  border: 1px solid var(--border);
  background: var(--button-bg);
  color: var(--editor-text);
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.9rem;
}

button:hover {
  background: var(--button-hover);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.editor-shell {
  width: min(820px, 92vw);
  height: min(86vh, 980px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--editor-bg);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.note-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--editor-bg);
  flex-wrap: wrap;
}

.note-toolbar-left,
.note-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.filename {
  color: var(--muted-text);
  font-size: 0.95rem;
}

#editor {
  flex: 1;
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: var(--editor-bg);
  color: var(--editor-text);
  padding: 0 2.25rem 0 2.25rem;
  font-size: 1rem;
  line-height: 32px;
  font-family: "Courier New", Courier, monospace;
  overflow: auto;
  white-space: pre-wrap;
  background-attachment: local;
  caret-color: var(--editor-text);
}

/* This is the important part:
   the top padding becomes part of the first line rhythm */
body[data-lined="on"] #editor {
  padding-top: 32px;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0,
    transparent 31px,
    var(--line-color) 31px,
    var(--line-color) 32px
  );
  background-size: 100% 32px;
  background-attachment: local;
  background-position: 0 25px;
}

body[data-lined="off"] #editor {
  padding-top: 32px;
}

@media (max-width: 640px) {
  .app-shell {
    padding: 1rem;
  }

  .note-toolbar {
    align-items: flex-start;
  }

  #editor {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
    font-size: 0.98rem;
  }

  body[data-lined="on"] #editor,
  body[data-lined="off"] #editor {
    padding-top: 32px;
  }
}