/* ==========================================================================
   miraieditor — Grid Paper Minimal Text Editor
   ========================================================================== */

/* ---- Reset & Base ---------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --grid-size: 24px;
  --grid-color: rgba(180, 195, 210, 0.25);
  --grid-thick: rgba(160, 180, 200, 0.15);
  --bg: #f8f9fb;
  --fg: #2c2f36;
  --accent: #5b7fff;
  --accent-glow: rgba(91, 127, 255, 0.55);
  --font-main: "Inter", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Fira Code", "JetBrains Mono", "Monaco", "Consolas", monospace;
  --letter-sp: 0.12em;
  --logo-gap: 18px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background: var(--bg);
  color: var(--fg);
}

/* ---- Grid background ------------------------------------------------- */
body.grid-mode {
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px),
    linear-gradient(var(--grid-thick) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-thick) 1px, transparent 1px);
  background-size:
    var(--grid-size) var(--grid-size),
    var(--grid-size) var(--grid-size),
    calc(var(--grid-size) * 4) calc(var(--grid-size) * 4),
    calc(var(--grid-size) * 4) calc(var(--grid-size) * 4);
}

/* ---- Editor area ----------------------------------------------------- */
#editor-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
}

#editor {
  width: 100%;
  height: 100%;
  padding: 48px 56px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: var(--font-main);
  font-size: 14.5px;
  line-height: 1.85;
  letter-spacing: var(--letter-sp);
  color: var(--fg);
  caret-color: var(--accent);
  tab-size: 4;
  -moz-tab-size: 4;
}

#editor::placeholder {
  color: rgba(44, 47, 54, 0.2);
  letter-spacing: 0.25em;
  font-size: 13px;
}

/* ---- Code mode (`:py`) ----------------------------------------------- */
body.code-mode #editor {
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: 0.02em;
  line-height: 1.7;
}

/* ---- Markdown preview ------------------------------------------------ */
/* Visual editor (Discord-style contenteditable) */
#visual-editor {
  display: none;
  position: absolute;
  inset: 0;
  padding: 48px 56px;
  overflow-y: auto;
  background: transparent;
  font-family: var(--font-main);
  font-size: 14.5px;
  line-height: 1.85;
  letter-spacing: var(--letter-sp);
  color: var(--fg);
  outline: none;
  caret-color: var(--accent);
  white-space: pre-wrap;
  word-wrap: break-word;
}

#visual-editor:empty::before {
  content: "s t a r t   t y p i n g . . .";
  color: rgba(44, 47, 54, 0.2);
  letter-spacing: 0.25em;
  font-size: 13px;
}

body.md-mode #editor {
  display: none;
}

body.md-mode #visual-editor {
  display: block;
}

/* ---- Visual editor inline formatting --------------------------------- */
#visual-editor .md-bold {
  font-weight: 700;
}

#visual-editor .md-italic {
  font-style: italic;
}

#visual-editor .md-strike {
  text-decoration: line-through;
  color: rgba(44, 47, 54, 0.45);
}

#visual-editor .md-code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(91, 127, 255, 0.08);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.02em;
}

#visual-editor .md-link {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(91, 127, 255, 0.3);
  cursor: pointer;
}

#visual-editor .md-heading {
  font-weight: 700;
  letter-spacing: 0.06em;
}

#visual-editor .md-h1 {
  font-size: 1.8em;
}

#visual-editor .md-h2 {
  font-size: 1.45em;
}

#visual-editor .md-h3 {
  font-size: 1.2em;
}

#visual-editor .md-h4 {
  font-size: 1.05em;
}

#visual-editor .md-blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: rgba(44, 47, 54, 0.6);
  display: block;
}

#visual-editor .md-hr {
  display: block;
  border: none;
  border-top: 1px solid var(--grid-color);
  margin: 0.3em 0;
}

#visual-editor .md-codeblock {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #1e2028;
  color: #d4d6df;
  padding: 12px 16px;
  border-radius: 6px;
  letter-spacing: 0.02em;
  margin: 0.3em 0;
  white-space: pre;
}

#visual-editor .md-syntax {
  color: rgba(44, 47, 54, 0.2);
  font-size: 0.85em;
  user-select: text;
}

