:root {
	--fs: 19px;
	--bg: #efe9df;
	--surface: #fffdf9;
	--ink: #1d2a26;
	--muted: #6b7570;
	--accent: #1f7a5c;
	--accent-ink: #fff;
	--line: #e0d8ca;
	--quote: #f1ece3;
	--day: #dfe9e4;
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #0f1412;
		--surface: #1c2421;
		--ink: #e9eeeb;
		--muted: #9aa7a1;
		--accent: #4cc39a;
		--accent-ink: #0b1a14;
		--line: #2a3430;
		--quote: #26302c;
		--day: #22302a;
		color-scheme: dark;
	}
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
	font: var(--fs)/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	background: var(--bg);
	color: var(--ink);
	-webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* Login */
.login { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; text-align: center; }
.login h1 { font-size: 1.4em; margin: 16px 0 24px; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login label { font-weight: 600; }
.login input { font: inherit; font-size: 1.2em; text-align: center; padding: 14px; border: 2px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); }
.login input:focus { outline: none; border-color: var(--accent); }
.login button { padding: 14px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 1.1em; }
.error { color: #c0392b; min-height: 1.4em; margin: 0; }

/* Layout */
.app { height: 100%; display: flex; flex-direction: column; }
header { background: var(--accent); color: var(--accent-ink); padding-top: env(safe-area-inset-top); flex: none; }
.titlebar { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 16px; }
.titlebar h1 { flex: 1; font-size: 1.15em; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { background: transparent; border: 0; color: inherit; min-width: 48px; height: 48px; border-radius: 24px; font-size: 1.1em; font-weight: 700; }
.icon small { font-size: .7em; }
.icon:active { background: rgba(255, 255, 255, .15); }
nav { display: flex; }
.tab { flex: 1; background: none; border: 0; padding: 10px 4px 12px; color: inherit; opacity: .75; font-weight: 600; border-bottom: 4px solid transparent; }
.tab.active { opacity: 1; border-bottom-color: currentColor; }

.banner { background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 16px; font-size: .9em; display: flex; gap: 12px; align-items: center; }
.banner p { margin: 0; flex: 1; }
.banner button { border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 10px; padding: 8px 14px; font-weight: 600; }
.banner .close { background: transparent; color: var(--muted); padding: 8px; }

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); }
.loader { height: 1px; }
.loader.busy { height: 56px; display: flex; align-items: center; justify-content: center; }
.loader.busy::after { content: ""; width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* Feed */
.feed { max-width: 760px; margin: 0 auto; padding: 8px 12px 24px; }
.day { text-align: center; margin: 18px 0 10px; }
.day span { display: inline-block; background: var(--day); color: var(--ink); border-radius: 10px; padding: 4px 14px; font-size: .8em; font-weight: 600; }
.day span::first-letter { text-transform: uppercase; }

.msg { margin-top: 10px; max-width: 88%; }
.msg.cont { margin-top: 3px; }
.msg.cont .sender { display: none; }
.bubble { background: var(--surface); border-radius: 4px 16px 16px 16px; padding: 8px 12px 6px; box-shadow: 0 1px 1px rgba(0, 0, 0, .06); overflow-wrap: anywhere; }
.msg.cont .bubble { border-radius: 16px; }
.msg.media .bubble { padding: 4px 4px 6px; }
.msg.media .sender, .msg.media .text, .msg.media .meta { padding-left: 8px; padding-right: 8px; }
.msg.sticker .bubble { background: transparent; box-shadow: none; padding: 0; }
.sender { font-weight: 700; font-size: .85em; margin-bottom: 2px; }
.text { white-space: pre-wrap; }
.text a { color: var(--accent); }
.meta { font-size: .7em; color: var(--muted); text-align: right; margin-top: 2px; }
.deleted .text { color: var(--muted); font-style: italic; }

.quote { background: var(--quote); border-left: 4px solid var(--accent); border-radius: 8px; padding: 6px 10px; margin: 2px 0 6px; font-size: .85em; cursor: pointer; }
.msg.media .quote { margin: 4px; }
.quote b { display: block; font-size: .9em; color: var(--accent); }
.quote span { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.thumb { position: relative; display: block; width: 100%; border: 0; padding: 0; background: var(--quote); border-radius: 12px; overflow: hidden; min-height: 80px; }
.thumb img, .thumb video { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb video[controls] { object-fit: contain; background: #000; }
.thumb.pending img { filter: blur(6px); transform: scale(1.05); }
.thumb .badge { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 2.2em; text-shadow: 0 1px 6px rgba(0, 0, 0, .6); pointer-events: none; }
.thumb .note { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .55); color: #fff; font-size: .7em; padding: 2px 8px; border-radius: 8px; }
.thumb .note.top { bottom: auto; top: 8px; }
.sticker-img { width: 140px; height: 140px; object-fit: contain; display: block; }
audio { width: 100%; min-width: 240px; margin: 4px 0; display: block; }
.doc { display: flex; align-items: center; gap: 10px; background: var(--quote); border-radius: 10px; padding: 10px 12px; color: inherit; text-decoration: none; margin: 4px 0; }
.poll ul { margin: 6px 0 0; padding-left: 1.2em; }

.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: -4px 0 0 10px; position: relative; }
.reactions span { background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; font-size: .8em; }

.highlight .bubble { animation: flash 1.6s; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 4px var(--accent); } }

.new-btn { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom)); border: 0; border-radius: 99px; background: var(--accent); color: var(--accent-ink); padding: 12px 22px; font-weight: 700; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }

/* Gallery */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 3px; padding: 3px; max-width: 1000px; margin: 0 auto; }
.gallery button { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: var(--quote); overflow: hidden; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .play { position: absolute; right: 6px; bottom: 4px; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, .7); font-size: .9em; }

/* Permission question */
.ask { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.ask-card { background: var(--surface); border-radius: 22px; padding: 28px 22px 18px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); }
.ask-icon { font-size: 2.6em; }
.ask h2 { font-size: 1.3em; margin: 8px 0; }
.ask p { margin: 0 0 20px; color: var(--muted); }
.ask button { display: block; width: 100%; border: 0; border-radius: 14px; padding: 15px; font-weight: 700; margin-top: 8px; }
.ask-yes { background: var(--accent); color: var(--accent-ink); font-size: 1.05em; }
.ask-no { background: transparent; color: var(--muted); }

/* Viewer */
.viewer { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; align-items: center; justify-content: center; touch-action: pan-y; }
.viewer-stage { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.viewer-stage img, .viewer-stage video { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close, .viewer-nav { position: absolute; z-index: 1; background: rgba(0, 0, 0, .5); color: #fff; border: 0; border-radius: 50%; width: 56px; height: 56px; font-size: 26px; line-height: 1; }
.viewer-close { top: calc(12px + env(safe-area-inset-top)); right: 12px; }
.viewer-nav { top: 50%; transform: translateY(-50%); font-size: 40px; }
.viewer-nav.prev { left: 8px; }
.viewer-nav.next { right: 8px; }
.viewer-caption { position: absolute; left: 0; right: 0; bottom: 0; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .8)); padding: 28px 16px calc(14px + env(safe-area-inset-bottom)); font-size: .85em; pointer-events: none; }
.viewer-caption b { display: block; }
