/* Our flat. Graph paper and an ink-drawn plan; the rooms carry the colour.
   Room fills: green = done for now, yellow = to do today, red = late. */

:root {
  --paper: #E9EFF1;
  --grid: #D3DDE2;
  --grid-strong: #BCCAD2;
  --surface: #FFFFFF;
  --surface-2: #F2F6F7;
  --ink: #22313F;
  --ink-soft: #5B6B78;
  --line: #CFD9DF;
  --wall: #1F2B36;
  --fine: #DDEFD5;
  --due: #FBE3A2;
  --late: #F6BFB3;
  --late-ink: #A8321F;
  --room-empty: #FFFFFF;
  --focus: #1F7A8C;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hand: "Patrick Hand", "Segoe Print", "Comic Sans MS", cursive;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131C23;
    --grid: #1C2831;
    --grid-strong: #27363F;
    --surface: #1A252D;
    --surface-2: #213039;
    --ink: #E3EBF0;
    --ink-soft: #98A9B5;
    --line: #2B3B46;
    --wall: #DCE6EC;
    --fine: #23392A;
    --due: #4B3D14;
    --late: #522720;
    --late-ink: #FF9F8C;
    --room-empty: #1A252D;
    --focus: #63C6D6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; }
.loading { padding: 40px 16px; color: var(--ink-soft); text-align: center; }

/* ---------------------------------------------------------------- frame */

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: max(12px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.day { margin: 0; display: flex; align-items: baseline; gap: 10px; font-size: 1rem; }
.day b { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.01em; }
.day span { color: var(--ink-soft); font-weight: 500; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; border: 0;
  background: var(--c); color: #fff; font-weight: 700; font-size: 1.05rem;
}

main.view { padding: 4px 16px calc(100px + env(safe-area-inset-bottom)); max-width: 1180px; margin: 0 auto; }
.narrow { max-width: 680px; margin: 0 auto; }
.page-title { font-size: 1.6rem; margin: 6px 0 14px; letter-spacing: -0.01em; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button {
  position: relative; border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; font-size: 0.8rem; color: var(--ink-soft);
}
.tabs button.on { color: var(--ink); font-weight: 700; }
.tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs .on svg { stroke-width: 2.3; }
.badge {
  position: absolute; top: 4px; left: calc(50% + 7px);
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--ink); color: var(--paper);
  font: 700 0.72rem/19px var(--font); font-style: normal;
}

/* ---------------------------------------------------------------- the plan */

.map-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 12px; margin-bottom: 4px;
}
.map { display: block; width: 100%; height: auto; max-height: 62vh; }
.map .g1, .map .g5, .map .tex { fill: none; }
.map .g1 { stroke: var(--grid); stroke-width: 0.03; }
.map .g5 { stroke: var(--grid-strong); stroke-width: 0.05; }
.map .tex { stroke: var(--ink); stroke-opacity: 0.11; stroke-width: 0.03; }

.room { outline: none; cursor: pointer; }
.room .floor { fill: var(--room-empty); transition: fill 0.6s ease; }
.room.s-fine .floor { fill: var(--fine); }
.room.s-due .floor { fill: var(--due); }
.room.s-late .floor { fill: var(--late); }
.room.sel .floor, .room:focus-visible .floor { stroke: var(--focus); stroke-width: 0.14; }
.room.cleared .floor { animation: cleared 1s ease; }
@keyframes cleared { 0%, 30% { fill: var(--surface); } }

.map .wall { fill: none; stroke: var(--wall); stroke-linecap: square; pointer-events: none; }
.map .wall.outer { stroke-width: 0.3; }
.map .wall.inner { stroke-width: 0.16; }
.map .window { fill: var(--surface); stroke: var(--wall); stroke-width: 0.045; }
.map .glass { stroke: var(--wall); stroke-width: 0.045; }
.map .door-leaf { stroke: var(--wall); stroke-width: 0.08; stroke-linecap: round; }
.map .door-arc { fill: none; stroke: var(--wall); stroke-width: 0.035; stroke-dasharray: 0.1 0.07; opacity: 0.75; }
.map .openings, .map .labels, .map .sel-outline, .map .preview { pointer-events: none; }

.room-name { font-family: var(--font); font-weight: 650; fill: var(--ink); text-anchor: middle; letter-spacing: -0.01em; }
.badge { fill: var(--surface); stroke-width: 0.1; }
.badge-emoji { text-anchor: middle; dominant-baseline: central; }
.late-dot { fill: #D9442E; stroke: var(--surface); stroke-width: 0.06; }

.map.editing { touch-action: none; user-select: none; -webkit-user-select: none; }
.map.tool-rooms { cursor: crosshair; }
.map.tool-rooms .room { cursor: grab; }
.map.tool-doors, .map.tool-windows, .map.tool-doors .room, .map.tool-windows .room { cursor: pointer; }
.sel-outline { fill: none; stroke: var(--focus); stroke-width: 0.12; stroke-dasharray: 0.3 0.18; }
.handle { fill: var(--surface); stroke: var(--focus); stroke-width: 0.16; cursor: nwse-resize; }
.preview { fill: color-mix(in srgb, var(--focus) 20%, transparent); stroke: var(--focus); stroke-width: 0.1; stroke-dasharray: 0.3 0.18; }

.tools { display: flex; gap: 4px; margin-bottom: 10px; padding: 3px; background: var(--surface-2); border-radius: 12px; width: fit-content; }
.tools button { border: 0; background: none; border-radius: 9px; padding: 8px 16px; font-weight: 600; color: var(--ink-soft); min-height: 40px; }
.tools button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.legend { list-style: none; margin: 10px 2px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.85rem; color: var(--ink-soft); }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1.5px solid var(--wall); display: inline-block; }
.sw.due { background: var(--due); }
.sw.late { background: var(--late); }
.sw.fine { background: var(--fine); }
.hint { margin: 10px 2px 0; font-size: 0.88rem; color: var(--ink-soft); }
.no-map { padding: 18px 8px; text-align: center; }
.no-map p { margin: 0 0 12px; color: var(--ink-soft); }
.form-acts.spaced { margin-top: 18px; }

/* ---------------------------------------------------------------- today */

.person h2, .answered h2, .soon h2, .balance h2, .group h2 {
  font-size: 1.05rem; margin: 22px 0 8px; display: flex; align-items: center; gap: 8px;
}
.person .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--who); }
.count { color: var(--ink-soft); font-weight: 500; font-size: 0.9rem; margin-left: auto; }
.clear { margin: 0; padding: 12px 14px; border-radius: 12px; border: 1.5px dashed var(--line); color: var(--ink-soft); }

