/* Shared palette and artwork from Sonnibad. */
:root {
  color-scheme: light;
  --bg: #fffdf8;
  --card: #ffffff;
  --text: #3b2a20;
  --muted: #6f5b4a;
  --line: #e8d5b3;
  --accent: #cc4700;
  --accent-ink: #ffffff;
  --sun: #ffd34e;
  --sun-soft: #fff3c4;
  --danger: #a63628;
  --lift: 0 18px 46px rgb(101 61 20 / 14%);
  --display: "Arial Rounded MT Bold", "Trebuchet MS", sans-serif;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.modal-open { overflow: hidden; }

.shell {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 24px 16px 110px;
}

.topbar, .actions, .task-actions, .list-head, .modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1, h2, p { margin: 0; }

h1 { font-family: var(--display); font-size: clamp(1.8rem, 7vw, 2.8rem); line-height: 1.12; letter-spacing: -0.035em; }
h2 { font-family: var(--display); font-size: 1.2rem; letter-spacing: -0.025em; }

.eyebrow {
  margin-bottom: 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.card {
  margin-top: 18px;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 10px 28px rgb(101 61 20 / 6%);
}

.stack { display: grid; gap: 12px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

label { display: grid; gap: 6px; font-weight: 700; }
label span, .field-label { font-size: 0.82rem; color: var(--muted); font-weight: 700; }

input, textarea, select, button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  font: inherit;
}

input, textarea, select {
  padding: 12px;
  background: rgb(255 255 255 / 78%);
  color: var(--text);
}

textarea { resize: vertical; }

.deadline-picker {
  display: grid;
  gap: 14px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.deadline-summary {
  color: var(--text);
  font-weight: 800;
  line-height: 1.25;
}

.deadline-hint {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.35;
}

/* The SVG circle has a 2400-unit diameter in a 600-unit viewport. */
.deadline-sun-field { position: relative; height: 190px; overflow: hidden; }
.date-wheel {
  position: absolute; inset: 0; width: 100%; height: 100%; padding: 0;
  background: transparent; border: 0; border-radius: 12px;
  color: var(--text); touch-action: none; user-select: none; cursor: ns-resize;
}
.date-wheel:active { transform: none; }
.date-wheel:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.wheel-scale { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.sun-disc { fill: url(#wheel-watercolor); stroke: #b79a70; stroke-width: 1.5; opacity: .55; }
.date-wheel[aria-pressed="true"] .sun-disc { opacity: 1; stroke: #bd8c40; }
.scale-tick { stroke: #a58b64; stroke-width: 1; }
.scale-tick.major { stroke: #655135; stroke-width: 2; }
.scale-label { fill: #55452e; font: 14px system-ui, sans-serif; text-anchor: middle; }
.wheel-selector {
  position: absolute; left: 50%; top: 16px; width: 2px; height: 37px;
  background: var(--accent); transform: translateX(-50%); pointer-events: none;
}
.wheel-selector::before {
  content: ""; position: absolute; top: -2px; left: -4px;
  width: 10px; height: 10px; background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.wheel-value {
  position: absolute; top: 116px; left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 1.2rem; font-weight: 700;
}
.deadline-native {
  position: absolute; z-index: 2; top: 104px; left: 50%; transform: translateX(-50%);
  width: min(260px, 80%); height: 44px; padding: 0; opacity: 0;
  cursor: pointer;
}
.deadline-native:disabled { display: none; }
.deadline-hint { font-size: 0.78rem; }

button {
  padding: 12px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:active { filter: brightness(.95); }
button:disabled { opacity: 0.5; cursor: wait; }
button.secondary { background: var(--sun-soft); color: var(--text); border-color: var(--line); }
button.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: #e7c9c9; }
button.compact { width: auto; padding-inline: 14px; }

.list-head { margin: 28px 4px 10px; }
.tasks { display: grid; gap: 0; padding: 0; margin: 0; list-style: none; }

.task {
  position: relative;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto 28px;
  align-items: center;
  gap: 6px;
  min-height: 56px;
  padding: 4px 0;
  margin-top: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg);
  transition: transform 190ms cubic-bezier(.2,.8,.2,1), box-shadow 190ms ease, opacity 160ms ease, border-color 160ms ease;
  touch-action: manipulation;
}

.task-main { display: grid; grid-template-columns: 1fr 165px; gap: 10px; }
.task-actions { grid-column: 2; justify-content: start; flex-wrap: wrap; }
.task-actions button { width: auto; }

.drag-handle {
  align-self: start; display: grid; place-items: center;
  width: 28px; height: 44px; padding: 0;
  border: 0; background: transparent; color: var(--muted);
  cursor: grab; touch-action: none;
}
.drag-handle:hover { color: var(--accent); background: var(--sun-soft); }

.task.dragging {
  opacity: 0.98;
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  box-shadow: var(--lift);
  cursor: grabbing;
  pointer-events: none;
}

.drag-placeholder {
  list-style: none;
  border: 2px dashed color-mix(in srgb, var(--accent) 45%, var(--line));
  border-radius: 22px;
  background: rgb(204 71 0 / 8%);
  box-shadow: inset 0 0 0 6px rgb(255 255 255 / 42%);
  animation: placeholder-pulse 900ms ease-in-out infinite alternate;
}

.tasks.drag-active .task:not(.dragging) { opacity: 0.72; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.fab {
  position: fixed;
  right: max(18px, calc((100vw - 720px) / 2 + 18px));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  padding: 0 0 4px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: white;
  font-size: 2.5rem;
  line-height: 1;
  filter: drop-shadow(0 5px 8px rgb(101 61 20 / 20%));
}

.fab:hover { filter: drop-shadow(0 7px 10px rgb(101 61 20 / 30%)); }
.fab img { width: 100%; height: 100%; transform-origin: 50% 65%; }
.hero-sun { position: relative; flex-shrink: 0; margin-right: -15px; cursor: pointer; border-radius: 50%; }
.hero-sun img { display: block; transform-origin: 50% 65%; }
.hero-sun:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }
.fab-plus { position: absolute; bottom: 0; right: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); font-size: 27px; line-height: 30px; border: 2px solid white; }
.sun-emote-sprite {
  position: absolute; inset: -14%; overflow: hidden; opacity: 0; pointer-events: none;
}
.sun-emote-sprite::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 1200%;
  background-repeat: no-repeat; background-size: 100% 100%; transform: translateX(0);
}
:is(.fab, .hero-sun):is(.sun-emote-plan, .sun-emote-write, .sun-emote-check, .sun-emote-celebrate) > img { opacity: 0; }
:is(.fab, .hero-sun):is(.sun-emote-plan, .sun-emote-write, .sun-emote-check, .sun-emote-celebrate) .sun-emote-sprite { opacity: 1; }
:is(.fab, .hero-sun):is(.sun-emote-plan, .sun-emote-write, .sun-emote-check, .sun-emote-celebrate) .sun-emote-sprite::before { animation: sun-emote-frames 2.4s steps(11, end) both; }
:is(.fab, .hero-sun).sun-emote-plan .sun-emote-sprite::before { background-image: url("/assets/sonni-emote-plan-sprites.webp"); }
:is(.fab, .hero-sun).sun-emote-write .sun-emote-sprite::before { background-image: url("/assets/sonni-emote-write-sprites.webp"); }
:is(.fab, .hero-sun).sun-emote-check .sun-emote-sprite::before { background-image: url("/assets/sonni-emote-check-sprites.webp"); }
:is(.fab, .hero-sun).sun-emote-celebrate .sun-emote-sprite::before { background-image: url("/assets/sonni-emote-celebrate-sprites.webp"); }
@keyframes sun-emote-frames { to { transform: translateX(-91.6667%); } }
@media (prefers-reduced-motion: reduce) { :is(.fab, .hero-sun) > img { opacity: 1; } :is(.fab, .hero-sun) .sun-emote-sprite { display: none; } }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(34 27 20 / 42%);
  backdrop-filter: blur(4px);
  animation: fade-in 150ms ease both;
}

.modal-card {
  position: relative;
  z-index: 1;
  width: min(680px, 100%);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: 18px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: 0 24px 80px rgb(34 27 20 / 28%);
  animation: modal-rise 210ms cubic-bezier(.2,.8,.2,1) both;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  border-color: var(--line);
  font-size: 1.6rem;
  line-height: 1;
}

.status {
  pointer-events: none;
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 96px;
  z-index: 40;
  max-width: 680px;
  margin: 0 auto;
  padding: 12px 14px;
  background: #221b14;
  color: white;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgb(0 0 0 / 18%);
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(28px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes placeholder-pulse { from { background: rgb(204 71 0 / 6%); } to { background: rgb(204 71 0 / 13%); } }

@media (max-width: 560px) {
  .shell { padding-inline: 12px; }
  .grid { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; }
  .actions { flex-direction: column-reverse; }
  .task-actions button { flex: 1 1 42%; }
  .modal { align-items: end; padding: 10px; }
  .modal-card { border-radius: 24px 24px 18px 18px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* Sonni is the identity; watercolor is kept behind content, never over it. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.sun-hello {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  min-height: 166px; margin-top: 24px; padding: 22px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 24px;
  background: var(--bg);
}
.sun-hello > div { position: relative; z-index: 1; }
.sun-hello h2 { font-size: clamp(1.45rem, 5vw, 2rem); line-height: 1.15; }
.sun-hello p { max-width: 170px; margin-top: 10px; color: var(--muted); font-size: .9rem; }
.sun-hello img { width: clamp(120px, 29vw, 160px); height: auto; }
.login-sonni { display: block; margin: 4px auto 18px; }
#login { padding: 24px; }
#login p { margin: 14px 0; }
.modal-sonni { flex: 0 0 52px; object-fit: contain; }
.modal-head > div { flex: 1; }
.modal-head .icon-button { flex-shrink: 0; }
.task:nth-child(3n + 2) { background-position: center, 25% 65%; }
.task:nth-child(3n) { background-position: center, 70% 30%; }
.edit-text { font-weight: 600; }
.edit-text, .edit-deadline { border-color: #e8d5b3; }
button { min-height: 44px; }
.date-wheel { min-height: 0; }
@media (max-width: 360px) {
  .sun-hello { padding: 16px; }
  .sun-hello img { width: 112px; }
}

/* Compact, autosaving Sonniaufträge. */
.task-main { min-width: 0; }
.task-actions { gap: 8px; }
.done-label { display: flex; align-items: center; gap: 8px; font-size: .86rem; min-height: 44px; }
.done-label input { width: 20px; height: 20px; accent-color: var(--accent); }
.save-state { margin-left: auto; color: var(--muted); font-size: .75rem; }
.task.is-done .edit-text { color: var(--muted); text-decoration: line-through; }

.task .archive-swipe { grid-column: 1 / -1; background: transparent; border: 0; color: var(--muted); font-size: .78rem; min-height: 44px; padding: 8px; touch-action: pan-y; }
.task { overflow: hidden; }
.task { touch-action: pan-y; transform-origin: 50% 80%; }
.task.swiping { z-index: 36; transition: none; box-shadow: var(--lift); }
.swipe-feedback {
  position: fixed; z-index: 35; display: grid; place-items: center;
  border-radius: 22px; border: 1px dashed var(--line);
  background: var(--sun-soft); color: var(--text); font-weight: 700;
  opacity: .75; pointer-events: none;
}
.swipe-feedback.complete { background: #e7f2dc; color: #31592b; }
.swipe-feedback.ready { opacity: 1; border-style: solid; }
.swipe-reveal { display: none; }
.archive-undo { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; font-size: .85rem; }
.archive-undo button { width: auto; margin-left: auto; }
.pending-archive > :not(.archive-undo) { display: none; }
.wheel-flame, .task-flame { overflow: hidden; pointer-events: none; }
.task-flame { flex: none; }
.task.is-done .task-flame { display: none; }
.flame-frames { animation: flame-frames .96s steps(8, end) infinite; }
@keyframes flame-frames { from { transform: translateX(0); } to { transform: translateX(-1024px); } }
@media (prefers-reduced-motion: reduce) { .flame-frames { animation: none; } }
@media (max-width: 560px) { .task-actions .retry { flex: 0 1 auto; } }

.task-main { display: block; }
.markdown-preview { overflow-wrap: anywhere; padding: 8px 0; line-height: 1.55; }
.markdown-preview h3 { margin: 0 0 8px; font-size: 1.06rem; }
.markdown-preview h1, .markdown-preview h2, .markdown-preview h4 { font-size: 1rem; margin-block: 12px 6px; }
.markdown-preview p + p { margin-top: 8px; }
.markdown-preview ul, .markdown-preview ol { padding-left: 22px; margin-block: 8px; }
.markdown-preview a { color: #a83b00; text-decoration: underline; }
.markdown-preview pre { white-space: pre-wrap; padding: 10px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.markdown-preview blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--line); }
.markdown-preview input { width: 16px; height: 16px; }
.markdown-preview table { display: block; overflow-x: auto; border-collapse: collapse; }
.markdown-preview td, .markdown-preview th { border: 1px solid var(--line); padding: 4px; }
.task.is-done .markdown-preview h3 { text-decoration: line-through; color: var(--muted); }
.edit-source, .close-editor { width: auto; font-size: .8rem; padding: 6px 10px; margin-bottom: 8px; }
.text-editor small { display: block; margin: 6px 0; color: var(--muted); }
.edit-deadline { margin-top: 6px; }

/* Compact rows: full editing stays in the modal. */
.task .task-main { min-width: 0; }
.task .markdown-preview { display: flex; align-items: baseline; gap: 8px; padding: 0; min-width: 0; white-space: nowrap; line-height: 1.45; }
.task .markdown-preview h3 { flex: 0 1 auto; min-width: 0; max-width: 100%; margin: 0; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; }
.task .markdown-preview:has(.markdown-excerpt) h3 { max-width: 60%; }
.markdown-excerpt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: .85rem; }
.markdown-excerpt::before { content: "| "; color: var(--line); }
.task .markdown-excerpt * { display: inline; margin: 0; padding: 0; border: 0; font-size: inherit; white-space: nowrap; }
.task .markdown-excerpt br::after, .task .markdown-excerpt li::after, .task .markdown-excerpt p::after { content: " "; }
.task-deadline { display: flex; align-items: center; gap: 3px; margin: 0; font-size: .76rem; white-space: nowrap; color: var(--muted); }
.done-label { justify-content: center; margin: 0; }
.accessible-action { position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important; overflow: hidden; clip-path: inset(50%); padding: 0 !important; }
.accessible-action:focus-within, .has-save-error .task-actions, .is-creating .task-actions { position: relative !important; grid-column: 1 / -1; width: auto !important; height: auto !important; min-height: 44px !important; clip-path: none; padding: 6px !important; }
.sync-state { min-height: 1.2em; margin: -8px 0 4px; color: var(--muted); font-size: .72rem; }
.task-actions { min-width: 0; }
.task.is-creating:not(.has-save-error) .task-actions { min-height: 16px !important; padding: 0 !important; grid-column: 2 / -1; font-size: .72rem; color: var(--muted); }
.task.is-creating .drag-handle, .task .drag-handle:disabled { opacity: .35; }
.task .archive-undo { min-height: 48px; }
.swipe-feedback { border-radius: 0; font-size: .85rem; }
