/* planner board v0.5 — no framework, no build step.
 *
 * Tokens are the decision (spec §16.4): warm anthracite, terracotta/amber/sage,
 * a 11–28 px type scale, 4-pt spacing, radii 10/14/20, tap targets >= 44 px.
 * Nothing here is decorative for its own sake: no gradients, no neon, no glow. */

:root {
  /* ground */
  --bg: #171310;
  --surface: #201a16;
  --raised: #2a221c;
  --line: #3a2f27;

  /* ink */
  --txt: #f2e9de;
  --txt2: #b8a99a;
  --txt3: #7d6f62;

  /* accents */
  --terra: #c9683f;
  --amber: #d99a3c;
  --sage: #7d9471;
  --red: #b8483f;

  /* spacing — 4-pt raster */
  --s1: 4px;  --s2: 8px;  --s3: 12px;  --s4: 16px;  --s6: 24px;  --s8: 32px;

  /* radii */
  --r1: 10px; --r2: 14px; --r3: 20px;

  /* type */
  --t11: 11px; --t13: 13px; --t15: 15px; --t17: 17px; --t22: 22px; --t28: 28px;

  --shadow: 0 1px 2px #0008, 0 8px 24px #0006;
  --shadow-lift: 0 2px 4px #0009, 0 18px 40px #0007;
  --ease-snap: cubic-bezier(.22, .61, .36, 1);
  --safe-b: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--txt);
  font: var(--t15)/1.4 -apple-system, "Inter", system-ui, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body.booting #board { opacity: 0; }

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
  border-radius: var(--r1);
}

/* ---------------------------------------------------------------- login --- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--s6); }

.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r3);
  padding: var(--s6);
  text-align: center;
}

.login-card h1 { margin: 0 0 var(--s2); font-size: var(--t28); letter-spacing: .02em; font-weight: 650; }
.login-sub { margin: 0 0 var(--s4); color: var(--txt2); font-size: var(--t13); }
.login-state { min-height: 20px; margin: var(--s3) 0 0; font-size: var(--t13); color: var(--txt2); word-break: break-word; }
.login-state.err { color: #d98a80; }
.login-hint { margin: var(--s4) 0 0; font-size: var(--t11); line-height: 1.5; color: var(--txt3); }

/* --------------------------------------------------------------- buttons --- */
.btn {
  appearance: none;
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r1);
  background: var(--raised);
  color: var(--txt);
  font-size: var(--t15);
  cursor: pointer;
}

.btn.primary {
  width: 100%;
  background: var(--terra);
  border-color: var(--terra);
  color: #1b120d;
  font-weight: 650;
}

.btn.ghost { background: transparent; color: var(--txt2); border-color: transparent; }
.btn:disabled { opacity: .5; }

.icon-btn {
  appearance: none;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; background: transparent; color: var(--txt2);
  border-radius: var(--r1);
  cursor: pointer;
}
.icon-btn:active { background: var(--raised); }
.icon-btn svg { width: 18px; height: 18px; }

/* ----------------------------------------------------------------- board --- */
.board {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  height: 100dvh;
  padding: calc(env(safe-area-inset-top) + var(--s1)) var(--s2) calc(var(--safe-b) + var(--s1));
}

.bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  padding: 0 var(--s1);
}

.bar-top { display: flex; align-items: center; gap: var(--s2); }

.brand {
  font-size: var(--t13);
  font-weight: 650;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--txt);
}

.summary { flex: 1 1 auto; font-size: var(--t11); color: var(--txt3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.conn { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }
.conn.ok { background: var(--sage); }
.conn.off { background: var(--red); }

/* view switcher — four words, one line, thumb-sized */
.views {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r2);
}

.view-btn {
  appearance: none;
  min-height: 40px;
  padding: 0 var(--s1);
  border: 0;
  border-radius: var(--r1);
  background: transparent;
  color: var(--txt2);
  font-size: var(--t11);
  letter-spacing: .02em;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.view-btn[aria-selected="true"] { background: var(--raised); color: var(--txt); }

/* --------------------------------------------------------------- views --- */
.views-wrap { flex: 1 1 auto; min-height: 0; display: flex; }
.view { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--s2); }
.view-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-bottom: var(--s2); -webkit-overflow-scrolling: touch; }

