/* =========================================================================
   Raw Paper — hand-drawn task & habit tracker
   Fonts: Excalifont (self-hosted).  Shapes: rough.js everywhere.
   ========================================================================= */

:root {
  --paper:      #EDE8E0;
  --paper-2:    #E5DFD4;
  --paper-3:    #F5F2EC;
  --ink:        #2c2a27;
  --ink-soft:   #5d574e;
  --ink-faint:  #9c958a;
  --line:       #c9c2b4;
  --line-soft:  #dbd5c9;
  --accent:     #c98a6f;
  --good:       #6f9a52;
  --bad:        #a64a3a;
  --shadow:     rgba(60, 50, 30, 0.18);

  --p1: #d8a48f;  --p2: #cbb38c;  --p3: #e7b78c;  --p4: #f0cb9a;
  --p5: #9fb89a;  --p6: #c98a6f;  --p7: #a9b9d6;  --p8: #c9a6c4;
  --p9: #d6c77f;  --p10:#8fb0a8;

  --font: 'Excalifont', 'Patrick Hand', 'Segoe Print', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  font-family: var(--font);
  color: var(--ink);
  background-color: var(--paper);
  /* simple dotted paper texture — no grid lines */
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,0.022) 0 1.2px, transparent 1.6px),
    radial-gradient(circle at 70% 60%, rgba(0,0,0,0.018) 0 1.2px, transparent 1.6px);
  background-size: 22px 22px, 30px 30px;
  /* scrolls with the page so it feels like moving across a big sheet */
  background-attachment: scroll;
  font-size: 18px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(80,65,40,0.10) 100%);
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

/* =========================================================================
   rough.js sketch layer — sits behind an element's content
   ========================================================================= */
[data-sketch] { position: relative; background: transparent; }
[data-sketch] > svg.sketch-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
  overflow: visible;
}

#app, #auth-screen { position: relative; z-index: 1; }
.wrap { max-width: 980px; margin: 0 auto; padding: 24px 20px 90px; }

/* ---- header ---------------------------------------------------------- */
header.topbar {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 8px;
}
.brand {
  font-family: var(--font);
  font-size: 3.4rem; font-weight: 400; line-height: 0.9;
  transform: rotate(-2deg); text-shadow: 1px 1px 0 rgba(0,0,0,0.06);
  display: inline-flex; align-items: center; gap: 0.12em;
  cursor: pointer; user-select: none;
  transition: transform 0.13s cubic-bezier(.2,.8,.3,1.3);
}
.brand:hover { transform: rotate(-2deg) translateY(-1px) scale(1.035); }
.brand:active { transform: rotate(-2deg) scale(0.96); }
.brand:hover .dot { transform: scale(1.4); }
.brand .dot { display: inline-block; transition: transform 0.18s ease; }

.logo-mark {
  height: 0.92em; width: auto; flex: 0 0 auto;
  transform: rotate(-4deg);
  transition: transform 0.15s ease;
}
.brand:hover .logo-mark { animation: logo-wiggle 0.55s ease; }
@keyframes logo-wiggle {
  0%,100% { transform: rotate(-4deg); }
  25% { transform: rotate(-14deg) scale(1.08); }
  55% { transform: rotate(4deg); }
  80% { transform: rotate(-8deg); }
}
.logo-mark.spin { animation: logo-spin 0.6s cubic-bezier(.2,.8,.3,1.5); }
@keyframes logo-spin {
  0%   { transform: rotate(-4deg) scale(1); }
  55%  { transform: rotate(346deg) scale(1.18); }
  100% { transform: rotate(356deg) scale(1); }
}
.auth-title .logo-mark { transform: rotate(-5deg); margin-right: 0.05em; }
.brand .dot, .auth-title .dot { color: var(--accent); }
.whoami { color: var(--ink-soft); display: flex; align-items: center; gap: 12px; }

