:root{
  --paper: #FBF6E9;
  --paper-edge: #F1E9D2;
  --line: #cdd6e8;
  --margin-red: #c0574d;
  --ink: #2B3A67;
  --ink-soft: #4a5a8a;
  --accent: #B23A2E;
  --muted: #8a8267;
  --shadow: 0 10px 30px rgba(43,58,103,.12);
  font-size: 16px;
}

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

body{
  margin:0;
  min-height:100vh;
  background: var(--paper-edge);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden{ display:none !important; }

/* Topbar */
.topbar{
  display:flex; align-items:center; gap:10px;
  padding: 18px 18px 12px;
  background: var(--paper-edge);
  position: sticky; top:0; z-index: 5;
}
.brand{
  font-family:'Kalam', cursive;
  font-weight:700;
  font-size: 1.45rem;
  margin: 0;
  color: var(--ink);
  letter-spacing: .5px;
}
.brand span{ color: var(--accent); }
.list-title{
  font-size:1.35rem;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.title-wrap{
  flex:1; min-width:0;
  display:flex; align-items:center; justify-content:center; gap:4px;
}
.topbar-spacer{ width:34px; flex-shrink:0; }
.edit-name-btn{ flex-shrink:0; padding:5px; opacity:.75; }
.edit-name-btn:active{ opacity:1; }
.back, .icon-btn{
  background:none; border:none; padding:6px; display:flex;
  cursor:pointer; border-radius:50%;
}
.back:active, .icon-btn:active{ background: rgba(43,58,103,.08); }

/* HOME */
.home{ padding: 4px 16px 120px; max-width:640px; margin:0 auto; }

.empty-state{
  text-align:center; margin-top: 18vh; color: var(--muted);
}
.empty-state p{ margin: 6px 0; font-family:'Kalam', cursive; font-size:1.15rem; color: var(--ink-soft); }
.empty-state p.muted{ font-family:'Inter'; font-size:.9rem; color: var(--muted); }

.lists{ list-style:none; margin:14px 0 0; padding:0; display:flex; flex-direction:column; gap:12px; }
.list-card{
  background: var(--paper);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display:flex; align-items:center;
  border-left: 5px solid var(--margin-red);
  overflow: hidden;
}
.lc-main{
  flex:1; min-width:0;
  display:flex; align-items:center; justify-content:space-between;
  padding: 16px 14px 16px 18px;
  text-decoration:none; color: inherit;
  transition: background .12s ease;
}
.lc-main:active{ background: rgba(43,58,103,.06); }
.lc-main .lc-name{ font-family:'Kalam', cursive; font-size:1.25rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.lc-name-row{ display:flex; align-items:center; gap:7px; min-width:0; }
.lc-main .lc-meta{ font-size:.78rem; color: var(--muted); margin-top:2px; }
.lc-main .lc-arrow{ opacity:.5; flex-shrink:0; margin-left:10px; }
.update-dot{
  flex-shrink:0;
  width:9px; height:9px; border-radius:50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(178,58,46,.16);
}
.update-label{ color: var(--accent); font-weight:600; }
.lc-delete{
  flex-shrink:0;
  width: 44px; height:44px;
  display:flex; align-items:center; justify-content:center;
  background:none; border:none; border-left: 1px solid var(--paper-edge);
  cursor:pointer;
}
.lc-delete:active{ background: rgba(178,58,46,.08); }

.fab{
  position: fixed; right: 22px; bottom: 28px;
  width: 60px; height:60px; border-radius:50%;
  background: var(--accent);
  border: none; box-shadow: 0 8px 20px rgba(178,58,46,.4);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; z-index:6;
}
.fab:active{ transform: scale(.94); }

.join-link{
  display:block; margin: 30px auto 0; background:none; border:none;
  color: var(--ink-soft); text-decoration:underline; font-size:.85rem;
  cursor:pointer; padding: 10px;
}

/* MODALS */
.modal-overlay{
  position: fixed; inset:0; background: rgba(30,32,25,.42);
  display:flex; align-items:flex-end; justify-content:center;
  z-index: 20;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }
.modal{
  width:100%; max-width: 480px;
  background: var(--paper);
  border-radius: 20px 20px 0 0;
  padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,.2);
  animation: slideUp .18s ease;
}
@media (min-width: 560px){
  .modal-overlay{ align-items:center; }
  .modal{ border-radius: 20px; }
}
@keyframes slideUp{ from{ transform: translateY(24px); opacity:0 } to{ transform:none; opacity:1 } }
.modal h2{ font-family:'Kalam', cursive; margin: 0 0 14px; font-size:1.4rem; }
.modal label{ font-size:.82rem; color: var(--muted); display:block; margin-bottom:6px; }
.modal input[type=text]{
  width:100%; padding: 13px 14px; border-radius: 10px;
  border: 1.5px solid var(--line); font-size: 1.05rem;
  font-family: 'Inter'; background: #fff;
  outline: none;
}
.modal input[type=text]:focus{ border-color: var(--ink-soft); }
.modal-actions{ display:flex; gap:10px; margin-top: 20px; }
.muted{ color: var(--muted); font-size:.85rem; }
.field-error{ color: var(--accent); font-size:.85rem; margin: 8px 2px 0; }

.btn-primary, .btn-secondary{
  border:none; border-radius: 12px; padding: 13px 18px;
  font-size:1rem; font-weight:600; cursor:pointer; flex:1;
  font-family:'Inter';
}
.btn-primary{ background: var(--ink); color: #FBF6E9; }
.btn-primary:active{ transform: scale(.98); }
.btn-secondary{ background: transparent; color: var(--muted); border:1.5px solid var(--line); }
.btn-wide{ width:100%; flex:none; }

/* LIST / NOTEBOOK PAGE */
.notebook-page{ padding: 6px 14px 130px; max-width: 640px; margin:0 auto; }

.filter-bar{
  display:flex; align-items:center; gap:10px;
  padding: 4px 6px 12px;
  font-size:.92rem; color: var(--ink-soft);
  cursor:pointer; user-select:none;
  width: fit-content;
}
.filter-bar .sr-checkbox{
  position:absolute; opacity:0; width:0; height:0;
}
.filter-circle{
  flex-shrink:0;
  width:26px; height:26px; border-radius:50%;
  border: 2.5px solid var(--ink-soft);
  background: var(--paper);
  background-repeat:no-repeat; background-position:center; background-size:15px;
  transition: background-color .15s ease, border-color .15s ease, transform .1s ease;
}
.filter-bar:active .filter-circle{ transform: scale(.9); }
.filter-bar .sr-checkbox:checked + .filter-circle{
  background-color: var(--accent);
  border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7' fill='none' stroke='%23FBF6E9' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.filter-bar .sr-checkbox:focus-visible + .filter-circle{
  outline: 2px solid var(--ink-soft); outline-offset: 2px;
}

.paper{
  background: var(--paper);
  border-radius: 6px;
  box-shadow: var(--shadow);
  padding: 22px 20px 30px 44px;
  position: relative;
  min-height: 60vh;
  background-image:
    repeating-linear-gradient(var(--paper) 0px, var(--paper) 37px, var(--line) 38px);
  background-position: 0 4px;
}
.paper::before{
  content:"";
  position:absolute; left: 30px; top:0; bottom:0; width:2px;
  background: var(--margin-red);
  opacity:.55;
}

.empty-list{
  font-family:'Kalam', cursive; color: var(--muted); font-size:1.1rem;
  text-align:center; margin-top: 40px; line-height:1.6;
}

.items{ list-style:none; margin:0; padding:0; }

.item{
  display:flex; align-items:flex-start; gap:12px;
  min-height: 38px; padding: 0 2px;
  position: relative;
}

.check{
  flex-shrink:0; width:24px; height:24px; margin-top: 6px;
  border-radius: 50%;
  border: 2px solid var(--ink-soft);
  background: transparent;
  cursor:pointer;
  position:relative;
  appearance:none; -webkit-appearance:none;
}
.check:active{ transform: scale(.92); }
.check::after{
  content:"";
  position:absolute; inset:0;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7' fill='none' stroke='%23B23A2E' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / 15px;
  opacity:0; transform: scale(.5);
  transition: opacity .12s ease, transform .12s ease;
}
.item.checked .check::after{ opacity:1; transform: scale(1); }

.item-text{
  font-family:'Kalam', cursive;
  font-size: 1.18rem;
  line-height: 38px;
  color: var(--ink);
  word-break: break-word;
  display: inline-block;
  max-width: calc(100% - 36px);
  text-decoration-line: line-through;
  text-decoration-color: transparent;
  text-decoration-thickness: 2.5px;
  text-decoration-skip-ink: none;
  transition: color .2s ease, text-decoration-color .2s ease, opacity .3s ease;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  border-radius: 4px;
}
.item-text.long-pressing{ opacity: .5; }

.item.checked .item-text{
  color: #8a8267;
  text-decoration-color: var(--accent);
}

/* scroll shortcut buttons (right margin) */
.scroll-fab{
  position: fixed; right: 14px;
  width: 42px; height:42px; border-radius:50%;
  background: var(--paper);
  border: 1.5px solid var(--line);
  box-shadow: var(--shadow);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; z-index: 6;
  opacity:0; pointer-events:none; transform: scale(.85);
  transition: opacity .15s ease, transform .15s ease;
}
.scroll-fab.is-visible{ opacity:1; pointer-events:auto; transform:none; }
.scroll-fab:active{ transform: scale(.92); }
.scroll-fab-top{ top: calc(env(safe-area-inset-top) + 78px); }
.scroll-fab-bottom{ bottom: calc(env(safe-area-inset-bottom) + 92px); }

/* bottom bar */
.bottom-bar{
  position: fixed; left:0; right:0; bottom:0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper-edge) 60%, transparent);
}
.bottom-actions{
  max-width: 560px; margin: 0 auto;
  display:flex; gap:10px;
}
.action-btn{
  flex:1;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:5px;
  padding: 12px 6px 10px;
  border-radius: 14px;
  border: none;
  cursor:pointer;
  font-family:'Inter';
  font-size:.76rem;
  font-weight:600;
}
.action-btn:active{ transform: scale(.96); }
.action-primary{ background: var(--ink); color:#FBF6E9; box-shadow: var(--shadow); }
.action-secondary{ background: var(--paper); color: var(--ink); border:1.5px solid var(--line); }
.action-danger{ background: var(--paper); color: var(--accent); border:1.5px solid rgba(178,58,46,.35); }

/* share modal */
.share-card{ text-align:center; }
.code-box{
  font-family:'Kalam', cursive;
  font-size: 2.1rem; letter-spacing: 6px;
  background: #fff; border: 2px dashed var(--ink-soft);
  border-radius: 12px; padding: 14px 10px; margin: 16px 0;
  color: var(--ink);
}
.copy-feedback{
  color: #2f7a4f; font-size:.85rem; margin-top:10px;
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
