:root {
  --bg: #14161a;
  --bg-soft: #1a1d23;
  --line: #262a32;
  --text: #e6e8ec;
  --muted: #7c828e;
  --danger: #f2777a;
  --accent: #e8b64c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

[data-color='amber'] { --accent: #e8b64c; }
[data-color='mint'] { --accent: #57cc99; }
[data-color='sky'] { --accent: #4ea8de; }
[data-color='violet'] { --accent: #a586e0; }
[data-color='rose'] { --accent: #ef7b96; }
[data-color='slate'] { --accent: #8b95a5; }

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 'Segoe UI Variable Text', -apple-system, BlinkMacSystemFont, 'Segoe UI',
    system-ui, sans-serif;
}

.view {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: var(--safe-top);
}

.view[hidden] {
  display: none;
}

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

/* ---------- barra superior ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.count {
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.spacer {
  flex: 1;
}

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

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

.icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon:active {
  background: #ffffff1a;
}

.icon.danger {
  color: var(--danger);
}

.icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon.spin svg {
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon.spin svg {
    animation: none;
  }
}

/* ---------- acceso ---------- */

.login {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(340px, 100%);
  margin: auto;
  padding: 24px;
  text-align: center;
}

.login .mark {
  margin: 0 auto;
  border-radius: 18px;
}

.login h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.field input,
.primary {
  width: 100%;
  /* 16px o más: por debajo, iOS hace zoom al enfocar el campo. */
  font-size: 16px;
  border-radius: 12px;
}

.field input {
  padding: 13px 14px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
}

.field input:focus {
  border-color: var(--accent);
  outline: none;
}

.primary {
  padding: 13px 14px;
  border: 0;
  background: var(--accent);
  color: #14161a;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.6;
}

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

/* ---------- buscador ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
}

.search svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
}

.search input {
  flex: 1;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.search input:focus {
  outline: none;
}

.search input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

/* ---------- lista ---------- */

.cards {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 8px 12px calc(96px + var(--safe-bottom));
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.card {
  display: flex;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  margin-bottom: 8px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--bg-soft);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.card:active {
  background: #ffffff0f;
}

.card .stripe {
  width: 3px;
  flex: 0 0 auto;
  border-radius: 3px;
  background: var(--accent);
}

.card .text {
  flex: 1;
  min-width: 0;
}

.card .title {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card .title.untitled {
  color: var(--muted);
  font-weight: 400;
  font-style: italic;
}

.card .snippet {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 14px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card .when {
  margin-top: 6px;
  color: #5d636e;
  font-size: 12px;
}

.empty {
  flex: 1;
  display: grid;
  place-content: center;
  margin: 0;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty[hidden] {
  display: none;
}

/* ---------- botón flotante ---------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(20px + var(--safe-bottom));
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #14161a;
  box-shadow: 0 6px 20px #0009;
  cursor: pointer;
}

.fab:active {
  transform: scale(0.94);
}

.fab svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

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

.swatches {
  display: flex;
  gap: 10px;
}

.swatches button {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  opacity: 0.5;
  cursor: pointer;
}

.swatches button[aria-pressed='true'] {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--bg-soft), 0 0 0 4px currentColor;
}

.title-input {
  flex: 0 0 auto;
  width: 100%;
  padding: 14px 16px 6px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 19px;
  font-weight: 600;
}

.title-input:focus {
  outline: none;
}

.title-input::placeholder {
  color: #4d525c;
  font-weight: 400;
}

.editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  padding: 4px 16px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  color: var(--text);
  font: inherit;
  line-height: 1.6;
}

.editor:focus {
  outline: none;
}

/* El marcador de vacío no puede ser un placeholder: esto no es un input. */
.editor:empty::before,
.editor.is-empty::before {
  content: attr(data-placeholder);
  color: #4d525c;
  pointer-events: none;
}

.editor p {
  margin: 0;
}

.editor ul,
.editor ol {
  margin: 0;
  padding-left: 24px;
}

.editor strong {
  font-weight: 700;
}

/* ---------- lista de tareas ---------- */

.editor ul[data-check='true'] {
  padding-left: 0;
  list-style: none;
}

.editor ul[data-check='true'] li {
  position: relative;
  padding-left: 30px;
  /* Objetivo de toque cómodo con el dedo. */
  min-height: 30px;
}

.editor ul[data-check='true'] li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25em;
  width: 19px;
  height: 19px;
  border: 2px solid var(--muted);
  border-radius: 5px;
}

.editor ul[data-check='true'] li[data-checked='true']::before {
  border-color: var(--accent);
  background: var(--accent);
}

.editor ul[data-check='true'] li[data-checked='true']::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 0.45em;
  width: 5px;
  height: 10px;
  border: solid #14161a;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.editor ul[data-check='true'] li[data-checked='true'] {
  color: var(--muted);
  text-decoration: line-through;
}

/* ---------- fotos ---------- */

.photos {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.photos[hidden] {
  display: none;
}

.photo {
  position: relative;
  flex: 0 0 auto;
}

.photo img {
  display: block;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  background: var(--bg-soft);
  object-fit: cover;
  cursor: pointer;
}

.photo .remove {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: var(--danger);
  color: #14161a;
  cursor: pointer;
}

.photo .remove svg {
  width: 11px;
  height: 11px;
  fill: none;
  stroke: currentColor;
  stroke-width: 3;
  stroke-linecap: round;
}

.photo.uploading img {
  opacity: 0.4;
}

/* ---------- foto a pantalla completa ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #000000e8;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: 8px;
  color: var(--text);
}

/* ---------- barra de formato ---------- */


.tools {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  padding: 4px 8px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  overflow-x: auto;
}

.tools .icon.active {
  color: var(--accent);
  background: #ffffff14;
}

.tools-gap {
  width: 12px;
  flex: 0 0 auto;
}

.editor-meta {
  flex: 0 0 auto;
  padding: 8px 16px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