/* --------------------------------------------------------------- field --- */
/* The quadrant view IS the field: a 2x2 grid of four named quadrants with one
   visible cross. The field grows in ROWS when a quadrant needs more room, the
   view around it scrolls, and each quadrant label sticks to the top of that
   scrollport inside its own quadrant — never at the field edge. */
#view-quadrant { overflow-y: auto; scroll-padding-top: 8px; }

.field {
  position: relative;
  flex: 1 0 auto;            /* grows with its content, is never squeezed */
  min-height: 300px;
  margin: 0 var(--s1);
  border-radius: var(--r3);
  background: var(--surface);
  border: 1px solid var(--line);
  touch-action: none;
  overflow: visible;         /* sticky labels need a field that does not clip */
}

/* left/width/top/height are set by layout() — they are the cross */
.zone { position: absolute; transition: background-color .18s ease; }

.z-tl { background: #b8483f0a; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); border-top-left-radius: var(--r3); }
.z-tr { background: #c9683f0d; border-bottom: 1px solid var(--line); border-top-right-radius: var(--r3); }
.z-bl { background: #7d6f620d; border-right: 1px solid var(--line); border-bottom-left-radius: var(--r3); }
.z-br { background: #d99a3c0a; border-bottom-right-radius: var(--r3); }

.zone.target { background: #d99a3c1a; box-shadow: inset 0 0 0 2px var(--amber); }
.zone.alarm .zname { color: #d98a80; }

/* the label sits in the quadrant's own top-left corner and stays visible */
.zlabel {
  position: sticky;
  top: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  width: fit-content;
  max-width: calc(100% - 16px);
  margin: 8px 8px 0;
  padding: 3px 6px;
  border-radius: var(--r1);
  background: #1b1611d9;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 3;
}

.zname {
  font-size: var(--t11);
  font-weight: 650;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--txt3);
  line-height: 1.2;
}

.zsub { font-size: var(--t11); letter-spacing: .02em; color: #6b6055; }
.zmeta { font-size: var(--t11); color: var(--txt3); }

.placed { position: absolute; inset: 0; pointer-events: none; z-index: 1; }

/* ---------------------------------------------------------------- cards --- */
.card {
  position: relative;
  display: block;
  min-height: 52px;
  padding: 10px 24px 10px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r2);
  background: var(--raised);
  box-shadow: var(--shadow);
  color: var(--txt);
  text-align: left;
  cursor: grab;
  transform: rotate(var(--rot, 0deg));
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transition: box-shadow .16s ease, background-color .16s ease;
}

.card .txt {
  font-size: 13px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* exactly ONE meta line: domain dot · age · deadline */
.card .meta {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin-top: var(--s1);
  font-size: var(--t11);
  color: var(--txt3);
  white-space: nowrap;
  overflow: hidden;
}

.card .meta .dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }
.card .meta .due { color: var(--txt2); }
.card .meta .due.over { color: #d98a80; }

/* the tick: >= 44 px of finger, 18 px of ink */
.card .tick {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--txt3);
  cursor: pointer;
  border-radius: 50%;
}
.card .tick svg { width: 19px; height: 19px; }
.card .tick:active { color: var(--sage); }
.card.done .tick { color: var(--sage); }

.card.in-field { position: absolute; pointer-events: auto; }
.card.dragging {
  cursor: grabbing;
  box-shadow: var(--shadow-lift);
  transform: rotate(var(--rot, 0deg)) scale(1.03);
  z-index: 60;
}
.card.overdue { box-shadow: 0 0 0 2px #b8483f8c, var(--shadow); }
.card.dream { border-style: dashed; }

.card.q-druecken { border-left: 3px solid var(--red); }
.card.q-anfangen { border-left: 3px solid var(--terra); }
.card.q-belohnung { border-left: 3px solid var(--amber); }
.card.q-weg { border-left: 3px solid var(--txt3); }
.card.q-ungesetzt { border-left: 3px solid var(--line); }

/* --------------------------------------------------------------- dock --- */
.dock {
  flex: 0 0 auto;
  max-height: 30dvh;
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  margin: 0 var(--s1);
  padding: var(--s2) var(--s3) var(--s3);
  border: 1px dashed #4a3d33;
  border-radius: var(--r2);
  background: var(--surface);
  transition: border-color .16s ease, background-color .16s ease;
}
.dock.hot { border-color: var(--amber); background: #2a221c; }

.dock-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }

.dock-name {
  font-size: var(--t11);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--txt3);
}

.dock-count { font-size: var(--t11); color: var(--txt3); }

.dock-cards {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
  align-content: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dock-cards .card { width: 46%; min-width: 132px; }

/* --------------------------------------------------- categories / lists --- */
.cats { display: flex; flex-direction: column; gap: var(--s3); padding: 0 var(--s1); }

.cat-head {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s1) 2px var(--s2);
  font-size: var(--t11);
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--txt2);
}
.cat-head .dot { width: 8px; height: 8px; border-radius: 50%; }
.cat-head .n { margin-left: auto; color: var(--txt3); letter-spacing: 0; }

.cat-col { display: flex; flex-direction: column; gap: var(--s2); }

.list { display: flex; flex-direction: column; gap: var(--s2); margin: 0; padding: 0 var(--s1) var(--s4); list-style: none; }
.list .card { width: 100%; }

.rank { display: flex; gap: var(--s2); align-items: baseline; }
.rank .idx { font-size: var(--t11); color: var(--txt3); width: 18px; flex: 0 0 auto; }

/* --------------------------------------------------------------- done --- */
.done-section {
  flex: 0 0 auto;
  margin: 0 var(--s1);
  border-top: 1px solid var(--line);
  padding-top: var(--s2);
}

.done-toggle {
  appearance: none;
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s2);
  border: 0;
  background: transparent;
  color: var(--txt3);
  font-size: var(--t11);
  letter-spacing: .12em;
  text-transform: uppercase;
  cursor: pointer;
}

.badge {
  min-width: 20px;
  padding: 1px var(--s1);
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--txt2);
  font-size: var(--t11);
  letter-spacing: 0;
}

.done-toggle .chev { margin-left: auto; transition: transform .18s ease; color: var(--txt3); }
.done-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }

.done-cards {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
  max-height: 32dvh;
  overflow-y: auto;
  padding: var(--s1) var(--s1) var(--s2);
}

/* ticked cards: quiet. No aging, no size, no domain shine (spec §16.2). */
.card.done {
  opacity: .6;
  background: var(--surface);
  min-height: 48px;
  padding-top: var(--s2);
  padding-bottom: var(--s2);
  cursor: pointer;
}
.card.done .txt { font-size: var(--t13); text-decoration: line-through; text-decoration-color: var(--txt3); }
.card.done .meta { margin-top: 0; }

/* ------------------------------------------------------------- add bar --- */
.addbar {
  flex: 0 0 auto;
  margin: 0 var(--s1);
  padding: var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r2);
  background: var(--surface);
}
.addbar:focus-within { border-color: #5a4a3c; }

.add-row { display: flex; gap: var(--s1); align-items: center; }

.add-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 0 var(--s3);
  border: 1px solid transparent;
  border-radius: var(--r1);
  background: var(--raised);
  color: var(--txt);
  font: inherit;
  font-size: var(--t15);
}
.add-input::placeholder { color: var(--txt3); }

