:root {
  --primary: #1e293b;
  --primary-dark: color-mix(in srgb, var(--primary) 78%, black);
  --text-main: #0f172a;
  --text-muted: #475569;
  --border: #e2e8f0;
  --card-bg: #ffffff;
  --radius: 10px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --header-h: 52px;
  --tabbar-h: 58px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }

body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.125;
  color: var(--text-main);
  background: #f1f5f9;
  padding-top: var(--header-h);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 0.5rem);
  -webkit-text-size-adjust: 100%;
}
body.no-tabs { padding-bottom: 1rem; }

.hidden { display: none !important; }

.page-bg, .page-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none !important;
  z-index: 0;
}
.page-bg {
  background-image: url("/bg.jpg");
  background-size: cover;
  background-position: center;
  opacity: 0.35;
}
.page-overlay { background: rgba(255, 255, 255, 0.88); }

.content-shell { position: relative; z-index: 10; min-height: 40vh; }
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.75rem 1rem 1.25rem;
  position: relative;
  z-index: 10;
}

.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  z-index: 90;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  height: var(--header-h);
  padding: 0 0.75rem 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--text-main);
  min-width: 0;
}
.brand-logo {
  width: 28px; height: 28px;
  object-fit: contain;
  border-radius: 6px;
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.1rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-shrink: 0;
}
.header-actions select {
  width: auto;
  margin: 0;
  padding: 0.22rem 0.35rem;
  font-size: 0.8rem;
}

.help-toggle {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--primary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: static;
  box-shadow: none;
}
.help-toggle:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.help-panel {
  display: none;
  position: fixed;
  top: calc(var(--header-h) + 0.4rem);
  right: 0.75rem;
  width: min(360px, calc(100vw - 1.5rem));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  z-index: 95;
}
.help-panel.open { display: block; }
.help-panel h3 {
  margin: 0 0 0.5rem;
  color: var(--primary);
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
}
.help-panel ol {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.install-bar {
  position: relative;
  z-index: 20;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.45rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text-muted);
}
.install-bar .btn { flex-shrink: 0; }
.install-bar #install-bar-text { flex: 1; min-width: 0; }

.home-kicker {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.05rem;
  color: var(--primary);
  margin: 0 0 0.35rem;
  line-height: 1.2;
}
.home-lead {
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.35;
  margin: 0;
}

.section-label {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.05rem;
  color: var(--primary);
  margin: 0.35rem 0;
}
.section-lead {
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.3;
  margin-bottom: 0.65rem;
}
.text-muted { color: var(--text-muted); }
.label {
  display: block;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0.55rem 0 0.25rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  margin-bottom: 0.65rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

input, textarea, select {
  width: 100%;
  font: inherit;
  line-height: 1.3;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text-main);
  margin-bottom: 0.15rem;
}
textarea { resize: vertical; min-height: 4rem; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid color-mix(in srgb, var(--primary) 35%, white);
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.2;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn-secondary {
  background: #fff;
  color: var(--text-main);
  border-color: var(--border);
}
.btn-secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-sm { font-size: 0.78rem; padding: 0.28rem 0.5rem; }
.btn-block { width: 100%; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.35rem 0 0.55rem;
}
.chip {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.12rem 0.4rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: var(--text-muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}

.member-row {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(720px, 100%);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.97);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 80;
}
.tabbar-item {
  flex: 1;
  max-width: 110px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.68rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  cursor: pointer;
  padding: 0.25rem 0.1rem;
  text-decoration: none;
}
.tabbar-item.active, .tabbar-item:hover { color: var(--primary); }
.tab-icon {
  width: 22px; height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tab-icon svg {
  width: 20px; height: 20px;
  fill: currentColor;
  display: block;
}

.chat-box {
  height: min(50vh, 380px);
  overflow-y: auto;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  margin: 0.5rem 0;
}
.chat-stream { display: flex; flex-direction: column; gap: 0.4rem; }
.bubble {
  max-width: 85%;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.3;
}
.bubble.mine {
  align-self: flex-end;
  background: color-mix(in srgb, var(--primary) 18%, white);
  border: 1px solid color-mix(in srgb, var(--primary) 30%, white);
}
.bubble.theirs {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
}
.chat-compose { display: flex; gap: 0.4rem; align-items: center; }
.chat-compose input { margin: 0; flex: 1; }

.ad-line {
  position: relative;
  z-index: 10;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
  margin-top: 0.5rem;
}
.ad-line a { color: var(--primary); text-decoration: none; }

.entry-text {
  flex: 1;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  line-height: 1.3;
}
.entry-text.is-done, .is-done {
  text-decoration: line-through !important;
  opacity: 0.72;
  color: var(--text-muted);
}

.status-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-available { background: #15803d; }
.status-quiet { background: #b45309; }
.status-busy { background: #b91c1c; }

@media (min-width: 768px) {
  .tabbar-item { font-size: 0.72rem; }
}