.jobs { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.job {
  display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 12px;
  background: var(--surface); border-radius: 12px; padding: 10px 10px 10px 10px;
  border-left: 6px solid var(--who);
}
.job-emoji {
  width: 46px; height: 46px; border-radius: 10px; background: var(--surface-2);
  display: grid; place-items: center; font-size: 1.55rem;
}
.job-what { min-width: 0; }
.job-name { display: block; font-weight: 600; }
.job-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; color: var(--ink-soft); font-size: 0.88rem; }
.late { color: var(--late-ink); font-weight: 600; }
.job-acts { display: flex; align-items: center; gap: 6px; }
.btn { min-height: 44px; border-radius: 10px; padding: 0 16px; font-weight: 700; border: 0; }
.btn.done { background: var(--who); color: #fff; }
.btn.skip { background: transparent; color: var(--ink-soft); border: 1.5px solid var(--line); }
.give {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  border: 2px dashed var(--c); background: transparent; color: var(--c); font-weight: 700;
}
@media (max-width: 480px) {
  .job { grid-template-columns: 46px 1fr; }
  .job-acts { grid-column: 1 / -1; }
  .job-acts .btn.done { flex: 1; }
  .give { margin-left: 4px; }
}

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 2px solid var(--who); border-radius: 999px;
  padding: 4px 4px 4px 12px;
}
.chip small { color: var(--ink-soft); font-size: 0.82rem; }
.chip.skipped { border-style: dashed; border-color: var(--line); color: var(--ink-soft); }
.undo { border: 0; border-radius: 999px; background: var(--surface-2); padding: 6px 12px; font-size: 0.85rem; font-weight: 600; }
.chip.pop { animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1); }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

.soon ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.soon li { display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: baseline; }
.when { color: var(--ink-soft); font-size: 0.9rem; font-weight: 600; }
.what { display: flex; flex-wrap: wrap; gap: 6px; }
.soon-chip { background: var(--surface); border-radius: 8px; padding: 3px 9px; font-size: 0.92rem; }

.bar { display: flex; gap: 3px; height: 36px; border-radius: 10px; overflow: hidden; }
.bar span {
  background: var(--c); color: #fff; font-weight: 700; font-size: 0.92rem;
  display: flex; align-items: center; padding: 0 12px; white-space: nowrap; min-width: fit-content;
  transition: flex-grow 0.6s ease;
}
.bar.none span { opacity: 0.45; }
.note { color: var(--ink-soft); font-size: 0.9rem; margin: 8px 0 0; }
.filter { margin: 10px 0 0; padding: 10px 14px; background: var(--surface); border-radius: 12px; }
.empty { margin: 14px 0; padding: 16px; background: var(--surface); border-radius: 12px; color: var(--ink-soft); }
.link { border: 0; background: none; padding: 0; color: var(--focus); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

.first-run { max-width: 560px; margin: 8vh auto 0; }
.first-run h1 { font-family: var(--hand); font-weight: 400; font-size: 2.6rem; margin: 0 0 8px; }
.first-run p { color: var(--ink-soft); }

/* ---------------------------------------------------------------- buttons and forms */

.primary, .ghost {
  min-height: 44px; border-radius: 10px; padding: 0 16px; font-weight: 700;
}
.primary { background: var(--ink); color: var(--paper); border: 0; }
.ghost { background: transparent; border: 1.5px solid var(--line); font-weight: 600; }
.danger { color: var(--late-ink); border-color: currentColor; }
.form-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }

