/* The Barracks: a phone-first app in the same night, bronze and crimson as the Chronicle. */
:root {
  --night: #0E0907; --panel: #19110C; --panel-2: #231811; --line: rgba(198, 144, 67, .18); --bronze: #C69043; --gold: #E8C36A;
  --crimson: #B02424; --bone: #F1E6D2; --bone-2: #BFAE95; --display: 'Cinzel', serif;
  --ui: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; --serif: 'EB Garamond', Georgia, serif;
  --top: calc(54px + env(safe-area-inset-top)); --tabs: calc(64px + env(safe-area-inset-bottom));
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--night); color: var(--bone); font: 400 15px/1.45 var(--ui); }
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--bone); }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.boot { height: 100vh; display: grid; place-items: center; }
.boot img { width: 90px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; transform: scale(.94); } }

/* Buttons and fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 0 18px; border-radius: 10px;
  border: 1px solid transparent; font: 700 .78rem/1 var(--display); letter-spacing: .12em; text-transform: uppercase; }
.btn.gold { background: linear-gradient(180deg, #F0CF7E, #C99A45); color: #1A100A; }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--bone); }
.btn:disabled { opacity: .55; }
.btn.busy { position: relative; color: transparent !important; }
.btn.busy::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #1A100A; border-right-color: transparent;
  animation: spin .7s linear infinite; }
.btn.ghost.busy::after { border-color: var(--bone); border-right-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0; background: transparent; color: var(--bone-2); flex: none; }
.icon-btn.gold { background: var(--gold); color: #1A100A; }
.ghost-sm { border: 1px solid var(--line); background: transparent; color: var(--bone); border-radius: 8px; padding: 6px 10px; font-size: .8rem; flex: none; }
.field { display: grid; gap: 6px; }
.field span { font-size: .8rem; color: var(--bone-2); }
.field input, .me-form input:not([type=checkbox]), textarea, .row input {
  width: 100%; min-height: 46px; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); outline: none; }
.field input:focus, textarea:focus, .row input:focus { border-color: var(--bronze); }
.err { color: #FF8A7A; min-height: 1.2em; margin: 0; font-size: .9rem; }
.empty { text-align: center; color: var(--bone-2); font-style: italic; font-family: var(--serif); font-size: 1.05rem; padding: 30px 16px; }
.row { display: flex; gap: 10px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabs) + 14px); translate: -50% 0; z-index: 100; background: var(--bone); color: var(--night);
  padding: 10px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: calc(100vw - 32px); transition: opacity .5s; }
.toast.bad { background: #FFD8D2; }
.toast.go { opacity: 0; }

/* Gate */
.gate { min-height: 100svh; max-width: 420px; margin: 0 auto; padding: calc(24px + env(safe-area-inset-top)) 22px 40px; display: flex; flex-direction: column;
  background: radial-gradient(ellipse 80% 40% at 50% 18%, #2A1810, transparent 70%); }
.gate-back { color: var(--bone-2); text-decoration: none; font-size: .85rem; }
.gate-helmet { width: 120px; margin: 26px auto 10px; filter: drop-shadow(0 14px 30px rgba(0,0,0,.7)); }
.gate h1 { font: 900 2rem/1.1 var(--display); text-align: center; margin: 0; letter-spacing: .08em; text-transform: uppercase;
  background: linear-gradient(#F6DB9C, #C69043); -webkit-background-clip: text; background-clip: text; color: transparent; }
.gate-sub { text-align: center; color: var(--bone-2); font-family: var(--serif); font-style: italic; font-size: 1.1rem; margin: 6px 0 24px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg button { border: 0; background: none; padding: 11px; border-radius: 9px; color: var(--bone-2); font-weight: 600; }
.seg button.on { background: var(--panel-2); color: var(--gold); box-shadow: inset 0 0 0 1px var(--line); }
.gate-form { display: grid; gap: 14px; margin-top: 18px; }
.gate-form .btn { margin-top: 4px; }
.gate-note { color: var(--bone-2); font-size: .85rem; text-align: center; margin-top: 18px; }

/* Shell */
.shell { height: 100dvh; display: flex; flex-direction: column; max-width: 680px; margin: 0 auto; }
.top { position: relative; z-index: 5; flex: none; height: var(--top); padding: env(safe-area-inset-top) 12px 0; display: flex; align-items: center; gap: 10px;
  background: rgba(14, 9, 7, .92); border-bottom: 1px solid var(--line); }
.top-home img { width: 34px; height: 34px; }
.top-title { flex: 1; margin: 0; font: 700 1.02rem/1 var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.top-online { font-size: .78rem; color: #7FD18B; }
.top-online:not(:empty)::before { content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #5FCB71; margin-right: 6px; }
.view { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px 12px 24px; }
.tabs { flex: none; height: var(--tabs); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--panel); border-top: 1px solid var(--line); }
.tab { position: relative; border: 0; background: none; color: var(--bone-2); display: grid; place-items: center; align-content: center; gap: 3px; font-size: .68rem; }
.tab.on { color: var(--gold); }
.tab-camera .ic { width: 28px; height: 28px; }
.tab-camera { margin: -14px auto 0; width: 62px; height: 62px; border-radius: 50%; background: linear-gradient(180deg, #F0CF7E, #C99A45); color: #1A100A;
  box-shadow: 0 0 0 5px var(--night), 0 8px 20px rgba(0,0,0,.6); align-self: start; }
.badge { position: absolute; top: 8px; left: 54%; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--crimson); color: #fff;
  font: 700 .66rem/18px var(--ui); font-style: normal; }

/* Avatars */
.av { width: var(--s); height: var(--s); border-radius: 50%; overflow: hidden; flex: none; display: grid; place-items: center;
  background: linear-gradient(135deg, #5C3A1A, #2A1A0E); box-shadow: 0 0 0 1.5px var(--bronze); }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av b { font: 700 calc(var(--s) * .36)/1 var(--display); color: var(--gold); }

/* Feed */
.composer { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--panel); color: var(--bone-2); text-align: left; margin-bottom: 14px; }
.composer > span:not(.av) { flex: 1; font-family: var(--serif); font-size: 1.08rem; font-style: italic; }
.fresh { position: sticky; top: 0; z-index: 2; text-align: center; margin: -6px 0 8px; }
.pill { border: 0; border-radius: 20px; padding: 8px 16px; background: var(--gold); color: #1A100A; font-weight: 700; box-shadow: 0 6px 16px rgba(0,0,0,.5); }
.post { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 14px; overflow: hidden; }
.post.pinned { border-color: rgba(232, 195, 106, .55); }
.post > header { display: flex; align-items: center; gap: 10px; padding: 12px 8px 8px 12px; }
.post > header > div { flex: 1; min-width: 0; display: grid; }
.post > header b { font-weight: 650; }
.post > header small { color: var(--bone-2); font-size: .78rem; }
.pin-tag { display: none; color: var(--gold); }
.post.pinned .pin-tag { display: block; }
.pin-tag .ic { width: 18px; height: 18px; fill: var(--gold); }
.post .body { margin: 0; padding: 0 14px 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; }
.grid { display: grid; gap: 2px; }
.grid.g2, .grid.g4 { grid-template-columns: 1fr 1fr; }
.grid.g3 { grid-template-columns: 1fr 1fr; }
.grid.g3 .ph:first-child { grid-column: 1 / -1; }
.ph { position: relative; border: 0; padding: 0; background: #000; }
.ph img { width: 100%; aspect-ratio: 4/3; object-fit: cover; }
.grid.g1 .ph img { aspect-ratio: auto; max-height: 520px; }
.ph b { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); font-size: 1.6rem; }
.post footer { display: flex; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--line); }
.act { display: flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--bone-2); padding: 8px 10px; border-radius: 10px; min-width: 64px; }
.act.on { color: var(--gold); }
.act.on .ic { fill: rgba(232, 195, 106, .25); }
.comments { padding: 4px 12px 12px; display: grid; gap: 10px; border-top: 1px solid var(--line); }
.c { display: flex; gap: 8px; align-items: flex-start; }
.c p { margin: 3px 0 0; flex: 1; overflow-wrap: anywhere; }
.c small { color: var(--bone-2); }
.x { border: 0; background: none; color: var(--bone-2); font-size: 1.2rem; line-height: 1; padding: 4px 6px; }
.c-form { display: flex; gap: 8px; align-items: center; }
.c-form input { flex: 1; min-height: 42px; padding: 9px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel-2); outline: none; }
.more { width: 100%; }

/* Sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,0); display: flex; align-items: flex-end; justify-content: center; transition: background .25s; }
.sheet-wrap.up { background: rgba(0,0,0,.6); }
.sheet { width: 100%; max-width: 680px; max-height: 92dvh; overflow-y: auto; background: var(--panel); border-radius: 18px 18px 0 0; border: 1px solid var(--line);
  border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); transform: translateY(100%); transition: transform .25s ease-out; }
.sheet-wrap.up .sheet { transform: none; }
.sheet header { display: flex; align-items: center; padding: 10px 8px 4px 16px; }
.sheet header h2 { flex: 1; margin: 0; font: 700 .95rem/1 var(--display); letter-spacing: .1em; text-transform: uppercase; color: var(--gold); }
.sheet-body { display: grid; gap: 12px; padding: 8px 16px 18px; }
.sheet .row .btn { flex: 1; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.th { position: relative; width: 78px; height: 78px; }
.th img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.th button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--bone); color: var(--night); font-weight: 700; }
.row-btn { text-align: left; border: 0; border-radius: 12px; background: var(--panel-2); padding: 15px 14px; font-size: 1rem; }
.row-btn.danger { color: #FF8A7A; }

/* The Mess */
.view-mess { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.stories { flex: none; display: flex; gap: 12px; overflow-x: auto; padding: 12px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.story { flex: none; border: 0; background: none; display: grid; justify-items: center; gap: 5px; width: 66px; padding: 0; }
.story small { font-size: .72rem; color: var(--bone-2); max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ring { position: relative; padding: 3px; border-radius: 50%; background: conic-gradient(var(--gold), var(--crimson), var(--gold)); }
.ring.seen { background: var(--line); }
.ring.none { background: transparent; }
.ring .av { box-shadow: 0 0 0 3px var(--night); }
.ring i { position: absolute; right: 0; bottom: 0; width: 22px; height: 22px; border-radius: 50%; background: var(--gold); color: #1A100A; font: 700 1.1rem/21px var(--ui);
  font-style: normal; box-shadow: 0 0 0 3px var(--night); }
.msgs { flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 84%; margin-top: 8px; }
.msg.chain { margin-top: 0; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.av-gap { width: 30px; flex: none; }
.bub { position: relative; background: var(--panel-2); border: 1px solid var(--line); padding: 7px 11px 6px; border-radius: 16px 16px 16px 5px; min-width: 64px;
  user-select: text; -webkit-touch-callout: none; }
.msg.mine .bub { background: #3A2614; border-color: rgba(232, 195, 106, .3); border-radius: 16px 16px 5px 16px; }
.bub .who { display: block; font-size: .76rem; color: var(--gold); margin-bottom: 2px; }
.bub p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.bub time { display: block; text-align: right; font-size: .66rem; color: var(--bone-2); margin-top: 2px; }
.mphoto { border: 0; padding: 0; background: none; margin: 2px -5px 4px; }
.mphoto img { border-radius: 12px; max-height: 300px; width: auto; }
.snap { display: grid; grid-template-columns: auto 1fr; gap: 0 8px; align-items: center; text-align: left; border: 1px solid var(--crimson);
  background: rgba(176, 36, 36, .14); color: #FFB4A8; border-radius: 10px; padding: 9px 12px; margin: 2px 0 4px; }
.snap .ic { grid-row: span 2; color: var(--crimson); }
.snap small { font-size: .7rem; opacity: .75; }
.snap.opened { border-color: var(--line); background: none; color: var(--bone-2); }
.snap.opened .ic { color: var(--bone-2); }
.msg.mine .snap { border-color: var(--line); color: var(--bone-2); background: none; }
.compose-bar { flex: none; display: flex; align-items: flex-end; gap: 4px; padding: 8px; border-top: 1px solid var(--line); background: var(--panel); }
.compose-bar textarea { flex: 1; min-height: 42px; max-height: 120px; resize: none; border-radius: 21px; padding: 10px 14px; }

/* Overlays */
.overlay { position: fixed; inset: 0; z-index: 80; background: #000; display: grid; place-items: center; }
.overlay > img, .cam-canvas { max-width: 100%; max-height: 100dvh; object-fit: contain; }
.ov-close { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; z-index: 3; width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.5); color: #fff; display: grid; place-items: center; }
.ov-nav { position: absolute; inset: auto 0 calc(20px + env(safe-area-inset-bottom)); display: flex; justify-content: center; gap: 30px; }
.ov-nav button { width: 52px; height: 52px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 2rem; }
.snap-top { position: absolute; top: calc(18px + env(safe-area-inset-top)); left: 12px; right: 64px; z-index: 2; display: flex; align-items: center; gap: 10px;
  color: #fff; text-shadow: 0 1px 4px #000; }
.snap-top small { opacity: .8; }
.count { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--gold); display: grid; place-items: center; font-weight: 700; }
.snap-view .cap { position: absolute; left: 0; right: 0; top: 66%; margin: 0; padding: 10px; text-align: center; background: rgba(0,0,0,.55); font-size: 1.2rem; }
.story-view .bars { position: absolute; top: calc(8px + env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 4px; z-index: 2; }
.story-view .bars i { flex: 1; height: 3px; border-radius: 2px; background: rgba(255,255,255,.3); overflow: hidden; position: relative; }
.story-view .bars i.done { background: #fff; }
.story-view .bars i.run::after { content: ''; position: absolute; inset: 0; background: #fff; transform-origin: left; animation: fillbar 5s linear forwards; }
@keyframes fillbar { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.story-view .tap { position: absolute; top: 0; bottom: 0; width: 40%; border: 0; background: none; z-index: 1; }
.story-view .tap.prev { left: 0; }
.story-view .tap.next { right: 0; width: 60%; }
.story-view .ghost-sm { color: #fff; border-color: rgba(255,255,255,.4); margin-left: auto; }
.cam { align-content: center; }
.cam-tools { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.85) 30%); display: grid; gap: 10px; }
.cap-in { min-height: 46px; border-radius: 23px; border: 1px solid rgba(255,255,255,.3); background: rgba(0,0,0,.45); padding: 10px 16px; outline: none; font-size: 1rem; }
.cam-send { display: grid; grid-template-columns: 1.4fr 1fr .8fr; gap: 8px; }
.cam-send .btn { padding: 0 8px; font-size: .7rem; }
.cam-send .btn.ghost { background: rgba(0,0,0,.4); border-color: rgba(255,255,255,.3); }
.cam-note { margin: 0; font-size: .74rem; color: rgba(255,255,255,.65); text-align: center; }

/* The Phalanx */
.count-line { color: var(--bone-2); font-size: .85rem; margin: 0 4px 10px; }
.people { display: grid; gap: 8px; }
.person { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.av-wrap { position: relative; }
.dot { position: absolute; right: 1px; bottom: 1px; width: 13px; height: 13px; border-radius: 50%; background: #5FCB71; box-shadow: 0 0 0 3px var(--panel); }
.p-info { flex: 1; min-width: 0; display: grid; }
.p-info small { color: var(--bone-2); font-size: .8rem; }
.p-info q { font-family: var(--serif); font-style: italic; color: var(--bone); margin-top: 2px; }
.p-info .now { color: var(--bronze); }

/* Me */
.me { display: grid; gap: 16px; }
.me-av { justify-self: center; border: 0; background: none; display: grid; justify-items: center; gap: 8px; color: var(--gold); font-size: .82rem; margin-top: 6px; }
.me-rank { text-align: center; margin: -8px 0 0; font: 700 .72rem/1 var(--display); letter-spacing: .3em; text-transform: uppercase; color: var(--bronze); }
.me-form { display: grid; gap: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; }
.me-form h3 { margin: 0; font: 700 .9rem/1 var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.hint { margin: -4px 0 0; color: var(--bone-2); font-size: .85rem; }
.check { display: flex; gap: 10px; align-items: center; font-size: .92rem; }
.check input { width: 22px; height: 22px; accent-color: var(--gold); }
.invites { display: grid; gap: 6px; }
.inv { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--panel-2); }
.inv code { font: 600 .92rem/1 ui-monospace, monospace; color: var(--gold); letter-spacing: .04em; }
.inv small { flex: 1; color: var(--bone-2); font-size: .78rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv.used code { color: var(--bone-2); text-decoration: line-through; }
.out { margin-bottom: 20px; }
