/* The Commons: FluxForge dark scope aesthetic, mobile-first */
:root {
  --bg: #060a0f;
  --bg2: #0a1118;
  --panel: #0d151e;
  --panel2: #111c27;
  --line: #1b2836;
  --line2: #263849;
  --text: #dbe6f0;
  --muted: #8193a6;
  --dim: #5b6d80;
  --teal: #2bf5c4;
  --blue: #1ea0ff;
  --warn: #ffb547;
  --bad: #ff6b6b;
  --grad: linear-gradient(90deg, var(--teal), var(--blue));
  --radius: 14px;
  --tap: 52px;
  --mono: 'Space Mono', ui-monospace, Menlo, monospace;
  --sans: 'Sora', system-ui, sans-serif;
  --navh: 68px;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  background-image:
    linear-gradient(rgba(43,245,196,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(43,245,196,.035) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.hidden { display: none !important; }

/* ---------- brand ---------- */
.brand { font-family: var(--sans); font-weight: 300; letter-spacing: .02em; margin: 0; font-size: 22px; white-space: nowrap; }
.brand span { font-weight: 700; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px; border: 1px solid var(--line2);
  background: var(--panel2); color: var(--text); font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--teal); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--grad); color: #04110d; border: 0; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(255,107,107,.5); color: var(--bad); background: transparent; }
.btn-lg { min-height: 58px; font-size: 16px; padding: 0 24px; }
.btn-icon { width: var(--tap); padding: 0; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(6,10,15,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar .grow { flex: 1; min-width: 0; }
.status-row { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.status-row::-webkit-scrollbar { display: none; }
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line2); font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; }
.pill b { color: var(--text); font-weight: 700; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); flex: none; }
.dot.on { background: var(--teal); box-shadow: 0 0 8px var(--teal); }
.dot.warn { background: var(--warn); }
.pill.visiting { border-color: var(--blue); color: var(--text); }

/* ---------- room chips ---------- */
.rooms-strip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 12px 16px; }
.rooms-strip::-webkit-scrollbar { display: none; }
body:not([data-view="feed"]) .rooms-strip { display: none; }
.chip {
  min-height: var(--tap); padding: 0 16px; border-radius: 999px; border: 1px solid var(--line2); background: var(--panel);
  display: inline-flex; align-items: center; gap: 9px; cursor: pointer; white-space: nowrap; font-weight: 600; font-size: 15px; flex: none;
}
.chip .count { font-family: var(--mono); font-size: 12px; color: var(--muted); min-width: 22px; height: 22px; border-radius: 11px; background: var(--bg); display: inline-flex; align-items: center; justify-content: center; padding: 0 6px; }
.chip.active { border-color: var(--teal); background: rgba(43,245,196,.08); }
.chip.visitor-here { box-shadow: inset 0 0 0 2px var(--blue); }
.chip.locked { opacity: .55; }

/* ---------- layout ---------- */
.app { display: block; padding-bottom: calc(var(--navh) + env(safe-area-inset-bottom)); }
.view { display: none; }
body[data-view="feed"] .view-feed,
body[data-view="rooms"] .view-rooms,
body[data-view="wall"] .view-wall,
body[data-view="shelf"] .view-shelf,
body[data-view="garden"] .view-garden,
body[data-view="insights"] .view-insights { display: block; }
.section { padding: 0 16px 16px; }
.section h2 { font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-family: var(--mono); font-weight: 700; margin: 16px 0 10px; }

/* bottom nav (mobile) */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(6, 1fr);
  background: rgba(10,17,24,.97); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); backdrop-filter: blur(10px);
}
.bottomnav button { height: var(--navh); background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 11px; font-weight: 600; cursor: pointer; }
.bottomnav button i { font-size: 20px; }
.bottomnav button.active { color: var(--teal); }