.add-go {
  appearance: none;
  width: 44px; height: 44px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r1);
  background: var(--terra);
  color: #1b120d;
  cursor: pointer;
}
.add-go:disabled { opacity: .45; }
.add-more { flex: 0 0 auto; }

.add-extra { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); padding: var(--s2) 2px 2px; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s1); }

.chip {
  appearance: none;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: var(--s1);
  padding: 0 var(--s2);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--txt2);
  font-size: var(--t11);
  cursor: pointer;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.chip.on { border-color: var(--terra); color: var(--txt); background: #2a221c; }

.add-due { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t11); color: var(--txt3); }
.add-due input {
  min-height: 36px;
  padding: 0 var(--s2);
  border: 1px solid var(--line);
  border-radius: var(--r1);
  background: var(--raised);
  color: var(--txt);
  font: inherit;
  font-size: var(--t13);
  color-scheme: dark;
}

/* --------------------------------------------------------------- sheet --- */
.sheet { position: fixed; inset: 0; z-index: 120; display: flex; align-items: flex-end; background: #0b0907cc; }

.sheet-inner {
  position: relative;
  width: 100%;
  max-height: 84dvh;
  overflow-y: auto;
  padding: var(--s4) var(--s4) calc(var(--s4) + var(--safe-b));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--r3) var(--r3) 0 0;
}

