/* libreta — estética papel rayado */

@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;500;700&family=Patrick+Hand&display=swap');

:root {
  --paper:        #fdf6e3;
  --paper-edge:   #efe6cb;
  --line:         #cfe2f3;
  --line-strong:  #a9c8e3;
  --margin:       #d24a3a;
  --ink:          #1f4e8c;
  --ink-muted:    #5a4634;
  --ink-soft:     #9b8a6c;
  --done:         #888;
  --row-h:        38px;
  --paper-pad-x:  clamp(18px, 4vw, 32px);
  --margin-x:     72px;
  --bg:           #b9a279;
  --bg-shadow:    #8e7a55;
  --safe-top:     env(safe-area-inset-top, 0px);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Caveat', 'Patrick Hand', cursive;
  font-size: 22px;
  line-height: var(--row-h);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: contain;
}

button { font: inherit; color: inherit; }

/* ───── login ───── */
body.login {
  display: grid;
  place-items: center;
  padding: 16px;
}
.paper--login {
  max-width: 420px;
  width: 100%;
  padding: 36px 28px 32px;
  text-align: center;
}
.title {
  font-family: 'Patrick Hand', cursive;
  font-size: 44px;
  margin: 0 0 4px;
  color: var(--ink);
}
.subtitle {
  margin: 0 0 32px;
  color: var(--ink-soft);
  font-size: 22px;
}
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 22px;
  background: #fff;
  color: #3c4043;
  text-decoration: none;
  font-family: 'Patrick Hand', cursive;
  font-size: 20px;
  border: 1px solid #dadce0;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(60,64,67,.08);
  transition: box-shadow .15s, transform .15s;
}
.btn-google:hover { box-shadow: 0 2px 6px rgba(60,64,67,.18); }
.btn-google:active { transform: translateY(1px); }
.btn-passkey {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  margin-top: 12px;
  background: var(--paper);
  color: var(--ink);
  border: 1px dashed var(--ink);
  border-radius: 6px;
  font-family: 'Patrick Hand', cursive;
  font-size: 18px;
  cursor: pointer;
}
.btn-passkey:hover { background: rgba(31,78,140,.05); }
.btn-passkey:disabled { opacity: .6; cursor: progress; }
.error {
  color: #a23a2a;
  margin-top: 14px;
  font-size: 18px;
  font-family: 'Patrick Hand', cursive;
}
.hint {
  margin-top: 24px;
  color: var(--ink-soft);
  font-size: 18px;
}

/* ───── papel rayado ───── */
.paper {
  position: relative;
  background-color: var(--paper);
  background-image:
    /* margen rojo izquierdo */
    linear-gradient(to right, transparent calc(var(--margin-x) - 1px), var(--margin) calc(var(--margin-x) - 1px), var(--margin) var(--margin-x), transparent var(--margin-x)),
    /* líneas horizontales */
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--row-h) - 1px), var(--line) calc(var(--row-h) - 1px), var(--line) var(--row-h));
  background-position: 0 0, 0 0;
  border: 1px solid var(--paper-edge);
  border-radius: 4px;
  box-shadow: 0 4px 18px rgba(60, 50, 30, .12), inset 0 0 0 1px rgba(255,255,255,.5);
}

