:root {
  --desk: #1f2e28;
  --desk-felt: #24352d;
  --folder: #d8c9a3;
  --folder-tab: #cabb92;
  --card: #faf6ec;
  --card-shadow: rgba(0, 0, 0, 0.25);
  --ink: #2a2622;
  --ink-soft: #6b6155;
  --pin: #d8a34c;
  --danger: #c1553d;
  --focus: #7fb4a2;
  --display: "Fraunces", serif;
  --mono: "IBM Plex Mono", monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at top left, var(--desk-felt), var(--desk) 70%);
  font-family: var(--mono);
  color: var(--ink);
}

.screen[hidden] {
  display: none;
}

.topbar {
  padding: 2rem 2.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Left/right zones are equal flex-basis so the center zone (the title)
   lands in the true middle of the bar, regardless of how wide the
   sign-out/email side ends up being. */
.topbar-spacer,
.topbar-center,
.topbar-right {
  flex: 1 1 0;
  min-width: 0;
}

.topbar-center {
  text-align: center;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.9rem;
}

/* --- Account menu: email + dropdown (Settings, Sign out) --- */
.account-menu {
  position: relative;
}

.account-toggle {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem 0.4rem;
  border-radius: 4px;
}
.account-toggle:hover {
  background: rgba(216, 201, 163, 0.1);
}

.user-email {
  color: #a9b8ae;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.account-caret {
  color: #a9b8ae;
  font-size: 0.7rem;
}

.account-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.4rem;
  background: var(--card);
  border-radius: 6px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.4);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  z-index: 20;
}
.account-dropdown[hidden] {
  display: none;
}

.account-dropdown-item {
  background: none;
  border: none;
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: 4px;
}
.account-dropdown-item:hover {
  background: #f0eadb;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    text-align: center;
  }
  .topbar-spacer {
    display: none;
  }
  .topbar-right {
    justify-content: center;
  }
  .account-dropdown {
    right: 50%;
    transform: translateX(50%);
  }
}

button.ghost {
  background: none;
  border: 1px solid #4a5c52;
  color: var(--folder);
  border-radius: 4px;
  padding: 0.4rem 0.7rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  cursor: pointer;
}
button.ghost:hover {
  border-color: var(--folder);
}

.topbar h1 {
  font-family: var(--display);
  font-weight: 700;
  font-size: 2rem;
  color: var(--folder);
  margin: 0;
  letter-spacing: 0.01em;
}

.subtitle {
  color: #a9b8ae;
  font-size: 0.85rem;
  font-style: italic;
}

button.primary {
  background: var(--ink);
  color: var(--card);
  border: 1px solid var(--ink);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}
button.primary:hover {
  background: #423c34;
}

button.primary.full-width {
  width: 100%;
  padding: 0.6rem;
}

/* --- Auth screen: the account is a signed index card on the desk --- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.auth-card {
  background: var(--card);
  border-radius: 3px;
  padding: 2rem 2.25rem;
  width: min(360px, 100%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  position: relative;
}

.auth-card::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--pin);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

.brand {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6rem;
  margin: 0.25rem 0 0.15rem;
  text-align: center;
}

.auth-screen .subtitle {
  display: block;
  text-align: center;
  color: var(--ink-soft);
  margin-bottom: 1.5rem;
}

.auth-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid #e2dccb;
}
.auth-tabs[hidden] {
  display: none;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 0.5rem 0.3rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.auth-tab.active {
  color: var(--ink);
  border-bottom-color: var(--pin);
  font-weight: 600;
}

.auth-form label {
  display: block;
  font-size: 0.75rem;
  color: var(--ink-soft);
  margin-bottom: 0.9rem;
}

.auth-form input {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.auth-form input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.form-hint {
  font-size: 0.7rem;
  color: var(--ink-soft);
  margin: -0.5rem 0 0.9rem;
}

.form-error {
  font-size: 0.78rem;
  color: var(--danger);
  margin: -0.4rem 0 0.9rem;
}

.form-success {
  font-size: 0.78rem;
  color: #2f6b4f;
  margin: -0.4rem 0 0.9rem;
}

.link-btn {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 0.75rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.5rem 0;
  text-align: center;
}
.link-btn:hover {
  color: var(--ink);
}

/* --- Verify-email banner: informational, never alarming --- */
.verify-banner {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 0 2.5rem 1rem;
  padding: 0.6rem 1rem;
  background: rgba(127, 180, 162, 0.15);
  border: 1px solid var(--focus);
  border-radius: 6px;
  color: var(--folder);
  font-size: 0.8rem;
}
.verify-banner[hidden] {
  display: none;
}

