/* Notepad - dark by default, light on toggle. */

:root,
:root[data-theme="dark"] {
  --bg:        #16181d;
  --bg-2:      #1d2027;
  --bg-3:      #262a33;
  --paper:     #1a1d23;
  --text:      #e7e9ee;
  --muted:     #8b91a1;
  --border:    #2f343f;
  --accent:    #5b9dff;
  --ok:        #3fb950;
  --err:       #ff6b6b;
}

:root[data-theme="light"] {
  --bg:        #eef0f4;
  --bg-2:      #ffffff;
  --bg-3:      #e6e9ef;
  --paper:     #ffffff;
  --text:      #1c1f26;
  --muted:     #6b7280;
  --border:    #d3d8e0;
  --accent:    #2563eb;
  --ok:        #15803d;
  --err:       #b91c1c;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ------------------------------------------------------------- sign in --- */

body.gate {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}

.gate-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.gate-hint {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.gate-card input {
  width: 100%;
  margin-bottom: 10px;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
}

.gate-card input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.gate-card button {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.gate-card button:hover { filter: brightness(1.1); }

.gate-error {
  margin: 14px 0 0;
  color: var(--err);
  font-size: 13px;
}

/* ---------------------------------------------------------------- shell --- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ------------------------------------------------------------------ tabs --- */

#tabbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

#tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  padding: 8px 10px 8px 14px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 9px 9px 0 0;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.tab:hover { background: var(--bg-3); }

.tab.active {
  background: var(--paper);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 2px 0 var(--accent);
}

.tab.dragging { opacity: .4; }
.tab.drop-target { border-left: 2px solid var(--accent); }

.tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.tab-label.editing {
  outline: 1px solid var(--accent);
  border-radius: 3px;
  padding: 0 3px;
  cursor: text;
}

.tab-close {
  background: none;
  border: 0;
  padding: 0 2px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  border-radius: 4px;
  cursor: pointer;
  opacity: .55;
}

.tab-close:hover { opacity: 1; background: var(--bg-3); color: var(--err); }

.tab-add {
  flex: none;
  width: 30px;
  height: 30px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}

.tab-add:hover { background: var(--bg-3); color: var(--text); }

.tabbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding-bottom: 6px;
}

.status {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.status.ok  { color: var(--ok); }
.status.err { color: var(--err); }
.status.pending { color: var(--muted); }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 4px 8px;
  color: var(--muted);
  cursor: pointer;
}

.icon-btn:hover { color: var(--text); }

/* -------------------------------------------------------------- toolbar --- */

#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

#toolbar button {
  min-width: 30px;
  height: 30px;
  padding: 0 7px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

#toolbar button:hover { background: var(--bg-3); }
#toolbar button.on { background: var(--bg-3); border-color: var(--accent); color: var(--accent); }

#toolbar select {
  height: 30px;
  padding: 0 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.sep {
  width: 1px;
  height: 20px;
  margin: 0 5px;
  background: var(--border);
}

.color-well { position: relative; display: inline-flex; cursor: pointer; }

.color-well input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.swatch {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: transparent;
  color: #111;
  font-weight: 700;
  font-size: 13px;
}

.palette { display: flex; gap: 3px; }

.palette button {
  width: 18px !important;
  min-width: 18px !important;
  height: 18px;
  padding: 0 !important;
  background: var(--c) !important;
  border: 1px solid rgba(128, 128, 128, .45) !important;
  border-radius: 50%;
}

.palette button.none {
  background: var(--bg) !important;
  background-image: linear-gradient(45deg, transparent 44%, var(--err) 44%, var(--err) 56%, transparent 56%) !important;
}

/* --------------------------------------------------------------- editor --- */

#editor {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 45vh;
  background: var(--paper);
  outline: none;
  font-size: 16px;
  line-height: 1.7;
  word-wrap: break-word;
}

#editor.drop { box-shadow: inset 0 0 0 2px var(--accent); }

#editor img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  vertical-align: top;
  cursor: zoom-in;
}

#editor a { color: var(--accent); }

#editor blockquote {
  margin: 12px 0;
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

#editor pre {
  padding: 12px 14px;
  background: var(--bg-3);
  border-radius: 8px;
  font: 13px/1.55 ui-monospace, Consolas, "Courier New", monospace;
  white-space: pre-wrap;
}

#editor ul, #editor ol { padding-left: 26px; }

#editor:empty::before {
  content: "Start typing. Paste images straight in - Ctrl+S saves, but it also saves itself.";
  color: var(--muted);
}

/* ---------------------------------------------------------- search bar --- */

#findbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

#findbar[hidden] { display: none; }

.find-icon { opacity: .55; font-size: 13px; }

#find-input {
  width: 240px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text);
  font-size: 14px;
}

#find-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

#findbar button {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

#findbar button:hover { background: var(--bg-3); }
#findbar button.on { background: var(--bg-3); border-color: var(--accent); color: var(--accent); }

.find-count {
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.find-count.err { color: var(--err); }

.find-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  margin-left: 6px;
  padding-bottom: 1px;
}

.find-chip {
  flex: none;
  padding: 3px 9px !important;
  height: 26px !important;
  background: var(--bg) !important;
  border: 1px solid var(--border) !important;
  border-radius: 20px !important;
  color: var(--text) !important;
  font-size: 12px !important;
  white-space: nowrap;
}

.find-chip.active { border-color: var(--accent) !important; color: var(--accent) !important; }
.find-chip.zero { opacity: .4; cursor: default; }

#find-close { margin-left: auto; font-size: 16px !important; }

::highlight(np-find) {
  background: #ffe066;
  color: #17181c;
}

::highlight(np-find-on) {
  background: #ff9f1c;
  color: #17181c;
}

/* ------------------------------------------------ selected-image popup --- */

#editor img.img-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#img-pop {
  position: fixed;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, .4);
}

#img-pop[hidden] { display: none; }

#img-pop button {
  height: 26px;
  padding: 0 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

#img-pop button:hover { background: var(--bg-3); }
#img-pop #pop-delete:hover { color: var(--err); }

/* --------------------------------------------------------- draw canvas --- */

#draw-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(6, 8, 12, .72);
}

#draw-modal[hidden] { display: none; }

.draw-panel {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  max-height: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}

.draw-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.draw-tools button {
  min-width: 30px;
  height: 30px;
  padding: 0 9px;
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.draw-tools button:hover { background: var(--bg-3); }
.draw-tools button.on { background: var(--bg-3); border-color: var(--accent); color: var(--accent); }

.draw-tools button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.draw-tools button.primary:hover { filter: brightness(1.1); }
.draw-tools button:disabled { opacity: .5; cursor: default; }

.draw-spacer { flex: 1; }

#draw-width { width: 96px; accent-color: var(--accent); }

.draw-stage {
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: auto;
  background: var(--bg-3);
}

#draw-canvas {
  max-width: min(1100px, 88vw);
  max-height: 72vh;
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 2px 14px rgba(0, 0, 0, .35);
  cursor: crosshair;
  touch-action: none;
}

@media (max-width: 640px) {
  #editor { padding: 16px 14px 45vh; }
  .palette { display: none; }
  .tab { max-width: 140px; }
  #find-input { width: 130px; }
  .find-tabs { display: none; }
  #draw-canvas { max-width: 92vw; max-height: 58vh; }
}