/* ---- Ghost cursors --------------------------------------------------- */
.ghost-cursor {
  position: absolute;
  width: 2px;
  pointer-events: none;
  z-index: 10;
  border-radius: 1px;
  animation: ghost-pulse 1.6s ease-in-out infinite;
}

@keyframes ghost-pulse {

  0%,
  100% {
    opacity: 0.7;
  }

  50% {
    opacity: 1;
  }
}

/* Ghost cursor colors (rotate through) */
.ghost-cursor[data-idx="0"] {
  background: #ff6b8a;
  box-shadow: 0 0 8px #ff6b8a88, 0 0 20px #ff6b8a44;
}

.ghost-cursor[data-idx="1"] {
  background: #4ecdc4;
  box-shadow: 0 0 8px #4ecdc488, 0 0 20px #4ecdc444;
}

.ghost-cursor[data-idx="2"] {
  background: #ffe66d;
  box-shadow: 0 0 8px #ffe66d88, 0 0 20px #ffe66d44;
}

.ghost-cursor[data-idx="3"] {
  background: #a78bfa;
  box-shadow: 0 0 8px #a78bfa88, 0 0 20px #a78bfa44;
}

.ghost-cursor[data-idx="4"] {
  background: #f97316;
  box-shadow: 0 0 8px #f9731688, 0 0 20px #f9731644;
}

/* ---- Save indicator -------------------------------------------------- */
#save-indicator {
  position: fixed;
  top: 20px;
  right: 24px;
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(44, 47, 54, 0.25);
  transition: color var(--transition), opacity var(--transition);
  pointer-events: none;
  z-index: 50;
}

#save-indicator.saving {
  color: var(--accent);
}

#save-indicator.saved {
  color: rgba(76, 175, 80, 0.6);
}

/* ---- Peer counter ---------------------------------------------------- */
#peer-count {
  position: fixed;
  top: 20px;
  left: 24px;
  font-size: 10px;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: rgba(44, 47, 54, 0.25);
  z-index: 50;
  display: none;
}

#peer-count.visible {
  display: block;
}

/* ---- Logo & footer links --------------------------------------------- */
#logo-area {
  position: fixed;
  bottom: 24px;
  right: 28px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#logo-links {
  display: flex;
  gap: 16px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition), transform var(--transition);
  pointer-events: none;
}

#logo-area:hover #logo-links {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

#logo-links a {
  font-size: 9px;
  letter-spacing: 0.35em;
  text-transform: uppercase;
  color: rgba(44, 47, 54, 0.35);
  text-decoration: none;
  transition: color var(--transition);
}

#logo-links a:hover {
  color: var(--accent);
}

#logo-img {
  height: 18px;
  opacity: 0.2;
  transition: opacity var(--transition);
  cursor: default;
  user-select: none;
}

#logo-area:hover #logo-img {
  opacity: 0.45;
}

/* If logo image fails to load, show text fallback */
#logo-text {
  font-size: 10px;
  letter-spacing: 0.5em;
  text-transform: lowercase;
  color: rgba(44, 47, 54, 0.15);
  cursor: default;
  user-select: none;
  transition: color var(--transition);
}

#logo-area:hover #logo-text {
  color: rgba(44, 47, 54, 0.35);
}

/* ---- Mode badge ------------------------------------------------------ */
#mode-badge {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: rgba(44, 47, 54, 0.2);
  z-index: 50;
  transition: color var(--transition);
}

/* ---- Scrollbar ------------------------------------------------------- */
#editor::-webkit-scrollbar,
#visual-editor::-webkit-scrollbar {
  width: 6px;
}

#editor::-webkit-scrollbar-track,
#visual-editor::-webkit-scrollbar-track {
  background: transparent;
}

#editor::-webkit-scrollbar-thumb,
#visual-editor::-webkit-scrollbar-thumb {
  background: rgba(44, 47, 54, 0.1);
  border-radius: 3px;
}

#editor::-webkit-scrollbar-thumb:hover,
#visual-editor::-webkit-scrollbar-thumb:hover {
  background: rgba(44, 47, 54, 0.2);
}

/* ---- Responsive ------------------------------------------------------ */
@media (max-width: 720px) {

  #editor,
  #visual-editor {
    padding: 28px 24px;
  }

  #logo-area {
    bottom: 12px;
    right: 16px;
  }
}