.verify-banner span {
  flex: 1;
}

.verify-banner .link-btn {
  width: auto;
  padding: 0;
  color: var(--folder);
}
.verify-banner .link-btn:hover {
  color: var(--card);
}

.verify-banner-dismiss {
  background: none;
  border: none;
  color: var(--folder);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.1rem 0.3rem;
}
.verify-banner-dismiss:hover {
  color: var(--card);
}

/* --- Home screen --- */
.home-content {
  padding: 0.5rem 2.5rem 2.5rem;
}

/* Current date: sits directly on the desk, no card behind it. */
.date-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  position: relative;
  margin-bottom: 1.75rem;
}

.date-label {
  background: none;
  border: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--folder);
  cursor: pointer;
  padding: 0.15rem 0.6rem;
  border-radius: 4px;
  text-align: center;
}
.date-label:hover {
  background: rgba(216, 201, 163, 0.12);
}

.native-picker {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.home-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 980px) {
  .home-layout {
    grid-template-columns: 1fr;
  }
}

.home-main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.panel {
  background: var(--card);
  border-radius: 8px;
  padding: 1.25rem 1.4rem;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.panel h2 {
  font-family: var(--display);
  font-size: 1.1rem;
  margin: 0 0 0.9rem;
}

.panel h3 {
  font-family: var(--display);
  font-size: 0.95rem;
  margin: 0 0 0.6rem;
  color: var(--ink);
}

/* --- Daily Tasks checklist --- */
.daily-tasks-list {
  list-style: none;
  margin: 0 0 0.9rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.task-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.task-item input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex-shrink: 0;
}

.task-reorder {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.task-move {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.5rem;
  line-height: 1;
  padding: 0.1rem 0.15rem;
}
.task-move:hover:not(:disabled) {
  color: var(--ink);
}
.task-move:disabled {
  opacity: 0.25;
  cursor: default;
}

.task-title-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--ink);
  padding: 0.1rem 0;
}
.task-title-input:hover,
.task-title-input:focus {
  border-bottom-color: var(--ink-soft);
  outline: none;
}

.task-item.completed .task-title-input {
  text-decoration: line-through;
  color: var(--ink-soft);
}

.task-stats {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.task-delete {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.75rem;
  flex-shrink: 0;
}
.task-delete:hover {
  color: var(--danger);
}

.tasks-empty {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.82rem;
  list-style: none;
}

.new-task-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.new-task-form input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.new-task-form input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

/* --- Journal --- */
#day-journal-input {
  display: block;
  width: 100%;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.55rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
}
#day-journal-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.save-hint {
  font-size: 0.72rem;
  color: var(--focus);
  margin: 0.3rem 0 0;
}

/* --- Goals panel --- */
.new-goal-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.new-goal-form input {
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.goals-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.goal-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.goal-item input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.goal-title {
  flex: 1;
  word-break: break-word;
}

.goal-item.completed .goal-title {
  text-decoration: line-through;
  color: var(--ink-soft);
}

.goal-date {
  font-size: 0.68rem;
  color: var(--ink-soft);
  white-space: nowrap;
}

.goal-delete {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.75rem;
}
.goal-delete:hover {
  color: var(--danger);
}

.goals-empty {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.8rem;
}

/* --- Goal Overview: collapsible, grouped by year --- */
.goal-overview {
  margin-top: 1.25rem;
  border-top: 1px solid #e2dccb;
  padding-top: 0.9rem;
}

.goal-overview summary {
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink);
}
.goal-overview summary:hover {
  color: var(--ink-soft);
}

.overview-year-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.9rem 0;
}

.overview-year-nav .ghost {
  border-color: #ccc;
  color: var(--ink-soft);
}
.overview-year-nav .ghost:hover {
  border-color: var(--ink-soft);
}

#overview-year-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.95rem;
}

.overview-section {
  margin-bottom: 1rem;
}

.overview-section h4 {
  font-family: var(--display);
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: 0 0 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.overview-list {
  gap: 0.4rem;
}

/* --- Friends panel: collapsible, entirely optional --- */
.friends-panel {
  margin-top: 1.5rem;
}

.friends-panel > summary {
  cursor: pointer;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
}
.friends-panel > summary:hover {
  color: var(--ink-soft);
}

.friends-panel[open] > summary {
  margin-bottom: 0.9rem;
}

.friends-badge {
  display: inline-block;
  background: var(--danger);
  color: var(--card);
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-left: 0.3rem;
  vertical-align: middle;
}
.friends-badge[hidden] {
  display: none;
}

.friends-hint {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin: -0.3rem 0 1rem;
}

.add-friend-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  max-width: 420px;
}