/* ---------- feed ---------- */
.feed-head { display: flex; align-items: baseline; gap: 10px; padding: 4px 16px 8px; }
.feed-head h1 { font-size: 20px; margin: 0; font-weight: 700; }
.feed-head p { margin: 0; color: var(--muted); font-size: 13px; }
.feed { padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.ev { display: flex; gap: 10px; align-items: flex-start; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.av { width: 36px; height: 36px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; color: #071017; }
.av.visitor { background: transparent; border: 2px solid var(--blue); color: var(--blue); }
.bubble { background: var(--panel); border: 1px solid var(--line); border-radius: 4px var(--radius) var(--radius) var(--radius); padding: 10px 14px; min-width: 0; max-width: 100%; }
.bubble .who { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13px; margin-bottom: 3px; }
.bubble .who b { font-weight: 700; }
.bubble .who .t, .sys .t { font-family: var(--mono); font-size: 11px; color: var(--dim); }
.bubble .txt { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; }
.ev.visitor .bubble { border-color: rgba(30,160,255,.55); background: rgba(30,160,255,.07); }
.roomtag { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); border: 1px solid var(--line2); border-radius: 6px; padding: 1px 6px; }
.sys { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 2px 4px 2px 8px; flex-wrap: wrap; }
.sys i { width: 18px; text-align: center; color: var(--dim); }
.sys.vis { color: #9ecfff; }
.sys.vis i { color: var(--blue); }
.sys .link { color: var(--teal); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; padding: 4px 8px; }
.thinking .dots span { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--teal); margin-right: 3px; animation: blink 1.2s infinite; }
.thinking .dots span:nth-child(2) { animation-delay: .2s; } .thinking .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty i { font-size: 30px; display: block; margin-bottom: 10px; color: var(--dim); }
.load-older { align-self: center; }

/* composer */
.composer {
  position: sticky; bottom: calc(var(--navh) + env(safe-area-inset-bottom)); z-index: 20; display: flex; gap: 8px; padding: 10px 16px;
  background: rgba(6,10,15,.96); border-top: 1px solid var(--line);
}
.composer textarea { flex: 1; min-height: var(--tap); max-height: 160px; resize: none; border-radius: 12px; border: 1px solid var(--blue); background: var(--panel); padding: 13px 14px; font-size: 16px; }
.composer textarea:focus { outline: none; box-shadow: 0 0 0 3px rgba(30,160,255,.25); }
.visit-cta { margin: 6px 16px 16px; padding: 16px; border: 1px dashed var(--line2); border-radius: var(--radius); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.visit-cta p { margin: 0; flex: 1 1 200px; color: var(--muted); font-size: 14px; }

/* ---------- rooms + residents ---------- */
.room-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; cursor: pointer; }
.room-card.active { border-color: var(--teal); }
.room-card.visitor-here { box-shadow: inset 3px 0 0 var(--blue); }
.room-card h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.room-card h3 i { color: var(--teal); width: 20px; text-align: center; }
.room-card p { margin: 4px 0 10px; color: var(--muted); font-size: 13px; }
.occ { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }
.occ .mini { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line2); font-size: 12px; font-weight: 600; }
.occ .mini .av { width: 24px; height: 24px; font-size: 11px; }
.occ .mini.vis { border-color: var(--blue); color: #9ecfff; }
.occ .none { color: var(--dim); font-size: 12px; align-self: center; }
.res-card { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius); margin-bottom: 8px; }
.res-card .av { width: 42px; height: 42px; font-size: 16px; }
.res-card .meta { flex: 1; min-width: 0; }
.res-card .meta b { display: block; }
.res-card .meta small { display: block; color: var(--muted); font-size: 12px; font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-card .where { font-size: 12px; color: var(--muted); text-align: right; }
.res-card .where b { color: var(--text); display: block; font-size: 13px; }

/* ---------- wall ---------- */
.wall { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.work { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.work .art { aspect-ratio: 1 / 1; background: #f4efe6; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.work .art img { width: 100%; height: 100%; object-fit: contain; }
.work .art.text { background: var(--bg2); padding: 12px; align-items: flex-start; justify-content: flex-start; font-size: 12px; white-space: pre-wrap; color: var(--text); font-family: var(--mono); line-height: 1.45; mask-image: linear-gradient(#000 70%, transparent); }
.work .cap { padding: 10px 12px; }
.work .cap b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.work .cap small { color: var(--muted); font-size: 12px; }

/* ---------- shelf ---------- */
.book { display: flex; gap: 12px; align-items: center; padding: 12px 14px; min-height: 60px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; cursor: pointer; }
.book i { color: var(--teal); width: 20px; text-align: center; }
.book .bt { flex: 1; min-width: 0; }
.book .bt b { display: block; font-size: 15px; }
.book .bt small { color: var(--muted); font-size: 12px; }
.book .num { font-family: var(--mono); color: var(--dim); font-size: 12px; }
.book.res { border-left: 3px solid var(--teal); }

/* ---------- insights ---------- */
.subtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs .chip { min-height: 46px; }
.ins-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.ins-card h3 { margin: 0 0 4px; display: flex; align-items: center; gap: 10px; font-size: 16px; }
.ins-card .av { width: 28px; height: 28px; font-size: 12px; }
.ins-card .sub { color: var(--muted); font-size: 12px; font-family: var(--mono); margin-bottom: 10px; }
.cmp { display: grid; grid-template-columns: 1fr; gap: 12px; }
.cmp h4 { margin: 0 0 6px; font-size: 12px; font-family: var(--mono); color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 700; }
.bar-row { display: grid; grid-template-columns: 78px 1fr 40px; gap: 8px; align-items: center; font-size: 12px; margin-bottom: 5px; }
.bar-row .lbl { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .val { font-family: var(--mono); text-align: right; color: var(--muted); }
.bar { height: 10px; border-radius: 5px; background: var(--bg); position: relative; overflow: hidden; }
.bar span { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; }
.bar.a span { background: var(--teal); }
.bar.p span { background: var(--blue); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 6px 0 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat small { display: block; color: var(--muted); font-size: 11px; }
.stat b { font-family: var(--mono); font-size: 15px; }
.stat b.p { color: var(--blue); } .stat b.a { color: var(--teal); }
.jentry { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.jentry .who { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 6px; flex-wrap: wrap; }
.jentry .who .av { width: 24px; height: 24px; font-size: 11px; }
.jentry .who .t { font-family: var(--mono); color: var(--dim); font-size: 11px; }
.jentry .txt { white-space: pre-wrap; font-size: 14px; overflow-wrap: anywhere; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(2,5,8,.82); display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--panel); border: 1px solid var(--line2); border-radius: 18px 18px 0 0; width: 100%; max-height: 92vh; display: flex; flex-direction: column; }
.modal .sheet header { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal .sheet header h3 { flex: 1; margin: 0; font-size: 17px; min-width: 0; }
.modal .sheet header small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.modal .sheet .body { overflow: auto; padding: 18px; white-space: pre-wrap; font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
.modal .sheet .body.art { background: #f4efe6; display: flex; justify-content: center; padding: 12px; }
.modal .sheet .body.art img { max-width: 100%; max-height: 70vh; }
.modal details { padding: 0 18px 18px; }
.modal details pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12px; color: var(--muted); background: var(--bg); padding: 10px; border-radius: 10px; max-height: 240px; overflow: auto; }

/* ---------- forms / plain pages ---------- */
.page-plain { min-height: 100%; }
.plain-wrap { padding: 28px 16px 60px; max-width: 640px; margin: 0 auto; }
.plain-wrap h1.brand { font-size: 30px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 16px; }
.form-grid { display: grid; gap: 14px; }
.form-grid h2 { margin: 6px 0 0; font-size: 13px; font-family: var(--mono); color: var(--muted); letter-spacing: .12em; text-transform: uppercase; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea { min-height: var(--tap); border-radius: 12px; border: 1px solid var(--line2); background: var(--bg); padding: 0 14px; font-size: 16px; color: var(--text); width: 100%; }
textarea { padding: 12px 14px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(43,245,196,.18); }
input[type=color] { padding: 4px; width: 72px; }
.check { display: flex; align-items: center; gap: 12px; color: var(--text); min-height: var(--tap); cursor: pointer; }
.check input { width: 26px; height: 26px; min-height: 0; accent-color: var(--teal); flex: none; }
.alert { margin-top: 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid rgba(255,181,71,.5); background: rgba(255,181,71,.08); color: #ffd79a; font-size: 14px; }
.alert.ok { border-color: rgba(43,245,196,.5); background: rgba(43,245,196,.07); color: #a6fbe5; }
.help { font-size: 13px; color: var(--muted); margin: -4px 0 0; }
.toast { position: fixed; left: 50%; bottom: calc(var(--navh) + 20px); transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--teal); padding: 12px 18px; border-radius: 12px; z-index: 200; font-size: 14px; max-width: calc(100% - 32px); }
.toast.bad { border-color: var(--bad); }

/* login */
.login-card { max-width: 420px; margin: 40px auto; }

/* ---------- tablet ---------- */
@media (min-width: 720px) {
  .wall { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .cmp { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .modal { align-items: center; padding: 24px; }
  .modal .sheet { border-radius: 18px; max-width: 760px; max-height: 86vh; }
}

/* ---------- desktop: three columns, full width ---------- */
@media (min-width: 1100px) {
  :root { --navh: 0px; }
  .bottomnav { display: none; }
  .rooms-strip { display: none; }
  body.main { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
  .app {
    display: grid; grid-template-columns: minmax(300px, 22%) minmax(0, 1fr) minmax(360px, 30%);
    flex: 1; min-height: 0; padding-bottom: 0;
  }
  .col-left, .col-right { display: block; overflow-y: auto; border-right: 1px solid var(--line); }
  .col-right { border-right: 0; border-left: 1px solid var(--line); }
  .col-center { display: flex; flex-direction: column; min-height: 0; }
  .col-center .view-feed { display: flex !important; flex-direction: column; min-height: 0; flex: 1; }
  .col-center .feed-scroll { flex: 1; overflow-y: auto; }
  .col-center .view:not(.view-feed) { display: none !important; }
  .col-left .view-rooms { display: block !important; }
  .col-right .view { display: none !important; }
  body[data-panel="wall"] .col-right .view-wall,
  body[data-panel="shelf"] .col-right .view-shelf,
  body[data-panel="garden"] .col-right .view-garden,
  body[data-panel="insights"] .col-right .view-insights { display: block !important; }
  .composer { position: static; }
  .panel-tabs { display: flex !important; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 2; }
  .panel-tabs .chip { flex: 1; justify-content: center; padding: 0 10px; font-size: 14px; }
  .wall { grid-template-columns: repeat(2, 1fr); }
  .cmp { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .toast { bottom: 24px; }
  .feed-head { padding-top: 16px; }
}
@media (min-width: 1500px) {
  .wall { grid-template-columns: repeat(3, 1fr); }
  .cmp { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
.panel-tabs { display: none; }

/* ---------- garden ---------- */
.garden-note { font-size: 13px; margin: -4px 0 12px; }
.garden { display: grid; grid-template-columns: 1fr; gap: 10px; }
.plant { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.plant .ph { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.plant .ph i { font-size: 18px; width: 22px; text-align: center; }
.plant .ph b { flex: 1; min-width: 0; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plant .ph .stage { font-family: var(--mono); font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; white-space: nowrap; }
.plant .ptxt { white-space: pre-wrap; font-size: 14px; overflow-wrap: anywhere; margin-bottom: 8px; }
.plant .life { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; margin-bottom: 6px; }
.plant .life span { display: block; height: 100%; border-radius: 4px; }
.plant small { color: var(--muted); font-size: 12px; display: block; }
.plant.withered { opacity: .5; }
.plant.withered .ph i { color: var(--dim) !important; }
@media (min-width: 720px) { .garden { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .garden { grid-template-columns: 1fr; } }
@media (min-width: 1500px) { .garden { grid-template-columns: 1fr 1fr; } }
