:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #69736d;
  --line: #e3ded3;
  --primary: #1f4d3a;
  --primary-ink: #ffffff;
  --accent: #c8913a;
  --ok-bg: #e4f2e8; --ok-ink: #1f5b36;
  --err-bg: #fbe7e4; --err-ink: #8a2c1d;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 8px 24px rgba(20, 30, 25, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121714; --card: #1b221e; --ink: #e8ece9; --muted: #95a19a; --line: #2b352f;
    --primary: #5fae86; --primary-ink: #0d1a13; --accent: #e0aa55;
    --ok-bg: #1d3427; --ok-ink: #a6dcb9; --err-bg: #3b211c; --err-ink: #f2b3a7;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--primary); }
h1 { font-size: 1.7rem; line-height: 1.2; margin: .2em 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .8em; }
code { background: var(--line); padding: .1em .35em; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

/* Pasek górny */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--primary); position: relative; flex: none;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 6px 5px; border: 2px solid var(--primary-ink); border-bottom: 0; border-radius: 6px 6px 0 0;
}
.brand-mark.big { width: 64px; height: 64px; border-radius: 20px; display: inline-block; }
.brand-mark.big::after { inset: 18px 15px 12px; border-width: 4px; border-radius: 14px 14px 0 0; }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a, .linklike {
  padding: 6px 10px; border-radius: 10px; color: var(--muted); text-decoration: none; font: inherit; font-size: .95rem;
}
.nav a.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.linklike { background: none; border: 0; cursor: pointer; }
.inline { display: inline; margin: 0; }

/* Układ */
.wrap { max-width: 720px; margin: 0 auto; padding: 20px 16px 48px; }
.wrap.narrow { max-width: 480px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }

/* Formularze */
.form { display: grid; gap: 14px; }
.form.grid2 { grid-template-columns: 1fr; }
@media (min-width: 600px) { .form.grid2 { grid-template-columns: 1fr 1fr; } .form.grid2 .btn { grid-column: 1 / -1; justify-self: start; } }
.form.row { grid-template-columns: 1fr auto; margin-top: 10px; }
label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); font: inherit; font-weight: 600; text-decoration: none;
}
.btn-wide { width: 100%; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-danger { background: var(--err-bg); color: var(--err-ink); }
.btn:active { transform: translateY(1px); }

.flash { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-size: .95rem; }
.flash-ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash-err { background: var(--err-bg); color: var(--err-ink); }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.tag { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); }
.tag-off { color: var(--err-ink); }

/* Logowanie */
.login { max-width: 420px; margin: 4vh auto 0; }
.login-hero { text-align: center; margin-bottom: 20px; }
.login-hero h1 { margin: 12px 0 4px; }

/* Start */
.hello { margin: 8px 0 18px; }
.hello p { margin: 0; }
.hello h1 { margin: 0 0 8px; font-size: 2rem; }
.gate { text-align: center; }
.gate-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  width: 190px; height: 190px; margin: 8px auto 16px; border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, color-mix(in srgb, var(--primary) 75%, #fff), var(--primary));
  color: var(--primary-ink); text-decoration: none; font-weight: 700; font-size: 1.15rem;
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--primary) 14%, transparent), 0 14px 30px color-mix(in srgb, var(--primary) 35%, transparent);
  transition: transform .15s ease;
}
.gate-btn svg { width: 54px; height: 54px; }
.gate-btn:active { transform: scale(.96); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { display: grid; gap: 4px; padding: 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.tile-ico { font-size: 1.5rem; }
.tile.soon { opacity: .6; }

/* Admin */
.houses { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
@media (max-width: 420px) { .houses { grid-template-columns: repeat(4, 1fr); } }
.house { display: grid; place-items: center; padding: 10px 4px; border-radius: 12px; border: 1px dashed var(--line); color: var(--muted); }
.house strong { font-size: 1.2rem; }
.house.on { border: 1px solid var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); color: var(--ink); }
.users { display: grid; gap: 8px; }
.user { border: 1px solid var(--line); border-radius: 14px; background: var(--bg); }
.user.off { opacity: .6; }
.user summary { display: flex; align-items: center; gap: 10px; padding: 12px 14px; cursor: pointer; list-style: none; }
.user summary::-webkit-details-marker { display: none; }
.user-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-body { padding: 0 14px 14px; display: grid; gap: 10px; }
.user-body form { margin: 0; }

/* ---------- Etap 3: dolny pasek, ogłoszenia ---------- */
textarea { resize: vertical; min-height: 120px; line-height: 1.45; }
body.has-tabbar { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center; gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tabbar a {
  position: relative; flex: 1; max-width: 120px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.badge {
  position: absolute; top: 2px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: .68rem; line-height: 18px; text-align: center;
}
.accent { color: var(--accent); }
.danger { color: var(--err-ink); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.card-head h2 { margin: 0; }

.compose summary { list-style: none; cursor: pointer; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.compose summary::-webkit-details-marker { display: none; }
.compose[open] summary { margin-bottom: 14px; }
.plus { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--primary-ink); font-size: 1.2rem; line-height: 1; }

.feed { display: grid; gap: 0; }
.post h2 { font-size: 1.15rem; margin: 2px 0 8px; }
.post-meta { display: flex; gap: 10px; flex-wrap: wrap; }
.post-meta:empty { display: none; }
.post-body { white-space: normal; overflow-wrap: anywhere; }
.post-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.post-actions { display: flex; gap: 6px; }
.post.important { border-left: 4px solid var(--err-ink); }
.post.pinned { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.tag-new { color: var(--primary); }

.mini-post { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); color: var(--ink); text-decoration: none; }
.mini-post strong { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-post span { flex: none; }
.mini-post.important strong { color: var(--err-ink); }
a.tile { color: var(--ink); text-decoration: none; }
a.tile:active { transform: scale(.98); }