.add-friend-form input {
  flex: 1;
  font-family: var(--mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}
.add-friend-form input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}

.friend-requests {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.friend-request {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  background: #f3efe2;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.friend-request span {
  flex: 1;
}

.friend-request.outgoing {
  color: var(--ink-soft);
  font-style: italic;
}

.friends-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.friend-email {
  flex: 1;
  min-width: 160px;
  word-break: break-word;
}

.friend-stat {
  color: var(--ink-soft);
  font-size: 0.78rem;
  white-space: nowrap;
}

.friend-cheer-count {
  font-size: 0.72rem;
  color: var(--focus);
  white-space: nowrap;
  min-width: 5.5rem;
}

.friend-cheer {
  background: none;
  border: 1px solid var(--ink);
  color: var(--ink);
  border-radius: 4px;
  padding: 0.35rem 0.6rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}
.friend-cheer:hover:not(:disabled) {
  background: var(--ink);
  color: var(--card);
}
.friend-cheer:disabled {
  border-color: #ccc;
  color: var(--ink-soft);
  cursor: default;
}

.friend-remove {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.75rem;
}
.friend-remove:hover {
  color: var(--danger);
}

.friends-empty {
  color: var(--ink-soft);
  font-style: italic;
  font-size: 0.82rem;
  list-style: none;
}

/* --- Celebrations: milestone toast + confetti --- */
.celebration-toast {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translate(-50%, -20px);
  background: var(--ink);
  color: var(--card);
  font-family: var(--display);
  font-weight: 700;
  font-size: 0.95rem;
  padding: 0.8rem 1.4rem;
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  z-index: 100;
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
  text-align: center;
  max-width: min(90vw, 420px);
}
.celebration-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 99;
}

.confetti-piece {
  position: absolute;
  top: -10px;
  width: 8px;
  height: 14px;
  opacity: 0.9;
  animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
  to {
    transform: translate(var(--drift), 100vh) rotate(var(--rot));
    opacity: 0;
  }
}

/* --- Settings dialog --- */
.settings-dialog {
  border: none;
  border-radius: 8px;
  padding: 1.5rem 1.6rem;
  width: min(420px, 90vw);
  font-family: var(--mono);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  background: var(--card);
  color: var(--ink);
}
.settings-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.settings-form h2 {
  font-family: var(--display);
  font-size: 1.2rem;
  margin: 0 0 1.1rem;
}

.theme-palettes {
  border: none;
  padding: 0;
  margin: 0 0 1.25rem;
  display: flex;
  gap: 1rem;
}

.theme-palettes legend {
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding: 0;
  margin-bottom: 0.5rem;
}

.palette-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
  cursor: pointer;
}

.palette-swatch {
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}
.palette-option input:checked + .palette-swatch {
  border-color: var(--focus);
}
.palette-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.palette-swatch-desk {
  background: conic-gradient(#1f2e28 0turn 0.5turn, #d8a34c 0.5turn 0.75turn, #faf6ec 0.75turn 1turn);
}
.palette-swatch-ocean {
  background: conic-gradient(#16232c 0turn 0.5turn, #4f9bc4 0.5turn 0.75turn, #f4f9fa 0.75turn 1turn);
}
.palette-swatch-sunset {
  background: conic-gradient(#2b1e24 0turn 0.5turn, #d97b3f 0.5turn 0.75turn, #fdf3ea 0.75turn 1turn);
}

.theme-custom {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid #e2dccb;
}

.theme-custom label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.theme-custom input[type='color'] {
  width: 40px;
  height: 32px;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}

#theme-reset-btn {
  margin-left: auto;
  align-self: flex-end;
}

/* --- Contrast checker: advisory only, never blocks Save --- */
.contrast-check {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  padding: 0.7rem 0.8rem;
  background: #f3efe2;
  border-radius: 6px;
}

.contrast-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
}

.contrast-label {
  flex: 1;
  color: var(--ink-soft);
}

.contrast-ratio {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.contrast-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  white-space: nowrap;
}
.contrast-badge.contrast-good {
  background: #dcefe6;
  color: #2f6b4f;
}
.contrast-badge.contrast-warn {
  background: #f7e6c4;
  color: #8a6414;
}
.contrast-badge.contrast-bad {
  background: #f5d9d2;
  color: #a3402c;
}

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

.dialog-actions button {
  font-family: var(--mono);
  font-size: 0.8rem;
  padding: 0.45rem 0.9rem;
  border-radius: 4px;
  border: 1px solid #ccc;
  background: white;
  cursor: pointer;
}

.dialog-actions button.primary {
  background: var(--ink);
  color: var(--card);
  border-color: var(--ink);
}
