:root {
  --primary: #3d5866;
  --primary-dark: #2b4357;
  --secondary: #689fa7;
  --soft: #e6f0f2;
  --accent: #b84d17;
  --accent-hover: #9c4113;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f2d3a;
  --muted: #4e5d6b;
  --border: #dde3e7;
  --danger: #a32020;
  --ok: #1d6b45;
  --ok-bg: #e5f4ec;
  --warn-bg: #fdf6e3;
  --focus: #1f6fd1;
  --radius: 0.75rem;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 100%;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
}

h1,
h2 {
  color: var(--primary-dark);
  line-height: 1.2;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 1rem;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
}

a {
  color: var(--primary);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

img {
  max-width: 100%;
  height: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Estructura ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  background: var(--primary-dark);
  color: #fff;
}

.top a,
.top .link {
  color: #fff;
}

.top__brand {
  font-weight: 600;
  text-decoration: none;
}

.top__nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-size: 0.95rem;
}

.top__nav form {
  margin: 0;
}

.main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.main--wide {
  max-width: 80rem;
}

.card {
  margin-bottom: 1rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card--warn {
  background: var(--warn-bg);
}

.narrow {
  max-width: 28rem;
  margin: 2rem auto;
}

.muted {
  color: var(--muted);
}

.notice {
  padding: 0.6rem 0.8rem;
  border-left: 3px solid var(--secondary);
  border-radius: 0.4rem;
  background: var(--soft);
  font-size: 0.95rem;
}

.error,
.danger {
  color: var(--danger);
}

.head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.head h1 {
  margin: 0;
}

/* ---------- Botones y campos ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.6rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--primary);
  border-radius: 999px;
  background: var(--surface);
  color: var(--primary);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  background: var(--soft);
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn--small {
  min-height: 2rem;
  padding: 0.25rem 0.75rem;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.field {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 1rem;
}

.field > span {
  font-weight: 600;
}

input[type='text'],
input[type='date'],
textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid #b9c4cb;
  border-radius: 0.5rem;
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.check,
.template {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.4rem 0;
  cursor: pointer;
}

.check input,
.template input {
  margin-top: 0.3rem;
}

.template small {
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  background: #eceff1;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.badge--ok {
  background: var(--ok-bg);
  color: var(--ok);
}

/* ---------- Lista de artículos ---------- */
.posts {
  margin: 0;
  padding: 0;
  list-style: none;
}

.posts__item {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.posts__title {
  font-size: 1.1rem;
  font-weight: 600;
}

.posts__meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.new {
  position: relative;
}

.new > summary {
  list-style: none;
}

.new > summary::-webkit-details-marker {
  display: none;
}

.new__menu {
  position: absolute;
  right: 0;
  z-index: 10;
  width: min(22rem, 90vw);
  margin-top: 0.5rem;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.15);
}

.publish:empty {
  display: none;
}

.publish {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
}

.publish--running {
  background: var(--soft);
  color: var(--primary-dark);
}

.publish--ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.publish--error {
  background: #fdecea;
  color: var(--danger);
}

.errors {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: #fdecea;
  color: var(--danger);
}

.errors ul {
  margin: 0.4rem 0 0;
}

/* ---------- Editor ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: -1.5rem -1rem 1rem;
  padding: 0.75rem 1rem;
  background: rgb(246 245 242 / 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(4px);
}

.bar__spacer {
  flex: 1;
}

.save-state {
  font-size: 0.9rem;
}

.layout {
  display: grid;
  gap: 1rem;
}

@media (min-width: 64em) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 20rem;
    align-items: start;
  }
}

.langs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 1rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 0.5rem 0.5rem 0 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.tab[aria-selected='true'] {
  border-color: var(--border);
  background: var(--surface);
  color: var(--primary-dark);
  margin-bottom: -1px;
}

.cover {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 0.75rem;
  border-radius: 0.5rem;
  object-fit: cover;
}

.cover--empty {
  display: grid;
  place-items: center;
  background: var(--soft);
  color: var(--muted);
}

.toolbar {
  position: sticky;
  top: 3.6rem;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem;
  border: 1px solid #b9c4cb;
  border-bottom: 0;
  border-radius: 0.5rem 0.5rem 0 0;
  background: #f3f5f6;
}

.toolbar__sep {
  width: 1px;
  height: 1.5rem;
  margin: 0 0.25rem;
  background: var(--border);
}

.tool {
  min-width: 2.2rem;
  min-height: 2.2rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.tool:hover {
  background: #e3e8eb;
}

.tool[aria-pressed='true'] {
  border-color: var(--secondary);
  background: var(--soft);
}

.prose-editor .tiptap {
  min-height: 18rem;
  padding: 1rem 1.25rem;
  border: 1px solid #b9c4cb;
  border-radius: 0 0 0.5rem 0.5rem;
  background: #fff;
  line-height: 1.65;
  outline: none;
}

.prose-editor .tiptap:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 1px;
}

.prose-editor h2 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1.35rem;
}

.prose-editor h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.1rem;
}

.imgblock {
  margin: 1rem 0;
  padding: 0.75rem;
  border: 1px dashed var(--secondary);
  border-radius: 0.5rem;
  background: #fafcfc;
}

.imgblock.ProseMirror-selectednode {
  outline: 3px solid var(--secondary);
}

.imgblock__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.imgblock figure {
  margin: 0 0 0.5rem;
}

.imgblock img {
  display: block;
  border-radius: 0.4rem;
}

.imgblock figcaption {
  margin: 0.3rem 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.imgblock__tools {
  text-align: center;
}

.advanced summary {
  color: var(--muted);
  cursor: pointer;
}

.advanced code,
.invite code {
  word-break: break-all;
}

.dialog {
  width: min(32rem, 94vw);
  padding: 1.25rem;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.4);
}

.dialog__img {
  display: block;
  max-height: 12rem;
  margin: 0 auto 1rem;
  border-radius: 0.4rem;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.devices {
  padding-left: 1.2rem;
}

.devices li {
  margin-bottom: 0.4rem;
}

.inline {
  display: inline;
  margin-left: 0.5rem;
}

.invite {
  padding: 0.75rem;
  border-radius: 0.5rem;
  background: var(--soft);
}

/* Estilos base de ProseMirror (TipTap con injectCSS: false por la CSP) */
.ProseMirror {
  position: relative;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-variant-ligatures: none;
  font-feature-settings: 'liga' 0;
}

.ProseMirror [contenteditable='false'] {
  white-space: normal;
}

.ProseMirror-hideselection *::selection {
  background: transparent;
}

.ProseMirror-gapcursor {
  display: none;
  pointer-events: none;
  position: absolute;
}

.ProseMirror-gapcursor::after {
  content: '';
  display: block;
  position: absolute;
  top: -2px;
  width: 20px;
  border-top: 1px solid black;
  animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
}

@keyframes ProseMirror-cursor-blink {
  to {
    visibility: hidden;
  }
}

.ProseMirror-focused .ProseMirror-gapcursor {
  display: block;
}