/* ───── app shell ───── */
body.app {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100dvh;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 14px 8px;
  background: #2b3b55;
  color: #f3eddc;
  font-family: 'Patrick Hand', cursive;
}
.topbar__title { font-size: 24px; letter-spacing: .5px; }
.topbar__user { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1.5px solid #f3eddc;
  object-fit: cover;
}
.topbar__name { font-size: 18px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iconbtn {
  background: transparent; border: 0; padding: 6px;
  display: grid; place-items: center;
  color: #f3eddc; cursor: pointer; border-radius: 50%;
}
.iconbtn:hover { background: rgba(255,255,255,.08); }

/* ───── pestañas: marcadores adhesivos sobre la libreta ───── */
.tabs {
  display: flex;
  gap: 2px;
  padding: 6px 10px 0;
  overflow-x: auto;
  background: var(--bg);
  scrollbar-width: none;
  align-items: flex-end;
  position: relative;
  z-index: 2;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  padding: 4px 12px 6px;
  margin-bottom: -1px;        /* se "mete" en el papel */
  font-family: 'Patrick Hand', cursive;
  font-size: 15px;
  line-height: 20px;
  background: rgba(253, 246, 227, 0.55);
  border: 1px solid rgba(0,0,0,.10);
  border-bottom: 0;
  border-top: 3px solid var(--tab-color, var(--ink));
  border-radius: 6px 6px 0 0;
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background .12s, transform .12s;
}
.tab:hover { background: rgba(253, 246, 227, 0.8); }
.tab.is-active {
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
  padding-bottom: 8px;
  z-index: 3;
}
.tab--add {
  color: var(--ink-soft);
  background: transparent;
  border: 1px dashed rgba(255,255,255,.45);
  border-bottom: 0;
  border-top: 1px dashed rgba(255,255,255,.45);
  padding: 4px 10px 6px;
  font-size: 16px;
  opacity: .85;
}
.tab--add:hover { opacity: 1; background: rgba(255,255,255,.1); color: #fff; }
.tab__count {
  margin-left: 5px;
  padding: 0 6px;
  border-radius: 9px;
  background: rgba(0,0,0,.12);
  color: var(--ink-muted);
  font-family: 'Patrick Hand', cursive;
  font-size: 12px;
  font-weight: 400;
  line-height: 16px;
  display: inline-block;
  vertical-align: 1px;
  min-width: 18px;
  text-align: center;
}
.tab.is-active .tab__count {
  background: var(--tab-color, var(--ink));
  color: #fff;
}

/* ───── papel principal ───── */
body.app .paper {
  margin: 0 8px 8px;
  padding: 4px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  z-index: 1;
}
.lines {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-padding-bottom: 80px;
}

/* línea = una tarea */
.task {
  display: flex;
  align-items: center;
  height: var(--row-h);
  padding-left: calc(var(--margin-x) + 6px);
  padding-right: var(--paper-pad-x);
  position: relative;
  color: var(--task-color, var(--ink));
  cursor: text;
  -webkit-tap-highlight-color: transparent;
}
.task__controls {
  position: absolute;
  left: 4px;
  top: 0; bottom: 0;
  width: calc(var(--margin-x) - 8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
}
.task__check {
  width: 18px; height: 18px;
  flex: 0 0 18px;
  border: 2px solid currentColor;
  border-radius: 4px;
  display: grid; place-items: center;
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.task__check svg { opacity: 0; transition: opacity .15s; }
.task.is-done .task__check svg { opacity: 1; }
.task__color {
  width: 12px; height: 12px;
  flex: 0 0 12px;
  border-radius: 50%;
  background: var(--task-color, var(--ink));
  border: 1px solid rgba(0,0,0,.15);
  cursor: pointer;
  padding: 0;
  opacity: .85;
}
.task__color:hover { opacity: 1; }
.task__delete {
  flex: 0 0 16px;
  width: 16px; height: 16px;
  border: 0; background: transparent;
  color: var(--ink-soft);
  padding: 0;
  display: grid; place-items: center;
  cursor: pointer;
  opacity: .55;
  transition: opacity .12s, color .12s;
}
.task__delete:hover { opacity: 1; color: var(--margin); }
.task__text {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  outline: none;
  color: inherit;
  font: inherit;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task__text:focus { white-space: normal; }
.task.is-done .task__text {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  color: var(--done);
}

/* drag */
.task.sortable-ghost { opacity: .4; }
.task.sortable-chosen { background: rgba(0,0,0,.04); }
.task.sortable-drag { box-shadow: 0 4px 14px rgba(0,0,0,.18); background: var(--paper); }

/* añadir */
.add {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px calc(var(--paper-pad-x) - 4px) calc(8px + var(--safe-bottom)) calc(var(--margin-x) + 8px);
  border-top: 1px solid var(--paper-edge);
  background: var(--paper);
}
.add__color {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  background: var(--add-color, var(--ink));
  cursor: pointer;
}
#add-input {
  flex: 1 1 auto;
  border: 0;
  background: transparent;
  outline: none;
  font: inherit;
  color: var(--add-color, var(--ink));
  padding: 6px 0;
  caret-color: var(--add-color, var(--ink));
}
#add-input::placeholder { color: var(--ink-soft); }
.add__btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 0;
  background: var(--ink);
  color: #fff;
  font-size: 24px;
  line-height: 0;
  cursor: pointer;
  display: grid; place-items: center;
}

/* selector de color flotante */
.colors {
  position: absolute;
  display: flex;
  gap: 6px;
  padding: 8px;
  background: var(--paper);
  border: 1px solid var(--paper-edge);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  z-index: 10;
}
.colors__swatch {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  cursor: pointer;
}
.colors__swatch.is-active { outline: 2px solid var(--ink); outline-offset: 2px; }

/* toast */
.toast {
  position: fixed;
  left: 50%; bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(40,40,40,.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-family: 'Patrick Hand', cursive;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.toast button {
  background: transparent;
  color: #ffd366;
  border: 0;
  font: inherit;
  cursor: pointer;
}

/* empty state */
.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 22px;
  font-family: 'Patrick Hand', cursive;
}

/* responsive */
@media (min-width: 720px) {
  body.app .paper { margin: 8px 12px 12px; }
  :root { --margin-x: 88px; }
}

/* prefiere-reduce-movimiento */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
