:root {
  color-scheme: light dark;
  --bg: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #f7f8f5;
  --text: #242722;
  --muted: #7d827a;
  --border: #e6e8e2;
  --accent: #5e9277;
  --accent-soft: #e6f0ea;
  --danger: #c75c59;
  --highlight: #eee2bf;
  --shadow: 0 12px 34px rgba(28, 38, 31, 0.09);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171917;
    --surface: #222522;
    --surface-2: #292c29;
    --text: #e7eae5;
    --muted: #9ca39a;
    --border: #343934;
    --accent: #83b99a;
    --accent-soft: #263e31;
    --danger: #ec8580;
    --highlight: #665c39;
    --shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: transparent; }
button:active { transform: scale(.97); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.qmf-icon { width: 20px; height: 20px; display: block; flex: 0 0 auto; }

.qmf-boot, .qmf-mobile-gate { min-height: 100dvh; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 32px; text-align: center; color: var(--muted); }
.qmf-mobile-gate .qmf-icon { width: 42px; height: 42px; color: var(--accent); }
.qmf-mobile-gate h1 { margin: 8px 0 0; color: var(--text); font-size: 24px; }
.qmf-mobile-gate p { margin: 0; max-width: 360px; line-height: 1.6; }

.qmf-mobile-login { min-height: 100dvh; display: grid; place-items: center; padding: calc(28px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom)); }
.qmf-login-card { display: grid; width: min(100%, 420px); gap: 16px; padding: 28px 22px; border: 1px solid var(--border); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.qmf-login-logo { display: grid; place-items: center; width: 52px; height: 52px; margin: 0 auto 2px; border-radius: 17px; background: var(--accent-soft); color: var(--accent); }
.qmf-login-logo .qmf-icon { width: 27px; height: 27px; }
.qmf-login-card h1 { margin: 0; text-align: center; font-size: 24px; }
.qmf-login-card > p { margin: -8px 0 2px; text-align: center; color: var(--muted); font-size: 13px; }
.qmf-login-card label { display: grid; gap: 7px; }
.qmf-login-card label span { color: var(--muted); font-size: 13px; }
.qmf-login-card input, .qmf-login-card select { width: 100%; min-height: 48px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.qmf-login-submit { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; border-radius: 13px; background: var(--accent); color: #fff; font-weight: 650; }
.qmf-login-submit:disabled { opacity: .7; }
.qmf-login-submit .qmf-spinner { width: 20px; height: 20px; border-color: rgba(255,255,255,.38); border-top-color: #fff; }
.qmf-login-error { padding: 9px 11px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 13px; line-height: 1.45; }
.qmf-login-card > small { color: var(--muted); text-align: center; line-height: 1.5; }

.qmf-mobile-app { width: 100%; min-width: 0; min-height: 100dvh; overflow-x: clip; padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.qmf-mobile-header { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); }
.qmf-mobile-brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.qmf-mobile-brand > span { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px; color: #fff; background: var(--accent); }
.qmf-mobile-brand div { display: flex; min-width: 0; flex-direction: column; }
.qmf-mobile-brand strong { font-size: 16px; }
.qmf-mobile-brand small { max-width: 220px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.qmf-mobile-header-actions { display: flex; flex: 0 0 auto; }
.qmf-icon-button, .qmf-mobile-card-actions button, .qmf-sheet-header > button, .qmf-sheet-tree-row > button:first-child { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; }

.qmf-offline-banner { position: sticky; top: calc(58px + env(safe-area-inset-top)); z-index: 29; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; background: #8d5844; color: #fff; font-size: 13px; }
.qmf-offline-banner .qmf-icon { width: 16px; height: 16px; }

.qmf-mobile-controls { padding: 14px 14px 8px; }
.qmf-mobile-search, .qmf-sheet-search { display: flex; align-items: center; gap: 9px; min-height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.qmf-mobile-search > .qmf-icon, .qmf-sheet-search > .qmf-icon { color: var(--muted); }
.qmf-mobile-search input, .qmf-sheet-search input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; }
.qmf-search-clear { display: grid; place-items: center; width: 36px; height: 36px; color: var(--muted); }
.qmf-search-clear .qmf-icon { width: 17px; height: 17px; }
.qmf-mobile-filter-row { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr) minmax(0, .8fr); gap: 8px; margin-top: 10px; }
.qmf-mobile-filter-row > button { display: flex; min-width: 0; align-items: center; justify-content: center; gap: 6px; height: 42px; padding: 0 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted); }
.qmf-mobile-filter-row > button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmf-mobile-filter-row > button.is-active { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); background: var(--accent-soft); color: var(--accent); }
.qmf-mobile-filter-row .qmf-icon { width: 17px; height: 17px; }
.qmf-mobile-result-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px 2px; color: var(--muted); font-size: 13px; }
.qmf-mobile-result-line small { max-width: 68%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.qmf-mobile-stream { display: grid; grid-template-columns: minmax(0, 1fr); min-width: 0; gap: 10px; padding: 6px 12px 24px; }
.qmf-mobile-card { position: relative; min-width: 0; max-width: 100%; overflow: clip; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 2px 10px rgba(30, 38, 32, .025); }
.qmf-mobile-card-header { position: relative; z-index: 4; display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title actions" "meta actions"; align-items: center; min-height: 62px; padding: 10px 10px 8px 15px; background: var(--surface); }
.qmf-mobile-card.is-expanded .qmf-mobile-card-header { position: sticky; top: calc(58px + env(safe-area-inset-top)); box-shadow: 0 1px 0 var(--border), 0 8px 14px color-mix(in srgb, var(--surface) 85%, transparent); }
.qmf-mobile-card-title { grid-area: title; min-width: 0; padding: 0; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 650; }
.qmf-mobile-card-meta { grid-area: meta; display: flex; min-width: 0; align-items: center; gap: 5px; margin-top: 3px; color: var(--muted); font-size: 11px; }
.qmf-mobile-card-meta button { min-width: 0; padding: 0; overflow: hidden; color: inherit; text-overflow: ellipsis; white-space: nowrap; }
.qmf-mobile-card-actions { grid-area: actions; display: flex; }
.qmf-mobile-card-actions button { width: 40px; height: 40px; color: var(--muted); }
.qmf-mobile-card-actions button.is-danger, .qmf-tag-tool.is-danger { color: var(--danger); }
.qmf-mobile-card-actions .qmf-icon { width: 18px; height: 18px; }
.qmf-mobile-card-body { position: relative; padding: 5px 15px 4px; line-height: 1.72; overflow-wrap: anywhere; }
.qmf-mobile-card-body.is-collapsed { max-height: 250px; overflow: hidden; }
.qmf-mobile-card-body.is-collapsed::after { content: ""; position: absolute; inset: auto 0 0; height: 54px; background: linear-gradient(transparent, var(--surface)); pointer-events: none; }
.qmf-mobile-card-expand { position: sticky; z-index: 5; bottom: 10px; display: grid; place-items: center; width: 38px; height: 34px; margin: 4px auto 7px; border: 1px solid var(--border); border-radius: 18px; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: var(--shadow); color: var(--muted); backdrop-filter: blur(12px); }
.qmf-mobile-card-expand[hidden] { display: none; }
.qmf-mobile-card-footer { padding: 4px 13px 12px; }
.qmf-mobile-card-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.qmf-mobile-tag-chip { display: inline-flex; align-items: center; min-height: 30px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.qmf-mobile-tag-chip > button:first-child { max-width: 170px; padding: 6px 8px 6px 10px; overflow: hidden; color: var(--accent); text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.qmf-tag-tool, .qmf-tag-add { display: grid; place-items: center; width: 32px; height: 30px; color: var(--muted); }
.qmf-tag-tool .qmf-icon, .qmf-tag-add .qmf-icon { width: 14px; height: 14px; }
.qmf-tag-add { border: 1px dashed var(--border); border-radius: 10px; }
mark { padding: 0 .08em; border-radius: 2px; background: var(--highlight); color: inherit; }

.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: .55em 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3 { margin: 1em 0 .45em; line-height: 1.3; }
.markdown-body h1 { font-size: 1.35em; }
.markdown-body h2 { font-size: 1.2em; }
.markdown-body h3 { font-size: 1.08em; }
.markdown-body img { display: block; max-width: 100%; height: auto; margin: 10px 0; border-radius: 12px; }
.markdown-body a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown-body pre { overflow: auto; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.markdown-body code { padding: .12em .3em; border-radius: 4px; background: var(--surface-2); }
.markdown-body pre code { padding: 0; }
.markdown-body blockquote { margin: .8em 0; padding-left: 12px; border-left: 3px solid var(--accent); color: var(--muted); }
.markdown-body table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown-body th, .markdown-body td { padding: 6px 9px; border: 1px solid var(--border); }

.qmf-mobile-empty { display: grid; min-height: 42vh; place-content: center; justify-items: center; gap: 10px; padding: 30px; text-align: center; color: var(--muted); }
.qmf-mobile-empty > .qmf-icon { width: 36px; height: 36px; }
.qmf-mobile-empty strong { color: var(--text); }
.qmf-mobile-empty p { margin: 0; line-height: 1.55; }
.qmf-spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.qmf-mobile-load-more { min-height: 46px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--muted); }
.qmf-mobile-fab { position: fixed; z-index: 31; right: 18px; bottom: calc(20px + env(safe-area-inset-bottom)); display: grid; place-items: center; width: 58px; height: 58px; border-radius: 20px; background: var(--accent); color: #fff; box-shadow: 0 12px 28px color-mix(in srgb, var(--accent) 45%, transparent); }
.qmf-mobile-fab .qmf-icon { width: 26px; height: 26px; }

.qmf-sheet-backdrop, .qmf-dialog-backdrop { position: fixed; z-index: 60; inset: 0; background: rgba(12, 16, 13, .42); backdrop-filter: blur(2px); }
.qmf-bottom-sheet { position: fixed; z-index: 61; inset: auto 0 0; display: flex; max-height: min(82dvh, 760px); flex-direction: column; padding: 0 14px calc(14px + env(safe-area-inset-bottom)); border-radius: 24px 24px 0 0; background: var(--surface); box-shadow: 0 -18px 50px rgba(0, 0, 0, .16); animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { transform: translateY(12%); opacity: .5; } }
.qmf-sheet-handle { width: 38px; height: 4px; margin: 8px auto 5px; border-radius: 4px; background: var(--border); }
.qmf-sheet-header { display: flex; align-items: center; gap: 4px; min-height: 54px; }
.qmf-sheet-header > div { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.qmf-sheet-header strong { font-size: 18px; }
.qmf-sheet-header small { color: var(--muted); }
.qmf-sheet-header .qmf-text-button { width: auto; padding: 0 8px; color: var(--accent); font-size: 13px; }
.qmf-sheet-search { margin: 5px 0 10px; background: var(--surface-2); }
.qmf-sheet-list { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 12px; }
.qmf-sheet-tree-row { display: flex; align-items: center; padding-left: calc(var(--depth) * 14px); }
.qmf-sheet-tree-row > button:first-child, .qmf-tree-spacer { width: 36px; height: 42px; flex: 0 0 36px; }
.qmf-sheet-tree-row > button:first-child .qmf-icon { width: 16px; height: 16px; }
.qmf-sheet-option, .qmf-sheet-all { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 5px 10px; border-radius: 11px; text-align: left; }
.qmf-sheet-option span, .qmf-sheet-all span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmf-sheet-option small, .qmf-sheet-all small { color: var(--muted); }
.qmf-sheet-option.is-active, .qmf-sheet-all.is-active { background: var(--accent-soft); color: var(--accent); }
.qmf-sheet-empty { padding: 28px; text-align: center; color: var(--muted); }

.qmf-filter-form { overflow-y: auto; padding: 4px 2px 16px; }
.qmf-filter-form > label, .qmf-filter-section { display: grid; gap: 8px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.qmf-filter-form label > span, .qmf-filter-section > span { color: var(--muted); font-size: 13px; }
.qmf-filter-form select, .qmf-filter-form input, .qmf-tag-dialog input { width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); }
.qmf-date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.qmf-date-row label { display: grid; gap: 6px; }
.qmf-filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.qmf-filter-chip { display: inline-flex; align-items: center; gap: 3px; padding: 5px 5px 5px 9px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.qmf-filter-chip button { display: grid; place-items: center; width: 24px; height: 22px; color: inherit; }
.qmf-filter-chip .qmf-icon { width: 13px; height: 13px; }
.qmf-filter-tag-entry { display: grid; grid-template-columns: 1fr 44px; gap: 7px; }
.qmf-filter-tag-entry button { display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.qmf-filter-choices { display: flex; flex-wrap: wrap; gap: 8px; }
.qmf-filter-choices button { display: flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 11px; border: 1px solid var(--border); border-radius: 11px; }
.qmf-filter-choices button.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.qmf-filter-choices .qmf-icon { width: 17px; height: 17px; }

.qmf-full-dialog { position: fixed; z-index: 71; inset: 0; display: flex; flex-direction: column; background: var(--surface); animation: dialog-in .18s ease-out; }
@keyframes dialog-in { from { transform: translateY(2%); opacity: .75; } }
.qmf-full-dialog > header { display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; align-items: center; height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 8px 0; border-bottom: 1px solid var(--border); }
.qmf-full-dialog > header > button { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 44px; height: 44px; border-radius: 12px; }
.qmf-full-dialog > header > strong { overflow: hidden; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.qmf-dialog-save { padding: 0 10px; color: var(--accent); }
.qmf-dialog-save .qmf-icon { width: 18px; height: 18px; }
.qmf-dialog-content { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.qmf-compose-title { width: 100%; padding: 8px 0 12px; border: 0; border-bottom: 1px solid var(--border); outline: 0; background: transparent; font-size: 20px; font-weight: 650; }
.qmf-compose-body { width: 100%; min-height: 44dvh; padding: 16px 0; resize: vertical; border: 0; outline: 0; background: transparent; line-height: 1.65; }
.qmf-dialog-hint { color: var(--muted); font-size: 12px; }
.qmf-compose-tools { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; padding-top: 12px; border-top: 1px solid var(--border); }
.qmf-image-picker { display: flex; align-items: center; gap: 6px; height: 42px; padding: 0 11px; border: 1px solid var(--border); border-radius: 11px; color: var(--muted); }
.qmf-image-picker input { display: none; }
.qmf-compose-tag-entry { display: grid; grid-template-columns: 1fr 42px; }
.qmf-compose-tag-entry input { min-width: 0; height: 42px; padding: 0 10px; border: 1px solid var(--border); border-radius: 11px 0 0 11px; background: var(--surface-2); }
.qmf-compose-tag-entry button { display: grid; place-items: center; border-radius: 0 11px 11px 0; background: var(--accent-soft); color: var(--accent); }
.qmf-compose-selected-tags, .qmf-compose-images { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.qmf-compose-selected-tags > span, .qmf-compose-images > span { display: inline-flex; min-width: 0; align-items: center; gap: 5px; min-height: 32px; padding: 3px 4px 3px 9px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.qmf-compose-images > span > span { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmf-compose-selected-tags button, .qmf-compose-images button { display: grid; place-items: center; width: 28px; height: 26px; }
.qmf-compose-selected-tags .qmf-icon, .qmf-compose-images .qmf-icon { width: 14px; height: 14px; }

.qmf-tag-dialog { position: fixed; z-index: 72; left: 16px; right: 16px; top: 50%; display: grid; gap: 14px; padding: 20px; transform: translateY(-50%); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.qmf-tag-dialog > div { display: flex; justify-content: flex-end; gap: 8px; }
.qmf-tag-dialog > div button { min-width: 74px; min-height: 40px; border-radius: 10px; background: var(--surface-2); }
.qmf-tag-dialog > div button.is-primary { background: var(--accent); color: #fff; }

.qmf-preview-dialog .qmf-dialog-content { padding-top: 12px; }
.qmf-preview-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; color: var(--muted); font-size: 12px; }
.qmf-preview-dialog .markdown-body { font-size: 16px; line-height: 1.75; }
.qmf-preview-tags { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }
.qmf-preview-tags span { padding: 5px 9px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }

.qmf-mobile-toast { position: fixed; z-index: 90; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); display: flex; max-width: calc(100vw - 30px); align-items: center; gap: 14px; padding: 11px 12px 11px 16px; transform: translateX(-50%); border-radius: 13px; background: #262b27; color: #fff; box-shadow: var(--shadow); font-size: 13px; white-space: nowrap; }
.qmf-mobile-toast span { overflow: hidden; text-overflow: ellipsis; }
.qmf-mobile-toast button { min-height: 32px; padding: 0 9px; border-radius: 8px; background: rgba(255,255,255,.14); color: #fff; }

@media (min-width: 720px) {
  .qmf-mobile-app { max-width: 720px; margin: 0 auto; }
  .qmf-bottom-sheet { left: 50%; width: 680px; transform: translateX(-50%); border-radius: 24px 24px 0 0; }
  .qmf-full-dialog { left: 50%; width: 720px; transform: translateX(-50%); box-shadow: var(--shadow); }
  .qmf-mobile-card.is-expanded .qmf-mobile-card-header { top: calc(58px + env(safe-area-inset-top)); }
}
