:root {
  --mf-panel-w: min(20rem, 90vw);
  --mf-border: #e7e5e4;
  --mf-muted: #78716c;
  --mf-card: #fff;
}

body.mf-shell {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--mf-panel-w) 1fr var(--mf-panel-w);
  font-family: system-ui, sans-serif;
  line-height: 1.55;
  color: #1c1917;
  background: #fafaf9;
  transition: grid-template-columns 0.2s ease;
}

body.mf-shell.mf-no-left { grid-template-columns: 0 1fr var(--mf-panel-w); }
body.mf-shell.mf-no-right { grid-template-columns: var(--mf-panel-w) 1fr 0; }
body.mf-shell.mf-no-left.mf-no-right { grid-template-columns: 0 1fr 0; }

.mf-panel {
  background: var(--mf-card);
  border: solid var(--mf-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 100vh;
  position: sticky;
  top: 0;
}
.mf-panel-left { border-width: 0 1px 0 0; }
.mf-panel-right { border-width: 0 0 0 1px; }
body.mf-no-left .mf-panel-left,
body.mf-no-right .mf-panel-right {
  width: 0; padding: 0; border: none; opacity: 0; pointer-events: none;
}

.mf-panel-head {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--mf-border);
  display: flex; align-items: center; gap: 0.5rem;
}
.mf-panel-head h2 { font-size: 0.9rem; margin: 0; flex: 1; font-weight: 600; }
.mf-panel-close { border: none; background: none; cursor: pointer; color: var(--mf-muted); font-size: 1.2rem; }
.mf-panel-search {
  margin: 0.45rem 0.75rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--mf-border);
  border-radius: 8px;
  font: inherit;
  width: calc(100% - 1.5rem);
}
.mf-panel-body { overflow-y: auto; padding: 0.4rem 0.75rem 1.25rem; flex: 1; }

.mf-dict-item, .mf-formula-item {
  padding: 0.55rem 0;
  border-bottom: 1px solid #f5f5f4;
  cursor: pointer;
  font-size: 0.85rem;
}
.mf-dict-item:hover, .mf-formula-item:hover { background: #fafaf9; }
.mf-dict-item.active, .mf-formula-item.active { background: #fffbeb; border-radius: 6px; }
.mf-dict-item .lbl, .mf-formula-item .lbl { font-weight: 600; }
.mf-dict-item .meta, .mf-formula-item .meta { font-size: 0.68rem; color: var(--mf-muted); }
.mf-dict-item .def, .mf-formula-item .note { color: #57534e; margin-top: 0.2rem; font-size: 0.8rem; }
.mf-formula-item .expr-latex { background: #f5f5f4; padding: 0.35rem; border-radius: 6px; margin: 0.25rem 0; overflow-x: auto; }

.mf-detail-box {
  margin: 0 0.75rem 0.5rem;
  padding: 0.65rem;
  background: #fffbeb;
  border-radius: 8px;
  font-size: 0.85rem;
  display: none;
  max-height: 40vh;
  overflow-y: auto;
}
.mf-detail-box.show { display: block; }
.mf-detail-box p { margin: 0.4rem 0; }
.mf-dict-formula { background: #fff; border: 1px solid var(--mf-border); border-radius: 6px; padding: 0.45rem; margin: 0.5rem 0; }
.mf-dict-formula .cap { font-size: 0.72rem; color: var(--mf-muted); }

.mf-main {
  min-width: 0;
  padding: 1.25rem 1rem 2.5rem;
  max-width: 48rem;
  margin: 0 auto;
  width: 100%;
}
body.mf-files .mf-main { max-width: none; padding: 0.75rem; display: flex; flex-direction: column; height: 100vh; box-sizing: border-box; }

.mf-header-chips {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  margin: 0.35rem 0 1rem;
}
.mf-chip {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.28rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--mf-border);
  background: #fff;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
}
.mf-chip:hover { border-color: #a8a29e; background: #fafaf9; }
.mf-chip-link { display: inline-block; }

.mf-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.28);
  z-index: 30;
}

.mf-files-top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  margin-bottom: 0.5rem; flex-shrink: 0;
}
.mf-files-top h1 { font-size: 1.15rem; margin: 0; flex: 1; }
.mf-files-top .back { font-size: 0.82rem; width: 100%; }
.mf-files-top .back a { color: var(--mf-muted); }
.mf-files-layout {
  display: grid;
  grid-template-columns: min(14rem, 32vw) 1fr;
  gap: 0.65rem;
  flex: 1;
  min-height: 0;
}
.mf-file-nav {
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--mf-border);
  border-radius: 10px;
  padding: 0.5rem 0;
  font-size: 0.82rem;
}
.mf-file-nav h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mf-muted);
  margin: 0.75rem 0.35rem 0.35rem;
  padding: 0 0.5rem;
}
.mf-file-nav button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  font: inherit;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  color: #44403c;
}
.mf-file-nav button:hover { background: #fafaf9; }
.mf-file-nav button.active { background: #1c1917; color: #fff; }
.mf-pdf-wrap {
  background: #fff;
  border: 1px solid var(--mf-border);
  border-radius: 10px;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.mf-pdf-toolbar {
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--mf-border);
  font-size: 0.8rem;
  color: var(--mf-muted);
  display: flex; gap: 0.5rem; align-items: center; flex-shrink: 0;
}
.mf-pdf-toolbar a { color: #1c1917; font-size: 0.78rem; }
.mf-pdf-frame {
  flex: 1;
  width: 100%;
  border: none;
  min-height: 60vh;
  background: #f5f5f4;
}
.mf-dl-zip {
  display: inline-block;
  padding: 0.35rem 0.85rem;
  background: #1c1917;
  color: #fff;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.8rem;
}

.mf-formula-block {
  background: #fff;
  border: 1px solid var(--mf-border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
}
.mf-formula-block .expr { margin: 0.5rem 0; overflow-x: auto; }
.mf-formula-block .explain { font-size: 0.92rem; color: #44403c; margin: 0.5rem 0 0; }

@media (max-width: 900px) {
  body.mf-shell { grid-template-columns: 1fr !important; }
  .mf-panel {
    position: fixed; z-index: 40;
    top: 0; bottom: 0; width: var(--mf-panel-w);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
    transform: translateX(-110%);
    transition: transform 0.2s ease;
  }
  .mf-panel-right { right: 0; left: auto; transform: translateX(110%); }
  body.mf-show-left .mf-panel-left { transform: translateX(0); }
  body.mf-show-right .mf-panel-right { transform: translateX(0); }
  body.mf-show-left .mf-backdrop, body.mf-show-right .mf-backdrop { display: block; }
  .mf-files-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .mf-file-nav { max-height: 28vh; }
  body.mf-files .mf-main { height: auto; min-height: 100vh; }
}

@media (min-width: 901px) {
  .mf-backdrop { display: none !important; }
}
