/* Notepad overlay. Desktop: floating, draggable, resizable, pop-out capable.
   Phone / tablet (.np--full): covers the screen. Popped window (.np--popped):
   fills its own window. Uses the app's theme tokens; falls back sensibly. */

.np {
  --np-ai: #4fd1b8;
  --np-font: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --np-size: 17px;
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: min(440px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 48px));
  min-width: 300px;
  min-height: 320px;
  z-index: 10500;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  background: var(--panel, #141420);
  color: var(--text-primary, #e2e8f0);
  border: 1px solid var(--panel-border, #232334);
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  overflow: hidden;
  resize: both;
}
:root[data-theme="light"] .np { --np-ai: #0b7a68; box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18); }
.np[hidden] { display: none; }

.np--serif { --np-font: Georgia, "Iowan Old Style", "Times New Roman", serif; }
.np--sans  { --np-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.np--mono  { --np-font: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

/* Phone and tablet: the whole screen, with the X. */
.np--full {
  inset: 0;
  right: 0;
  bottom: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  resize: none;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}
body.np-open-full { overflow: hidden; }

/* Its own window. */
.np--popped {
  position: static;
  width: 100vw;
  height: 100vh;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  resize: none;
}
.np-popout-body { margin: 0; background: var(--bg, #0b0b0f); }

.np__bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
  border-bottom: 1px solid var(--panel-border, #232334);
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.np--full .np__bar, .np--popped .np__bar { cursor: default; }
.np__title { font-size: 13px; font-weight: 600; letter-spacing: 0.02em; }
.np__hint {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--text-tertiary, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.np__tools { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.np__btn {
  min-width: 32px;
  height: 32px;
  padding: 0 6px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--text-secondary, #b0b8d0);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.np__btn[hidden] { display: none; }
.np__btn:hover { background: var(--bg-hover, rgba(255, 255, 255, 0.06)); color: var(--text-primary, #e2e8f0); }
.np__btn:focus-visible, .np__link:focus-visible, .np__input:focus-visible { outline: 2px solid var(--accent, #7c9bff); outline-offset: -2px; }
.np--full .np__btn { min-width: 44px; height: 44px; font-size: 15px; }

/* The writing surface: a native textarea over a mirror that colours the lines
   the companion wrote. Both must share every metric or the text drifts. */
.np__sheet { position: relative; flex: 1; min-height: 0; }
.np__backdrop, .np__input {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  margin: 0;
  padding: 16px 18px;
  border: 0;
  font-family: var(--np-font);
  font-size: var(--np-size);
  line-height: 1.65;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
  overflow-y: scroll;
  scrollbar-width: none;
}
.np__backdrop::-webkit-scrollbar, .np__input::-webkit-scrollbar { display: none; }
.np__backdrop { color: var(--text-primary, #e2e8f0); pointer-events: none; z-index: 1; }
.np__input {
  z-index: 2;
  width: 100%;
  height: 100%;
  resize: none;
  background: transparent;
  color: transparent;
  caret-color: var(--text-primary, #e2e8f0);
  outline: none;
}
.np__input::placeholder { color: var(--text-tertiary, #64748b); }
.np__input::selection { background: color-mix(in srgb, var(--accent, #7c9bff) 40%, transparent); color: transparent; }
.np-ai { color: var(--np-ai); }

/* The margin: where the companion's note types itself out. */
.np__margin {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-height: 52px;
  padding: 10px 18px;
  border-top: 1px solid var(--panel-border, #232334);
  font-family: var(--np-font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--np-ai);
}
.np__margin:not(.is-active) { color: var(--text-tertiary, #64748b); }
.np__margin:not(.is-active)::before { content: "\00a0"; }
.np__note { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.np__keys { flex: none; font: 12px system-ui, sans-serif; color: var(--text-tertiary, #64748b); white-space: nowrap; }
.np__keys[hidden] { display: none; }
.np__keys kbd {
  padding: 1px 6px;
  border: 1px solid var(--panel-border, #232334);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface-3, #222222);
  color: var(--text-secondary, #b0b8d0);
  font: inherit;
}

.np__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 8px;
  font-size: 12px;
  color: var(--text-tertiary, #64748b);
}
.np__link {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
  padding: 4px 2px;
}
.np__link:hover { color: var(--text-primary, #e2e8f0); }
.np--full .np__link { padding: 10px 6px; }

.np__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 720px) {
  .np__hint { display: none; }
  .np__backdrop, .np__input { padding: 14px 16px; }
}