label { display: flex; flex-direction: column; gap: 5px; font-size: 0.9rem; font-weight: 600; }
input, select {
  min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface); font-size: 1rem; font-weight: 400;
}
input:focus, select:focus { border-color: var(--focus); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.grow { flex: 1 1 180px; }
.short { max-width: 220px; }
.stack { display: grid; gap: 12px; max-width: 420px; }

.chore-form {
  display: grid; gap: 14px; margin: 8px 0 14px; padding: 16px;
  background: var(--surface); border-radius: 14px; border: 2px solid var(--ink);
}
.chore-form h2 { margin: 0; font-size: 1.1rem; }
.emoji-field input { width: 74px; text-align: center; font-size: 1.3rem; }
.emoji-picks { display: flex; flex-wrap: wrap; gap: 4px; margin-top: -6px; }
.emoji-picks button { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.25rem; padding: 0; }
.seg { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.seg legend { padding: 0; margin-bottom: 6px; font-size: 0.9rem; font-weight: 600; }
.seg label { position: relative; font-weight: 500; font-size: 0.95rem; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.seg span { display: block; padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--line); }
.seg input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------------------------------------------------------------- chores */

.chore-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.chore-open {
  width: 100%; display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 12px;
  padding: 8px 14px 8px 8px; border: 0; border-radius: 12px; background: var(--surface); text-align: left;
}
.chore-main { min-width: 0; }
.chore-due { font-size: 0.88rem; color: var(--ink-soft); white-space: nowrap; }
.chore-due.late { color: var(--late-ink); font-weight: 600; }

/* ---------------------------------------------------------------- shopping */

.shop-add {
  position: sticky; top: 62px; z-index: 3;
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px;
  padding: 6px 0 10px; background: var(--paper);
}
@media (max-width: 480px) {
  .shop-add { grid-template-columns: 1fr auto; }
  .shop-add input { grid-column: 1 / -1; }
}
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.suggest button { border: 1.5px dashed var(--grid-strong); background: transparent; border-radius: 999px; padding: 6px 12px; font-size: 0.92rem; }
.items { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: 12px; overflow: hidden; }
.item { display: grid; grid-template-columns: 52px 1fr auto 44px; align-items: center; min-height: 54px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.tick { width: 52px; height: 54px; border: 0; background: none; display: grid; place-items: center; padding: 0; }
.tick::before {
  content: ""; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--ink-soft);
  display: grid; place-items: center; font-weight: 700; font-size: 0.9rem; color: var(--surface);
}
.tick.on::before { content: "✓"; background: var(--ink-soft); }
.got .item-name { text-decoration: line-through; color: var(--ink-soft); }
.who-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); margin-right: 4px; }
.x { width: 44px; height: 54px; border: 0; background: none; color: var(--ink-soft); font-size: 1.4rem; }

/* ---------------------------------------------------------------- flat editor side */

.room-panel h2 { font-size: 1.05rem; margin: 20px 0 8px; }
.room-list { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.mini-chore { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; background: var(--surface); padding: 8px 12px; border-radius: 10px; }
.mini-chore .note { margin: 0; }

.settings h2 { font-size: 1.1rem; margin: 28px 0 10px; }

/* ---------------------------------------------------------------- sign in */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; }
.login-card h1 { font-family: var(--hand); font-weight: 400; font-size: 2.8rem; margin: 0 0 4px; }
.login-plan { width: 112px; }
.login-plan rect { stroke: var(--wall); stroke-width: 2.4; stroke-linejoin: miter; }
.login-plan .s-fine { fill: var(--fine); }
.login-plan .s-due { fill: var(--due); }
.login-plan .s-late { fill: var(--late); }
.form-error { margin: 0; min-height: 1.4em; color: var(--late-ink); font-weight: 600; }

/* ---------------------------------------------------------------- toast */

#toast { position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 10; display: flex; justify-content: center; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px;
  background: var(--ink); color: var(--paper); border-radius: 12px; padding: 10px 10px 10px 16px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22); max-width: 520px; animation: pop 0.3s ease;
}
.toast.error { background: #A8321F; color: #fff; }
.toast button { min-height: 36px; border-radius: 8px; border: 1.5px solid currentColor; background: none; color: inherit; padding: 0 14px; font-weight: 700; }

/* ---------------------------------------------------------------- wide screens */

@media (min-width: 900px) {
  .split { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  .split .map-panel { position: sticky; top: 72px; }
  .map { max-height: 74vh; }
  .split .lists > :first-child { margin-top: 0; }
  .tabs {
    left: 50%; right: auto; bottom: 16px; transform: translateX(-50%);
    width: 460px; border: 1px solid var(--line); border-radius: 16px; padding-bottom: 0;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.1);
  }
  #toast { bottom: 96px; }
}

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