/* ---- tabs ------------------------------------------------------------- */
.tabs {
  display: flex; gap: 18px; margin: 14px 0 26px;
  border-bottom: 2px dashed var(--line); padding-bottom: 2px;
}
.tab {
  background: none; border: none; cursor: pointer;
  font-family: var(--font); font-size: 1.5rem; color: var(--ink-faint);
  padding: 4px 6px 10px; position: relative;
  transition: color 0.2s, transform 0.2s;
}
.tab:hover { color: var(--ink-soft); transform: translateY(-1px) rotate(-1deg); }
.tab.active { color: var(--ink); }
.tab.active::after {
  content: ""; position: absolute; left: -2px; right: -2px; bottom: 2px;
  height: 8px; background: var(--accent); border-radius: 50%;
  opacity: 0.35; transform: rotate(-1deg) scaleX(1.04);
  animation: underline-in 0.35s ease;
}
@keyframes underline-in { from { transform: scaleX(0) rotate(-1deg); opacity: 0; } }

/* ---- sketchy button --------------------------------------------------- */
.btn {
  border: none; background: transparent; cursor: pointer;
  font-family: var(--font); font-size: 1.05rem; color: var(--ink);
  padding: 8px 16px;
  transition: transform 0.12s ease, filter 0.12s ease;
}
.btn:hover { transform: translate(-1px,-1px) rotate(-0.6deg); }
.btn:active { transform: translate(1px,1px) scale(0.98); }
.btn.primary { color: #fff8ee; }
.btn.tiny { padding: 4px 10px; font-size: 0.95rem; }
.btn.danger { color: var(--bad); }
.nav-arrow { padding: 2px 12px; font-size: 1.4rem; line-height: 1; }

/* ---- inputs ----------------------------------------------------------- */
input[type="text"], input[type="password"], input[type="number"], input[type="email"], .field {
  background: transparent; border: none; padding: 6px 4px 8px;
  outline: none;
}
input::placeholder { color: var(--ink-faint); opacity: 0.7; }

/* =========================================================================
   Auth screen
   ========================================================================= */
#auth-screen .wrap { max-width: 470px; padding-top: 8vh; }
.paper-card { padding: 32px 30px; }
.auth-title { font-size: 3rem; margin: 0 0 4px; font-weight: 400; display: flex; align-items: center; gap: 0.12em; }
.auth-sub { color: var(--ink-soft); margin: 0 0 22px; }
.auth-form label { display: block; color: var(--ink-soft); margin-top: 14px; }
.auth-form input { width: 100%; font-size: 1.1rem; }
/* always-visible hand-ruled underline on the login/signup fields */
.auth-input {
  border-bottom: 2px solid var(--ink-faint) !important;
  border-radius: 0;
  transition: border-color 0.18s ease;
}
.auth-input:focus { border-bottom-color: var(--accent) !important; }
.auth-actions { margin-top: 26px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.auth-switch-text { color: var(--ink-soft); }
.auth-switch { background: none; border: none; cursor: pointer; color: var(--accent); text-decoration: underline wavy; font-family: var(--font); }
.form-error { color: var(--bad); min-height: 1.3em; margin-top: 10px; transform: rotate(-0.5deg); }

/* shared paper panel look (fill drawn by rough, this just spaces) */
.paper-card, .add-task, .day-summary, .habit-tools { padding: 18px 20px; }

/* =========================================================================
   TASKS tab
   ========================================================================= */
.day-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
#day-today { margin-left: auto; }   /* push "today" to the right edge */
.day-nav .date-label { font-size: 2.1rem; min-width: 0; }
.day-nav .date-sub { color: var(--ink-soft); font-size: 1rem; }

.add-task-toggle { margin-bottom: 24px; }
.add-task { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 24px; }
.add-task .grp { display: flex; flex-direction: column; gap: 2px; }
.add-task .grp label { font-size: 0.85rem; color: var(--ink-faint); }
.add-task .grp.title-grp { flex: 1 1 240px; }
.add-task input.mini { width: 90px; }
.add-task input.title-in { width: 100%; font-size: 1.15rem; }

.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.task {
  position: relative; display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  transition: transform 0.18s ease, opacity 0.3s;
  animation: drop-in 0.34s cubic-bezier(.2,.9,.3,1.4) both;
}
@keyframes drop-in { from { opacity: 0; transform: translateY(-8px) rotate(-2deg); } }
.task.done { opacity: 0.62; }

.task .marker { flex: 0 0 auto; width: 34px; height: 34px; cursor: pointer; }
.task .marker svg { display: block; overflow: visible; }
.task .body { flex: 1 1 auto; min-width: 0; }
.task .ttl { font-size: 1.25rem; word-break: break-word; position: relative; }
.task.done .ttl { color: var(--ink-soft); }
.task .meta { display: flex; gap: 14px; color: var(--ink-soft); font-size: 0.95rem; margin-top: 2px; flex-wrap: wrap; }
.task .meta .pts { color: var(--accent); }
.task .meta .delta-over { color: var(--bad); }
.task .meta .delta-under { color: var(--good); }
.task .actions { display: flex; gap: 8px; flex: 0 0 auto; align-items: center; }

.strike {
  position: absolute; left: -2%; top: 55%; width: 104%; height: 3px;
  background: var(--accent); border-radius: 2px; transform-origin: left center;
  transform: scaleX(0) rotate(-1.5deg);
}
.task.done .strike { animation: strike-in 0.4s ease forwards; }
@keyframes strike-in { to { transform: scaleX(1) rotate(-1.5deg); } }

.day-summary { margin-top: 26px; display: flex; gap: 28px; flex-wrap: wrap; }
.day-summary b { font-size: 1.7rem; color: var(--accent); }
.summary-item { display: flex; flex-direction: column; }
.summary-item span { color: var(--ink-faint); font-size: 0.85rem; }

.empty-note { text-align: center; color: var(--ink-faint); font-size: 1.8rem; padding: 40px 10px; transform: rotate(-1.5deg); }

/* ---- day journal ---- */
.journal { margin-top: 30px; padding: 20px 24px 22px; display: flex; flex-direction: column; gap: 14px; }
.journal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.journal-title { margin: 0; font-size: 1.8rem; font-weight: 400; }
.journal-tools { display: flex; align-items: center; gap: 12px; }
.rec-btn { display: inline-flex; align-items: center; gap: 8px; }
.rec-ico { width: 11px; height: 11px; border-radius: 50%; background: var(--bad); display: inline-block; box-shadow: 0 0 0 0 rgba(166,74,58,0.5); }
.rec-btn.recording .rec-ico { animation: rec-pulse 1.1s infinite; }
.rec-btn.recording { color: var(--bad); }
@keyframes rec-pulse { 0% { box-shadow: 0 0 0 0 rgba(166,74,58,0.5);} 70% { box-shadow: 0 0 0 8px rgba(166,74,58,0);} 100% { box-shadow: 0 0 0 0 rgba(166,74,58,0);} }
.rec-status { color: var(--ink-soft); font-size: 0.95rem; }
.saved-hint { color: var(--ink-faint); font-size: 0.85rem; transition: opacity 0.4s; }
.journal-text {
  width: 100%; min-height: 130px; resize: vertical;
  background: transparent; border: none; outline: none;
  font-family: var(--font); font-size: 1.12rem; line-height: 1.7em; color: var(--ink);
  /* faint ruled lines like a notebook page */
  background-image: linear-gradient(transparent calc(1.7em - 1px), var(--line-soft) calc(1.7em - 1px), var(--line-soft) 1.7em, transparent 1.7em);
  background-size: 100% 1.7em; background-attachment: local;
  background-position: 0 6px;
  padding: 6px 8px;
}
.journal-text::placeholder { color: var(--ink-faint); opacity: 0.75; }

/* recorded voice notes */
.voice-notes { display: flex; flex-direction: column; gap: 10px; }
.voice-note {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px;
}
.voice-note .vn-text { flex: 1 1 auto; color: var(--ink-soft); font-size: 0.96rem; min-width: 0; }

/* hand-drawn audio player */
.vn-player { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.vn-player audio { display: none; }
.vn-play { background: none; border: none; cursor: pointer; width: 34px; height: 34px; padding: 0; flex: 0 0 auto; transition: transform 0.12s; }
.vn-play:hover { transform: scale(1.1) rotate(-3deg); }
.vn-play svg { display: block; overflow: visible; }
.vn-track { position: relative; width: 150px; height: 16px; cursor: pointer; flex: 0 0 auto; }
.vn-track svg.vn-trackbg { position: absolute; left: 0; top: 0; overflow: visible; }
.vn-fill { position: absolute; left: 0; top: 6px; height: 4px; width: 0; background: var(--accent); border-radius: 3px; }
.vn-knob { position: absolute; top: 3px; left: 0; width: 10px; height: 10px; margin-left: -5px; border-radius: 50%; background: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.vn-time { color: var(--ink-soft); font-size: 0.84rem; min-width: 34px; }
.voice-note .vn-text.empty { color: var(--ink-faint); font-style: italic; }
.voice-note .vn-del {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--ink-faint); font-family: var(--font); font-size: 1rem; padding: 4px 8px;
}
.voice-note .vn-del:hover { color: var(--bad); }

/* =========================================================================
   HABITS tab
   ========================================================================= */
.month-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
#month-this { margin-left: auto; }   /* push "this month" to the right edge */
.month-nav .month-label { font-size: 2.1rem; }
.habit-sheet-title { font-size: 2.8rem; margin: 4px 0 2px; font-weight: 400; }

.habit-tools { margin: 34px 0 10px; display: flex; flex-direction: column; gap: 12px; }
.ht-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.ht-row .grp { display: flex; flex-direction: column; gap: 2px; }
.ht-row .grp.grow { flex: 1 1 200px; }
.ht-row label, .ht-label { color: var(--ink-faint); font-size: 0.9rem; }
.ht-label { align-self: center; }
#h-name { width: 100%; font-size: 1.1rem; }
.hint { color: var(--ink-faint); font-size: 0.78rem; }

.kind-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.kind-pill {
  cursor: pointer; padding: 5px 13px; color: var(--ink-soft);
  font-family: var(--font); background: transparent; border: none;
  position: relative; transition: transform 0.12s, color 0.15s;
}
.kind-pill:hover { transform: rotate(-1.5deg); }
.kind-pill.sel { color: var(--ink); }

.more-toggle { align-self: flex-start; background: none; border: none; cursor: pointer; color: var(--accent); text-decoration: underline wavy; font-family: var(--font); font-size: 0.95rem; padding: 0; }
.ht-more { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-end; padding-top: 6px; }
.ht-more .grp { display: flex; flex-direction: column; gap: 2px; }
.ht-more label { color: var(--ink-faint); font-size: 0.9rem; }
#h-goal { width: 90px; }

.swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
  transition: transform 0.12s;
}
.swatch.auto { width: auto; height: 24px; border-radius: 8px; padding: 0 8px; display: grid; place-items: center; font-size: 0.78rem; color: var(--ink-soft); box-shadow: none; border: 1px dashed var(--ink-faint); }
.swatch:hover { transform: scale(1.15) rotate(-6deg); }
.swatch.sel { border-color: var(--ink); transform: scale(1.12); }

/* ---- the grid ---- */
.grid-scroll { overflow-x: auto; padding: 6px 0 12px; }
.grid-frame { position: relative; display: inline-block; background: var(--paper); border-radius: 8px; box-shadow: 3px 4px 0 var(--shadow); }
table.habit-grid { border-collapse: collapse; position: relative; z-index: 1; }
table.habit-grid th, table.habit-grid td {
  border: 1px solid var(--line-soft); text-align: center; padding: 0; background: transparent;
}
table.habit-grid thead th { vertical-align: bottom; height: 150px; padding: 6px 0; }
.habit-head-inner { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.habit-name-v {
  font-family: var(--font); font-size: 1.25rem; writing-mode: vertical-rl;
  transform: rotate(180deg); white-space: nowrap; max-height: 112px; overflow: hidden;
}
.habit-kind-tag { font-size: 0.62rem; color: var(--ink-faint); letter-spacing: 0.5px; }
td.foot-cell { padding: 3px 0; }
.habit-menu-btn {
  background: none; border: none; cursor: pointer; font-family: var(--font);
  font-size: 1.5rem; line-height: 0.6; color: var(--ink-faint); padding: 4px 8px;
  border-radius: 8px; transition: color 0.15s, transform 0.12s;
}
.habit-menu-btn:hover { color: var(--ink); transform: scale(1.2); }

th.col-day-head { font-family: var(--font); height: auto; vertical-align: middle; padding: 8px 6px; color: var(--ink-soft); }
.col-day-head, td.day-cell { width: 46px; color: var(--ink-soft); }
td.day-cell { font-size: 0.95rem; padding: 2px 0; }
td.day-cell.today { color: var(--accent); font-weight: bold; }
tr.weekend td.day-cell { color: var(--ink-faint); }
td.habit-cell:hover { background: rgba(201,138,111,0.12); }   /* only the hovered cell */

td.habit-cell { width: 58px; height: 30px; cursor: pointer; position: relative; overflow: hidden; }
td.habit-cell .dot-svg { position: absolute; inset: 0; margin: auto; }
td.habit-cell .cell-val {
  position: relative; z-index: 2; font-size: 0.86rem; line-height: 30px;
  font-weight: 400; pointer-events: none; white-space: nowrap;
}

.habit-empty { text-align: center; padding: 40px; font-size: 1.7rem; color: var(--ink-faint); }

/* span overlay (range habits) */
.span-layer { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.span-layer svg { position: absolute; inset: 0; overflow: visible; }
.span-label {
  position: absolute; font-size: 0.78rem; color: var(--ink); white-space: nowrap;
  transform: translate(-50%, 0) rotate(-90deg); transform-origin: center;
  pointer-events: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis;
}

/* legend / counts */
.habit-stats { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 22px; }
.habit-chip { display: flex; align-items: center; gap: 8px; padding: 7px 13px; }
.habit-chip .swatch { width: 16px; height: 16px; cursor: default; }
.habit-chip .count { color: var(--ink-soft); }

/* =========================================================================
   Popover (value / range editor)
   ========================================================================= */
.popover {
  position: fixed; z-index: 100; min-width: 200px; padding: 14px 16px;
  animation: pop-in 0.16s ease;
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.9) translateY(4px); } }
.popover h4 { margin: 0 0 8px; font-weight: 400; font-size: 1.1rem; }
.popover .po-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.popover input { font-size: 1.2rem; width: 100%; text-align: center; }
.popover input.time { font-family: var(--font); }
.popover .step { width: 34px; height: 34px; font-size: 1.3rem; padding: 0; flex: 0 0 auto; }
.popover .po-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 12px; }
.popover .po-hint { color: var(--ink-faint); font-size: 0.82rem; }
.tag-chips { display: flex; flex-wrap: wrap; gap: 8px; max-width: 260px; }
.tag-chip {
  font-family: var(--font); font-size: 0.95rem; cursor: pointer;
  background: transparent; color: var(--ink);
  border: 2px solid var(--ink-faint); border-radius: 12px 9px 13px 8px;
  padding: 4px 11px; transition: transform 0.1s;
}
.tag-chip:hover { transform: rotate(-1.5deg) scale(1.04); }
.tag-chip.sel { border-color: var(--ink); }

/* toast */
#toast {
  position: fixed; bottom: 26px; left: 50%;
  transform: translateX(-50%) rotate(-1deg);
  background: var(--ink); color: var(--paper);
  padding: 10px 20px; border-radius: 12px 9px 13px 8px;
  box-shadow: 2px 3px 0 var(--shadow); z-index: 120;
  opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px) rotate(-1deg); }

/* ---- settings ---- */
.settings-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.settings-title { font-size: 2.4rem; font-weight: 400; margin: 0; }
.settings-card { max-width: 460px; }
.set-label { font-size: 1.4rem; display: block; }
.set-hint { color: var(--ink-soft); margin: 6px 0 16px; font-size: 0.98rem; }
.reset-select {
  font-family: var(--font); font-size: 1.2rem; color: var(--ink);
  background: transparent; border: 2px dashed var(--ink-faint);
  border-radius: 12px 9px 13px 8px; padding: 8px 14px; cursor: pointer; outline: none;
}
.reset-select:focus { border-color: var(--accent); }
.set-saved { color: var(--good); margin-top: 14px; min-height: 1.2em; }

.view { animation: page-in 0.4s ease; }
@keyframes page-in { from { opacity: 0; transform: translateY(10px) rotate(-0.4deg); } }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .brand { font-size: 2.6rem; }
  .add-task input.mini { width: 74px; }
}