.sheet-x {
  position: absolute; right: var(--s3); top: var(--s2);
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--txt2);
  cursor: pointer;
}

.sheet-title { margin: 0 44px var(--s3) 0; font-size: var(--t17); font-weight: 650; overflow-wrap: anywhere; }
.sheet-note { margin: 0 0 var(--s3); font-size: var(--t13); color: var(--txt2); white-space: pre-wrap; }

.facts { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3); margin: 0 0 var(--s4); font-size: var(--t13); }
.facts dt { color: var(--txt3); }
.facts dd { margin: 0; color: var(--txt); }

.sheet-deadline { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--line); }
.sheet-deadline label { font-size: var(--t11); letter-spacing: .1em; text-transform: uppercase; color: var(--txt3); }
.sheet-deadline input[type="date"] {
  flex: 1 1 140px; min-height: 44px;
  padding: 0 var(--s2);
  border: 1px solid var(--line); border-radius: var(--r1);
  background: var(--raised); color: var(--txt);
  font: inherit; font-size: var(--t13); color-scheme: dark;
}

.sheet-hint { margin: var(--s4) 0 0; font-size: var(--t11); line-height: 1.5; color: var(--txt3); }

/* ----------------------------------------------------- states: load/err --- */
.skeleton { display: flex; flex-direction: column; gap: var(--s2); padding: 0 var(--s1); }
.skeleton .sk {
  height: 56px;
  border-radius: var(--r2);
  background: linear-gradient(100deg, var(--surface) 20%, var(--raised) 40%, var(--surface) 60%);
  background-size: 220% 100%;
  animation: sk 1.4s linear infinite;
}
@keyframes sk { from { background-position: 120% 0; } to { background-position: -40% 0; } }

.state-line {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3);
  border: 1px solid var(--line); border-radius: var(--r2);
  background: var(--surface);
  font-size: var(--t13); color: var(--txt2);
}
.state-line .grow { flex: 1 1 auto; }
.empty { padding: var(--s4) var(--s3); font-size: var(--t13); color: var(--txt3); text-align: left; }

/* --------------------------------------------------------------- toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--s6) + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  padding: var(--s2) var(--s4);
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--txt);
  font-size: var(--t13);
  z-index: 200;
  box-shadow: var(--shadow);
}
.toast.err { border-color: #6d2c26; color: #e8b7b0; }

/* ------------------------------------------------- reduced motion / hover --- */
@media (hover: hover) {
  .card:hover { background-color: #302720; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
  .skeleton .sk { animation: none; }
}
