:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #d5dbe3;
  --button: #f5f7fa;
  --button-hover: #e6ebf1;
  --accent: #2f6fde;
  --editor-bg: #ffffff;
  --font-size: 16px;
}

[data-theme="dark"] {
  --bg: #15181d;
  --panel: #1e2228;
  --text: #e3e7ec;
  --muted: #8d97a3;
  --border: #323843;
  --button: #272c34;
  --button-hover: #323843;
  --accent: #6a9cff;
  --editor-bg: #1a1d22;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  gap: 8px;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  white-space: nowrap;
}

.filename {
  flex: 1;
  min-width: 0;
  max-width: 320px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
}

.filename:hover { border-color: var(--border); }
.filename:focus { outline: none; border-color: var(--accent); background: var(--panel); }

.save-status {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

/* Toolbar */
.toolbar,
.findbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.group + .group {
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--button);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

button:hover { background: var(--button-hover); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

/* Find bar */
.findbar[hidden] { display: none; }

.findbar input[type="text"] {
  flex: 1 1 160px;
  min-width: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--editor-bg);
  color: var(--text);
  font: inherit;
}

.findbar input[type="text"]:focus { outline: none; border-color: var(--accent); }

.check {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  white-space: nowrap;
}

.find-info { color: var(--muted); font-size: 13px; }
.findbar .close { margin-left: auto; }

/* Editor */
.editor-wrap {
  flex: 1;
  min-height: 0;
}

.editor {
  width: 100%;
  height: 100%;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--editor-bg);
  color: var(--text);
  font-family: Consolas, "Cascadia Mono", "Courier New", monospace;
  font-size: var(--font-size);
  line-height: 1.55;
  resize: none;
  tab-size: 4;
}

.editor:focus { outline: none; border-color: var(--accent); }
.editor.nowrap { white-space: pre; overflow-wrap: normal; overflow-x: auto; }

/* Status bar */
.statusbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  padding: 8px 16px;
  border-radius: 6px;
  background: #222;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Print: only the note text */
.print-area { display: none; }

@media print {
  .app, .toast { display: none !important; }
  .print-area {
    display: block;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: Consolas, "Courier New", monospace;
    font-size: 12pt;
    color: #000;
  }
}

/* Small screens */
@media (max-width: 640px) {
  .app { padding: 8px; }
  .brand { font-size: 16px; }
  .group + .group { padding-left: 0; border-left: none; }
  button { padding: 6px 10px; }
  .statusbar { flex-direction: column; gap: 2px; }
}
