/* Default skin — the reference implementation every other skin is copied from.
 *
 * TOKENS LIVE IN THE CORE, NOT HERE.
 * static/core/tokens.css defines every --mg-* default and the shell loads it
 * before this file (docs/DECISIONS.md D9-1). This stylesheet only consumes
 * them. Redefine a token in a :root block here to override a core default —
 * do not restate the whole set, or the fallback layer stops being observable.
 *
 * NO HARDCODED COLORS OR SIZES (CLAUDE.md 코드 스타일). Everything below reads
 * --mg-*. A literal value here would be invisible to the theme editor and to
 * every skin that inherits this file's structure.
 *
 * SECTIONS
 *   1. base elements
 *   2. shell — layout shared by all four header placements
 *   3. shell — per-placement rules (top / bottom / left / right)
 *   4. content typography
 *   5. components
 *   6. forms
 *   7. block engine
 *   8. boards
 *   9. characters
 *  10. manage
 *  11. narrow viewports
 */

/* ------------------------------------------------------------------ *
 * 1. base elements
 * ------------------------------------------------------------------ */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--mg-bg);
  background-image: var(--mg-bg-image);
  background-repeat: var(--mg-bg-repeat);
  background-position: var(--mg-bg-position);
  background-size: var(--mg-bg-size);
  background-attachment: var(--mg-bg-attachment);
  color: var(--mg-text);
  font-family: var(--mg-font-body);
  font-size: var(--mg-font-size-base);
  line-height: var(--mg-line-height);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--mg-font-heading);
  font-weight: 400;
  line-height: 1.3;
  margin: 0 0 var(--mg-space-3);
}

h1 { font-size: var(--mg-font-size-xl); }
h2 { font-size: var(--mg-font-size-lg); }
h3 { font-size: var(--mg-font-size-md); }

a {
  color: var(--mg-link);
  text-decoration: none;
}

a:hover {
  color: var(--mg-link-hover);
  text-decoration: underline;
}

img {
  max-width: 100%;
}

hr {
  border: 0;
  border-top: var(--mg-border-width) solid var(--mg-border);
  margin: var(--mg-space-5) 0;
}

/* ------------------------------------------------------------------ *
 * 2. shell — shared by all four header placements
 *
 * The shell DOM is core-owned and never re-rendered by hx-boost
 * (CLAUDE.md 금지 8·9). Placement is switched with a <body> class alone, so
 * the markup is identical in all four modes.
 * ------------------------------------------------------------------ */

.mg-shell {
  display: grid;
  min-height: 100vh;
}

.mg-shell-header {
  grid-area: header;
  background: var(--mg-surface);
  display: flex;
  align-items: center;
  gap: var(--mg-space-5);
  padding: var(--mg-space-3) var(--mg-space-5);
}

.mg-shell-brand {
  font-family: var(--mg-font-heading);
  font-size: var(--mg-font-size-lg);
  color: var(--mg-accent);
  text-decoration: none;
  white-space: nowrap;
}

.mg-shell-brand:hover {
  color: var(--mg-accent-hover);
  text-decoration: none;
}

.mg-shell-nav-toggle {
  display: none;
  background: transparent;
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-pill);
  color: var(--mg-text);
  font: inherit;
  padding: var(--mg-space-1) var(--mg-space-3);
  cursor: pointer;
}

.mg-shell-nav {
  display: flex;
  align-items: center;
  gap: var(--mg-space-2);
  flex: 1;
  justify-content: flex-end;
}

.mg-shell-nav-item {
  position: relative;
}

.mg-shell-nav a,
.mg-shell-nav span,
.mg-shell-account a {
  display: block;
  color: var(--mg-text);
  font-size: var(--mg-font-size-sm);
  font-weight: 500;
  text-decoration: none;
  padding: var(--mg-space-2) var(--mg-space-3);
  border-radius: var(--mg-radius-pill);
  white-space: nowrap;
  transition: background var(--mg-transition-fast), color var(--mg-transition-fast);
}

.mg-shell-nav a:hover,
.mg-shell-account a:hover {
  color: var(--mg-accent);
  background: var(--mg-accent-soft);
  text-decoration: none;
}

/* Active menu item. Hover darkens, so the current page is marked with the
   soft tint instead — otherwise "active" and "hovered" look identical. */
.mg-shell-nav [aria-current="page"] {
  color: var(--mg-accent);
  background: var(--mg-accent-soft);
  text-decoration: none;
}

.mg-shell-subnav {
  display: none;
  background: var(--mg-surface);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-sm);
  box-shadow: var(--mg-shadow-lift);
  padding: var(--mg-space-1);
  min-width: 100%;
}

.mg-shell-nav-item:hover > .mg-shell-subnav,
.mg-shell-nav-item:focus-within > .mg-shell-subnav {
  display: block;
  position: absolute;
  inset-inline-start: 0;
  z-index: 1;
}

.mg-shell-account {
  display: flex;
  gap: var(--mg-space-1);
}

#mango-player-root:empty {
  display: none;
}

.mg-shell-scrim {
  display: none;
}

/* Back-to-top. Present in the DOM in all four placements, revealed by the
   runtime body.mg-scrolled class. */
.mg-shell-totop {
  display: none;
  position: fixed;
  inset-inline-end: var(--mg-space-5);
  bottom: var(--mg-space-5);
  z-index: 2;
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface);
  color: var(--mg-text);
  box-shadow: var(--mg-shadow-lift);
  padding: var(--mg-space-2) var(--mg-space-4);
  cursor: pointer;
  font-size: inherit;
  transition: transform var(--mg-transition-fast);
}

.mg-shell-totop:active {
  transform: scale(0.96);
}

body.mg-scrolled .mg-shell-totop {
  display: block;
}

.mg-shell-error {
  position: fixed;
  inset-inline: var(--mg-space-5);
  bottom: var(--mg-space-5);
  z-index: 5;
  border: var(--mg-border-width) solid var(--mg-danger);
  border-radius: var(--mg-radius-sm);
  background: var(--mg-danger-soft);
  color: var(--mg-text);
  box-shadow: var(--mg-shadow-lift);
  padding: var(--mg-space-3) var(--mg-space-4);
  text-align: center;
}

.mg-shell-error[hidden] {
  display: none;
}

/* The sidebar is a shell node, so it cannot live inside #content: hx-boost
   replaces that element on every navigation. This wrapper owns the box
   #content used to own, keeping the header gutter aligned without sidebar-
   aware variants. With the sidebar off, #content gets the old box back. */
.mg-shell-main {
  grid-area: content;
  display: flex;
  gap: var(--mg-space-5);
  width: 100%;
  max-width: var(--mg-content-width);
  margin: 0 auto;
  padding: var(--mg-space-6) var(--mg-space-5);
}

#content {
  flex: 1 1 auto;
  min-width: 0;
}

/* Hidden is the base state so an unknown or missing sidebar mode fails closed. */
.mg-shell-sidebar {
  display: none;
  flex: 0 0 var(--mg-shell-sidebar-width);
  min-width: 0;
  flex-direction: column;
  gap: var(--mg-space-5);
}

body.mg-sidebar-left .mg-shell-sidebar,
body.mg-sidebar-right .mg-shell-sidebar {
  display: flex;
}

/* DOM order remains content first. The left placement reverses only the visual
   row, so tab order still follows the reading order and needs no narrow-screen
   reorder. */
body.mg-sidebar-left .mg-shell-main {
  flex-direction: row-reverse;
}

/* The render tag must be flush with the aside tags or whitespace prevents
   :empty from releasing this otherwise empty column. */
body.mg-sidebar-left .mg-shell-sidebar:empty,
body.mg-sidebar-right .mg-shell-sidebar:empty {
  display: none;
}

/* Management screens keep the node but opt out with CSS so shell markup never
   branches. The switch has to live inside #content: hx-boost swaps that element
   and nothing else, so a <body> class set by the server goes stale the moment a
   boosted link crosses into or out of /manage/ - the sidebar stayed visible on
   manage screens and then stayed hidden after leaving them. Keying off the
   manage wrapper follows the swap for free, and the #content in :has() outranks
   the placement rules, so this no longer depends on file order either. */
.mg-shell-main:has(#content .mg-manage) .mg-shell-sidebar {
  display: none;
}

/* The sidebar remains narrow at every viewport, so its columns bridge to one
   track without a media query. */
.mg-shell-sidebar .mg-block-columns {
  grid-template-columns: 1fr;
}

/* Measured article-column widths at each boundary (960px content width,
   18rem sidebar, 24px gap, 24px gutters):

     header top/bottom   @64rem -> 600px
     header left/right   @64rem -> 408px    the 16rem vertical nav is a column
     header left/right   @75rem -> 584px    outside .mg-shell-main

   A container query would express this once, but container-type implies
   contain: layout and would make .mg-shell-main a containing block for fixed
   descendants. The gallery lightbox inside #content must cover the viewport,
   so the two media queries stay separate. */
@media (max-width: 75rem) {
  body.mg-header-left .mg-shell-main,
  body.mg-header-right .mg-shell-main {
    flex-direction: column;
  }

  body.mg-header-left .mg-shell-sidebar,
  body.mg-header-right .mg-shell-sidebar {
    flex: 0 0 auto;
  }
}

@media (max-width: 64rem) {
  body.mg-sidebar-left .mg-shell-main,
  body.mg-sidebar-right .mg-shell-main {
    flex-direction: column;
  }

  body.mg-sidebar-left .mg-shell-sidebar,
  body.mg-sidebar-right .mg-shell-sidebar {
    flex: 0 0 auto;
  }
}

/* ------------------------------------------------------------------ *
 * 3. shell — per-placement rules
 *
 * Each placement is self-contained below. A distributed skin that supports
 * only some placements can drop the blocks it does not want and keep the
 * rest; nothing outside this section reads the placement class except the
 * two dock offsets noted inline.
 * ------------------------------------------------------------------ */

/* --- top ---------------------------------------------------------- */

body.mg-header-top .mg-shell {
  grid-template-areas: "header" "content";
  grid-template-rows: auto 1fr;
}

/* The header is full-bleed but its contents line up with .mg-shell-main. There is no
   inner wrapper element in the shell markup, so the gutter is computed instead
   of nested. */
body.mg-header-top .mg-shell-header,
body.mg-header-bottom .mg-shell-header {
  border-bottom: var(--mg-border-width) solid var(--mg-border);
  padding-inline: max(
    var(--mg-space-5),
    calc((100% - var(--mg-content-width)) / 2)
  );
}

/* Only meaningful for the top placement: left/right are already sticky and
   bottom is a fixed dock. */
body.mg-headerfix-on.mg-header-top .mg-shell-header {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* --- bottom ------------------------------------------------------- */

body.mg-header-bottom .mg-shell {
  grid-template-areas: "content" "header";
  grid-template-rows: 1fr auto;
  padding-block-end: var(--mg-shell-dock-height);
}

body.mg-header-bottom .mg-shell-header {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  height: var(--mg-shell-dock-height);
  z-index: 2;
  border-bottom: 0;
  border-top: var(--mg-border-width) solid var(--mg-border);
}

body.mg-header-bottom .mg-shell-subnav {
  bottom: 100%;
}

/* Floating elements clear the dock. */
body.mg-header-bottom .mg-shell-totop,
body.mg-header-bottom .mg-shell-error {
  bottom: calc(var(--mg-shell-dock-height) + var(--mg-space-5));
}

/* --- left / right ------------------------------------------------- */

body.mg-header-left .mg-shell {
  grid-template-areas: "header content";
  grid-template-columns: var(--mg-shell-nav-width) 1fr;
}

body.mg-header-right .mg-shell {
  grid-template-areas: "content header";
  grid-template-columns: 1fr var(--mg-shell-nav-width);
}

/* Pin the vertical sidebar to the viewport. As a grid item its default
   align-self: stretch makes the column as tall as the content, so on a long
   page the bottom of the menu can only be reached by scrolling. align-self
   must drop to start for sticky to have room to move. */
body.mg-header-left .mg-shell-header,
body.mg-header-right .mg-shell-header {
  flex-direction: column;
  align-items: stretch;
  gap: var(--mg-space-2);
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  padding: var(--mg-space-5) var(--mg-space-4);
}

body.mg-header-left .mg-shell-header {
  border-inline-end: var(--mg-border-width) solid var(--mg-border);
}

body.mg-header-right .mg-shell-header {
  border-inline-start: var(--mg-border-width) solid var(--mg-border);
}

body.mg-header-left .mg-shell-nav,
body.mg-header-right .mg-shell-nav {
  align-items: stretch;
  flex-direction: column;
  justify-content: flex-start;
}

body.mg-header-left .mg-shell-account,
body.mg-header-right .mg-shell-account {
  flex-direction: column;
}

body.mg-header-left .mg-shell-subnav,
body.mg-header-right .mg-shell-subnav {
  border: 0;
  box-shadow: none;
  background: transparent;
  margin-inline-start: var(--mg-space-3);
  padding: 0;
}

/* Vertical placements expand submenus in place instead of flying out. The
   base hover rule sets position: absolute; it has to be undone here or the
   open list floats and covers the next menu item.

   A flyout is not an option: the sidebar is viewport-height with
   overflow-y: auto, so anything escaping its box gets clipped. */
body.mg-header-left .mg-shell-nav-item:hover > .mg-shell-subnav,
body.mg-header-left .mg-shell-nav-item:focus-within > .mg-shell-subnav,
body.mg-header-right .mg-shell-nav-item:hover > .mg-shell-subnav,
body.mg-header-right .mg-shell-nav-item:focus-within > .mg-shell-subnav {
  position: static;
}

/* ------------------------------------------------------------------ *
 * 4. content typography
 * ------------------------------------------------------------------ */

#content > h1:first-child {
  margin-bottom: var(--mg-space-5);
}

#content p {
  margin: 0 0 var(--mg-space-4);
}

#content ul,
#content ol {
  padding-inline-start: var(--mg-space-5);
}

#content dl {
  display: grid;
  grid-template-columns: minmax(6rem, max-content) 1fr;
  gap: var(--mg-space-2) var(--mg-space-5);
  margin: 0 0 var(--mg-space-5);
  padding: var(--mg-space-4) var(--mg-space-5);
  background: var(--mg-surface-tint);
  border-radius: var(--mg-radius);
}

#content dt {
  font-weight: 700;
  font-size: var(--mg-font-size-sm);
  color: var(--mg-text-muted);
}

#content dd {
  margin: 0;
}

.mg-muted {
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-sm);
}

/* ------------------------------------------------------------------ *
 * 5. components
 * ------------------------------------------------------------------ */

.mg-card {
  background: var(--mg-surface);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  box-shadow: var(--mg-shadow);
  padding: var(--mg-space-5);
  margin-bottom: var(--mg-space-4);
}

.mg-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--mg-space-1);
  padding: var(--mg-space-2) var(--mg-space-5);
  border-radius: var(--mg-radius-pill);
  border: var(--mg-border-width) solid var(--mg-accent);
  cursor: pointer;
  text-decoration: none;
  font-family: var(--mg-font-body);
  font-weight: 700;
  font-size: var(--mg-font-size-sm);
  line-height: 1.6;
  transition: transform var(--mg-transition-fast), background var(--mg-transition-fast),
    color var(--mg-transition-fast), border-color var(--mg-transition-fast);
}

.mg-btn:hover {
  text-decoration: none;
}

/* Press feedback only — the brief specifies no hover motion. */
.mg-btn:active {
  transform: scale(0.96);
}

.mg-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Button mode is a <body> class, not a token (D9-1: modes are class toggles
   because they bundle several rules). Outline is the default when no mode
   class is present. */
body.mg-button-outline .mg-btn,
body:not([class*="mg-button-"]) .mg-btn {
  background: transparent;
  color: var(--mg-accent);
}

body.mg-button-outline .mg-btn:hover,
body:not([class*="mg-button-"]) .mg-btn:hover {
  background: var(--mg-accent-soft);
}

body.mg-button-solid .mg-btn {
  background: var(--mg-accent);
  color: var(--mg-accent-text);
}

body.mg-button-solid .mg-btn:hover {
  background: var(--mg-accent-hover);
  border-color: var(--mg-accent-hover);
}

body.mg-button-ghost .mg-btn {
  background: transparent;
  color: var(--mg-accent);
  border-color: transparent;
}

body.mg-button-ghost .mg-btn:hover {
  background: var(--mg-accent-soft);
}

.mg-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--mg-font-size-sm);
}

.mg-table th,
.mg-table td {
  border-bottom: var(--mg-border-width) solid var(--mg-border);
  padding: var(--mg-space-3);
  text-align: left;
}

.mg-table th {
  color: var(--mg-text-muted);
  font-weight: 700;
  font-size: var(--mg-font-size-xs);
  letter-spacing: 0.03em;
}

.mg-table tbody tr:hover td {
  background: var(--mg-surface-tint);
}

.mg-comment {
  border-top: var(--mg-border-width) solid var(--mg-border);
  padding: var(--mg-space-4) 0;
}

.mg-comment--reply {
  margin-left: var(--mg-space-6);
  border-top: 0;
  background: var(--mg-surface-tint);
  border-radius: var(--mg-radius-sm);
  padding: var(--mg-space-3) var(--mg-space-4);
  margin-top: var(--mg-space-2);
}

.emoticon {
  display: inline-block;
  width: var(--mg-emoticon-size);
  height: var(--mg-emoticon-size);
  object-fit: contain;
  vertical-align: middle;
}

.mg-emoticon-picker {
  margin: var(--mg-space-2) 0;
  padding: var(--mg-space-3);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  background: var(--mg-surface);
}

.mg-emoticon-picker h2 {
  font-size: var(--mg-font-size-sm);
  margin: var(--mg-space-2) 0;
}

.mg-emoticon-picker__items {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-2);
}

.mg-emoticon-picker__item {
  border: 0;
  padding: 0;
  background: transparent;
}

.mg-emoticon-picker__item img {
  width: calc(var(--mg-emoticon-size) * 2);
  height: calc(var(--mg-emoticon-size) * 2);
}

.toastui-editor-defaultUI-toolbar button.mg-emoticon-picker__toolbar-btn {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
}

/* Spoiler curtain. UI only — never a permission boundary (D22). The title is
   still in the HTML source; the <details> element does the hiding with no
   JavaScript so it cannot fail open. */
.mg-spoiler {
  display: block;
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  background: var(--mg-surface-tint);
  padding: var(--mg-space-4);
}

/* Lists keep the curtain in the text flow so the badge and meta stay on one
   line — <details> defaults to block and would push them onto the next row. */
.mg-spoiler--inline {
  display: inline-block;
  vertical-align: baseline;
  border-radius: var(--mg-radius-pill);
  padding: 0 var(--mg-space-3);
}

.mg-spoiler__label {
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-sm);
  cursor: pointer;
}

/* Rating badge. Part of the title, so it sits inside <h1> (D22-3). */
.mg-rating {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface-tint);
  color: var(--mg-text-muted);
  font-family: var(--mg-font-body);
  font-size: var(--mg-font-size-xs);
  font-weight: 700;
  line-height: 1.6;
  padding: 0 var(--mg-space-3);
  margin-inline-start: var(--mg-space-2);
}

.mg-rating--teen {
  background: var(--mg-green-soft);
  color: var(--mg-green-hover);
}

.mg-rating--adult {
  background: var(--mg-accent-soft);
  color: var(--mg-accent-hover);
}

/* ------------------------------------------------------------------ *
 * 6. forms
 *
 * Core screens render Django's form.as_p (D8-2), so these have to reach bare
 * elements. :where() drops the specificity to zero on purpose: vendor editor
 * stylesheets (Toast UI, Editor.js) use class selectors and must keep winning
 * over anything here.
 * ------------------------------------------------------------------ */

/* Control metrics (10px 14px, 19px box, 6px box radius) are literal because the
   design system specifies them outside the --mg-space-* rhythm. Colors stay on
   tokens. */

:where(#content) :where(input, select, textarea) {
  font-family: var(--mg-font-body);
  font-size: var(--mg-font-size-base);
  padding: 10px 14px;
  border-radius: var(--mg-radius-sm);
  border: var(--mg-border-width) solid var(--mg-border);
  background: var(--mg-surface);
  color: var(--mg-text);
  outline: none;
  transition: border-color var(--mg-transition-fast);
  width: 100%;
  max-width: 100%;
}

:where(#content) :where(input, select, textarea):focus {
  border-color: var(--mg-accent);
}

:where(#content) :where(select):hover {
  border-color: var(--mg-border-strong);
}

:where(#content) :where(textarea) {
  resize: vertical;
  min-height: 90px;
}

/* form.as_p wraps each field in a <p>; that is our .ds-field. */
:where(#content) :where(form p) {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--mg-space-4);
}

:where(#content) :where(label) {
  font-weight: 700;
  font-size: var(--mg-font-size-sm);
}

/* Django renders help_text as <span class="helptext">. */
:where(#content) :where(.helptext) {
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-xs);
}

:where(#content) :where(button, input[type="submit"]) {
  cursor: pointer;
}

/* Checkbox and radio. Django emits a bare <input>, with no sibling box element
   to paint, so the control is drawn on the input itself via appearance:none.
   The editors ship their own controls and must keep them. */
:where(#content) :where(input[type="checkbox"], input[type="radio"]):not(
  :where(.codex-editor *, .toastui-editor-defaultUI *)
) {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 19px;
  height: 19px;
  padding: 0;
  border-radius: 6px;
  border: var(--mg-border-width) solid var(--mg-border-strong);
  background: var(--mg-surface);
  display: inline-grid;
  place-content: center;
  vertical-align: text-bottom;
  transition: background var(--mg-transition-fast), border-color var(--mg-transition-fast);
}

:where(#content) :where(input[type="radio"]):not(
  :where(.codex-editor *, .toastui-editor-defaultUI *)
) {
  border-radius: var(--mg-radius-pill);
}

:where(#content) :where(input[type="checkbox"], input[type="radio"]):hover:not(
  :where(.codex-editor *, .toastui-editor-defaultUI *)
) {
  border-color: var(--mg-accent);
}

:where(#content) :where(input[type="checkbox"], input[type="radio"]):checked:not(
  :where(.codex-editor *, .toastui-editor-defaultUI *)
) {
  background: var(--mg-accent);
  border-color: var(--mg-accent);
}

:where(#content) :where(input[type="checkbox"])::after {
  content: "";
  width: 5px;
  height: 9px;
  border-right: 2px solid var(--mg-accent-text);
  border-bottom: 2px solid var(--mg-accent-text);
  transform: rotate(45deg) translate(-1px, -1px);
  opacity: 0;
  transition: opacity 0.12s ease;
}

:where(#content) :where(input[type="radio"])::after {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: var(--mg-radius-pill);
  background: var(--mg-accent-text);
  opacity: 0;
  transition: opacity 0.12s ease;
}

:where(#content) :where(input[type="checkbox"], input[type="radio"]):checked::after {
  opacity: 1;
}

:where(#content) :where(input[type="checkbox"], input[type="radio"]):focus-visible {
  box-shadow: 0 0 0 3px var(--mg-accent-soft);
}

:where(#content) :where(input, select, textarea):disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* A checkbox/radio field is a row, not a stacked label-over-control group. */
:where(#content) :where(form p):has(> input[type="checkbox"], > input[type="radio"]) {
  flex-direction: row;
  align-items: center;
  gap: 9px;
}

/* Dropdown — built over a native <select> by static/core/js/dropdown.js.
   The select is hidden HERE, inside the wrapper the script creates, and
   nowhere else: with the script absent there is no wrapper, so the plain
   select stays visible and usable. */
.mg-dropdown {
  position: relative;
  width: 100%;
}

.mg-dropdown > select {
  display: none;
}

.mg-dropdown__trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font-family: var(--mg-font-body);
  font-size: var(--mg-font-size-base);
  padding: 10px 14px;
  border-radius: var(--mg-radius-sm);
  border: var(--mg-border-width) solid var(--mg-border);
  background: var(--mg-surface);
  color: var(--mg-text);
  cursor: pointer;
  text-align: left;
  transition: border-color var(--mg-transition-fast);
}

.mg-dropdown__trigger:hover {
  border-color: var(--mg-border-strong);
}

.mg-dropdown__trigger:focus-visible {
  border-color: var(--mg-accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--mg-accent-soft);
}

.mg-dropdown__trigger[aria-expanded="true"] {
  border-color: var(--mg-accent);
}

.mg-dropdown__trigger[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.mg-dropdown__value {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mg-dropdown__value--empty {
  color: var(--mg-text-muted);
}

.mg-dropdown__chevron {
  flex: none;
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--mg-text-muted);
  border-bottom: 2px solid var(--mg-text-muted);
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform var(--mg-transition-fast);
}

.mg-dropdown__trigger[aria-expanded="true"] .mg-dropdown__chevron {
  transform: rotate(-135deg) translate(-4px, -4px);
}

.mg-dropdown__menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--mg-surface);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-sm);
  box-shadow: var(--mg-shadow-lift);
  padding: 6px;
  max-height: 260px;
  overflow: auto;
}

.mg-dropdown__menu[hidden] {
  display: none;
}

.mg-dropdown__option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: var(--mg-font-size-base);
  color: var(--mg-text);
  cursor: pointer;
}

.mg-dropdown__option:hover {
  background: var(--mg-surface-tint);
}

.mg-dropdown__option--selected {
  background: var(--mg-surface-tint);
  font-weight: 700;
}

/* Keyboard position. Kept distinct from --selected so arrowing through a
   multi-select still shows which rows are actually picked. */
.mg-dropdown__option--active {
  outline: 2px solid var(--mg-accent-soft);
  outline-offset: -2px;
}

.mg-dropdown__option[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
}

.mg-dropdown__option[aria-selected="true"] .mg-dropdown__check::before {
  content: "✓";
}

.mg-dropdown__check {
  flex: none;
  width: 16px;
  color: var(--mg-accent);
  font-weight: 700;
}

.mg-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px 3px 10px;
  border-radius: var(--mg-radius-pill);
  background: var(--mg-accent-soft);
  color: var(--mg-accent-hover);
  font-size: var(--mg-font-size-sm);
  font-weight: 700;
}

.mg-chip button {
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}

.errorlist,
.mg-field-error,
.mg-editor-error {
  color: var(--mg-danger);
}

.errorlist {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--mg-space-2);
  font-size: var(--mg-font-size-sm);
}

/* Toast UI writes an inline height on the host, but when it fails before that
   the editing area collapses to 0px and only the toolbar is left. */
[data-mg-editor] {
  min-height: 300px;
}

/* The host min-height is not enough on its own: Toast UI's internals are a
   height:100% chain, so an auto-height host still collapses the editing area. */
[data-mg-editor] .toastui-editor-ww-container,
[data-mg-editor] .toastui-editor-md-container {
  min-height: 250px;
}

.mg-post-field {
  margin-bottom: var(--mg-space-5);
}

.mg-post-form--gallery {
  display: flex;
  flex-direction: column;
}

.mg-post-form--gallery .mg-post-attachments {
  order: -1;
}

.mg-gallery-upload__preview {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-3);
}

.mg-gallery-upload__preview img {
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-sm);
  max-width: 100%;
}

/* ------------------------------------------------------------------ *
 * 7. block engine (docs/BLOCKS.md)
 * ------------------------------------------------------------------ */

.mg-block-heading {
  margin-top: var(--mg-space-6);
}

.mg-block-text,
.mg-block-list,
.mg-block-image,
.mg-block-gallery,
.mg-block-columns,
.mg-block-timeline,
.mg-block-page-link,
.mg-block-toc,
.mg-block-quote,
.mg-block-table {
  margin: var(--mg-space-5) 0;
}

.mg-block-image {
  margin-inline: 0;
}

.mg-block-image img,
.mg-block-gallery img {
  max-width: 100%;
  height: auto;
  border-radius: var(--mg-radius-sm);
}

.mg-block-image figcaption,
.mg-block-gallery figcaption {
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-sm);
  margin-top: var(--mg-space-2);
}

.mg-block-image--left { text-align: left; }
.mg-block-image--center { text-align: center; }
.mg-block-image--right { text-align: right; }

.mg-block-image--normal img { max-width: 50%; }
.mg-block-image--wide img { max-width: 75%; }
.mg-block-image--full img { max-width: 100%; }

.mg-block-gallery,
.mg-block-columns {
  display: grid;
  gap: var(--mg-space-4);
}

.mg-block-gallery__item {
  margin: 0;
}

.mg-block-gallery--cols-2,
.mg-block-columns--1-1 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mg-block-gallery--cols-3,
.mg-block-columns--1-1-1 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mg-block-gallery--cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mg-block-columns--1-2 { grid-template-columns: 1fr 2fr; }
.mg-block-columns--2-1 { grid-template-columns: 2fr 1fr; }

.mg-block-quote {
  margin-inline: 0;
  padding: var(--mg-space-3) var(--mg-space-5);
  border-inline-start: var(--mg-space-1) solid var(--mg-accent-soft);
  color: var(--mg-text);
}

.mg-block-quote__cite {
  display: block;
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-sm);
  font-style: normal;
  margin-top: var(--mg-space-2);
}

.mg-block-timeline {
  list-style: none;
  padding-inline-start: 0;
  border-inline-start: var(--mg-border-width) solid var(--mg-border);
}

.mg-block-timeline__item {
  padding: 0 0 var(--mg-space-5) var(--mg-space-5);
}

.mg-block-timeline__label {
  display: block;
  color: var(--mg-accent);
  font-weight: 700;
  font-size: var(--mg-font-size-sm);
}

.mg-block-timeline__title {
  display: block;
  font-family: var(--mg-font-heading);
  font-size: var(--mg-font-size-md);
}

.mg-block-toc {
  background: var(--mg-surface-tint);
  border-radius: var(--mg-radius);
  padding: var(--mg-space-4) var(--mg-space-5);
}

.mg-block-toc ol {
  list-style: none;
  padding-inline-start: 0;
  margin: 0;
}

.mg-block-toc__item--l3 { padding-inline-start: var(--mg-space-4); }
.mg-block-toc__item--l4 { padding-inline-start: var(--mg-space-6); }

.mg-block-page-link {
  list-style: none;
  padding-inline-start: 0;
}

.mg-block-page-link--card {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: var(--mg-space-4);
}

.mg-block-page-link--card li {
  background: var(--mg-surface);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  box-shadow: var(--mg-shadow);
  padding: var(--mg-space-4);
}

.mg-block-divider {
  border-top: var(--mg-border-width) solid var(--mg-border);
}

/* Rendered by the engine for perm_level >= 8 viewers only. */
.mg-block-error {
  border: var(--mg-border-width) dashed var(--mg-border-strong);
  border-radius: var(--mg-radius-sm);
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-sm);
  padding: var(--mg-space-3);
}

/* ------------------------------------------------------------------ *
 * 8. boards
 * ------------------------------------------------------------------ */

.mg-post-subtitle {
  color: var(--mg-text-muted);
  font-size: var(--mg-font-size-md);
  margin-top: calc(var(--mg-space-3) * -1);
}

/* Thumbnail and gallery grids wrap with flex, not with
   repeat(auto-fill, minmax(...)). An auto-fill track whose minimum is an
   intrinsic size is invalid and drops the whole declaration silently, which
   collapsed these to a single column once already (commit 169fe88). Flex
   wrapping has no such cliff, and apps/boards/tests.py holds the mechanism
   in place. */
.mg-post-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-4);
  list-style: none;
  padding-inline-start: 0;
}

.mg-post-grid__item {
  flex: 0 1 12rem;
  max-width: 100%;
}

.mg-post-grid__item img,
.mg-post-mixed-list__item img,
.mg-gallery__item img {
  max-width: 100%;
  height: auto;
  border-radius: var(--mg-radius-sm);
}

.mg-post-mixed-list {
  list-style: none;
  padding-inline-start: 0;
}

.mg-post-mixed-list__item {
  border-bottom: var(--mg-border-width) solid var(--mg-border);
  padding: var(--mg-space-3) 0;
}

.mg-post-mixed-list__item a {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--mg-space-4);
}

.mg-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-3);
  margin: var(--mg-space-5) 0;
}

/* This class lands on two different elements. A viewer who passes download_level
   gets <button class="mg-gallery__item"><img></button>; everyone else gets a bare
   <img class="mg-gallery__item"> with no lightbox hook (docs/SKIN_API.md). The
   descendant rule above only reaches the first shape, so height must be declared
   here as well — otherwise flex shrinks the width while the intrinsic height
   attribute survives and the image renders as a tall strip. */
.mg-gallery__item {
  flex: 0 1 10rem;
  max-width: 100%;
  height: auto;
  background: var(--mg-surface-tint);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-sm);
  padding: 0;
  overflow: hidden;
  cursor: zoom-in;
}

/* No opening hook on the bare image, so it must not advertise one. */
img.mg-gallery__item {
  cursor: default;
}

/* Lightbox. The overlay lives inside #content so an hx-boost swap disposes of
   it (docs/SKIN_API.md). */
.mg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  gap: var(--mg-space-4);
  padding: var(--mg-space-5);
  background: var(--mg-bg);
}

.mg-lightbox[hidden] {
  display: none;
}

.mg-lightbox__image {
  max-width: min(100%, var(--mg-content-width));
  max-height: 80vh;
  object-fit: contain;
}

.mg-lightbox__prev,
.mg-lightbox__next,
.mg-lightbox__close {
  position: absolute;
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface);
  color: var(--mg-text);
  font: inherit;
  padding: var(--mg-space-2) var(--mg-space-4);
  cursor: pointer;
}

.mg-lightbox__prev { inset-inline-start: var(--mg-space-5); }
.mg-lightbox__next { inset-inline-end: var(--mg-space-5); }
.mg-lightbox__close { top: var(--mg-space-5); inset-inline-end: var(--mg-space-5); }

.mg-lightbox__caption { margin: 0; color: var(--mg-text); }
.mg-lightbox__counter { margin-inline-start: var(--mg-space-2); color: var(--mg-text-muted); }
.mg-lightbox__zoom { position: absolute; inset-block-end: var(--mg-space-5); inset-inline-end: var(--mg-space-5); }
.mg-lightbox--zoom { overflow: auto; align-items: start; }
.mg-lightbox--zoom .mg-lightbox__image { max-width: none; max-height: none; width: auto; }
.mg-lightbox--zoom .mg-lightbox__prev,
.mg-lightbox--zoom .mg-lightbox__next { display: none; }

.mg-page-head, .mg-board-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--mg-space-3); margin-block-end: var(--mg-space-5); }
.mg-page-head__title, .mg-board-head__title { margin: 0; }
.mg-page-head__meta, .mg-board-head__desc { margin: 0; }
.mg-page-head__actions, .mg-board-head__actions { display: flex; gap: var(--mg-space-2); margin-inline-start: auto; }
.mg-badge { display: inline-block; padding: var(--mg-space-1) var(--mg-space-2); border-radius: var(--mg-radius-pill); font-size: var(--mg-font-size-xs); font-weight: 700; background: var(--mg-accent-soft); color: var(--mg-accent-hover); }
.mg-badge--green { background: var(--mg-green-soft); color: var(--mg-green-hover); }
.mg-badge--muted { background: var(--mg-surface-tint); color: var(--mg-text-muted); }
.mg-badge--notice { background: var(--mg-accent-soft); color: var(--mg-accent-hover); }
.mg-badge--pending { background: var(--mg-danger-soft); color: var(--mg-danger); }
.mg-avatar { display: block; inline-size: var(--mg-avatar-size); block-size: var(--mg-avatar-size); border: var(--mg-border-width) solid var(--mg-border); border-radius: var(--mg-radius-pill); background: var(--mg-surface-tint); object-fit: cover; }
.mg-avatar--sm { inline-size: var(--mg-avatar-size-sm); block-size: var(--mg-avatar-size-sm); }
.mg-avatar--empty { display: inline-block; }
.mg-character-grid { display: flex; flex-wrap: wrap; gap: var(--mg-space-4); }
.mg-character-card { flex: 1 1 13.75rem; max-width: 100%; border: var(--mg-border-width) solid var(--mg-border); border-radius: var(--mg-radius); background: var(--mg-surface); }
.mg-character-card__link { display: flex; gap: var(--mg-space-3); padding: var(--mg-space-4); color: inherit; text-decoration: none; }
.mg-character-card__body { display: block; min-width: 0; }
.mg-character-card__name, .mg-character-card__intro { display: block; }
.mg-character-card__badges { display: flex; flex-wrap: wrap; gap: var(--mg-space-1); margin-block: var(--mg-space-1); }
.mg-character-grid--list { flex-direction: column; gap: 0; }
.mg-character-grid--list .mg-character-card { flex: 1 1 auto; border-radius: 0; }
.mg-filter-chips { display: flex; gap: var(--mg-space-2); overflow-x: auto; margin-block-end: var(--mg-space-4); }
.mg-filter-chip { white-space: nowrap; padding: var(--mg-space-2) var(--mg-space-3); border: var(--mg-border-width) solid var(--mg-border); border-radius: var(--mg-radius-pill); }
.mg-filter-chip--active { background: var(--mg-accent); border-color: var(--mg-accent); color: var(--mg-accent-text); }
.mg-pagination { display: flex; justify-content: center; align-items: center; gap: var(--mg-space-2); margin-block-start: var(--mg-space-5); }
.mg-pagination__page, .mg-pagination__current, .mg-pagination__step { padding: var(--mg-space-2) var(--mg-space-3); border-radius: var(--mg-radius-sm); }
.mg-pagination__current { background: var(--mg-accent); color: var(--mg-accent-text); }
.mg-pagination__gap { padding: var(--mg-space-2); color: var(--mg-text-muted); }
.mg-view-toggle { font-size: var(--mg-font-size-sm); color: var(--mg-text-muted); }
.mg-empty { color: var(--mg-text-muted); }
.mg-profile__header { display: flex; align-items: center; gap: var(--mg-space-4); margin-block-end: var(--mg-space-6); }
.mg-profile__avatar { inline-size: var(--mg-avatar-size); block-size: var(--mg-avatar-size); }
.mg-profile__name { margin: 0; }
.mg-profile__body { min-width: 0; }
.mg-profile--aside .mg-profile__body { display: grid; grid-template-columns: var(--mg-profile-aside-width) minmax(0, 1fr); gap: var(--mg-space-6); }
.mg-profile__aside { min-width: 0; }
.mg-profile-info { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--mg-space-2) var(--mg-space-4); }
.mg-profile-info__term, .mg-profile-info__desc { margin: 0; }
.mg-profile-info__image { max-width: 100%; height: auto; }
.mg-profile-section { scroll-margin-top: var(--mg-space-8); margin-block: var(--mg-space-5); }
.mg-profile-section__head { cursor: pointer; }
.mg-profile-section__title { display: inline; font-size: var(--mg-font-size-lg); }
.mg-profile-section__more { margin-inline-start: var(--mg-space-2); color: var(--mg-text-muted); }
.mg-profile-section__body { max-width: 68ch; line-height: 1.8; margin-block-start: var(--mg-space-3); }
.mg-profile-layout { display: flex; flex-direction: column; gap: var(--mg-space-5); }
.mg-profile-layout > .mg-profile__header { margin-block-end: 0; }
.mg-profile-layout > .mg-featured-log { margin-top: 0; }
.mg-block-character-field { display: flex; flex-direction: column; gap: var(--mg-space-1); }
.mg-block-character-field__label { color: var(--mg-text-muted); font-size: var(--mg-font-size-sm); }
.mg-block-character-field__value { max-width: 68ch; line-height: 1.8; }
.mg-block-character-field__image { max-width: 100%; height: auto; }
.mg-profile__badge { margin-inline-start: var(--mg-space-2); }
@media (min-width: 75rem) { .mg-profile-toc { position: sticky; top: var(--mg-space-5); } }
body.mg-headerfix-on.mg-header-top .mg-profile-toc { position: static; }
@media (max-width: 64rem) { .mg-profile--aside .mg-profile__body { grid-template-columns: 1fr; } .mg-profile-toc__list { display: flex; gap: var(--mg-space-2); overflow-x: auto; padding: 0; list-style: none; } }
@media (max-width: 64rem) { .mg-profile-layout .mg-block-columns { grid-template-columns: 1fr; } }
@media (max-width: 48rem) { .mg-profile__avatar { inline-size: var(--mg-avatar-size-sm); block-size: var(--mg-avatar-size-sm); } .mg-profile-info { grid-template-columns: 1fr; } }

/* Novel reader. The --mg-reader-* variables are inherited from the .mg-reader
   root and consumed by .mg-reader-body, so the title, byline and typography
   controls keep their own size (docs/SKIN_API.md). */
.mg-reader {
  max-width: var(--mg-reader-width);
  margin: 0 auto;
}

.mg-reader-body {
  font-family: var(--mg-reader-font-family);
  font-size: calc(var(--mg-font-size-base) * var(--mg-reader-font-scale));
  line-height: var(--mg-reader-line-height);
  text-align: var(--mg-reader-align);
}

.mg-reader-body p {
  margin: 0 0 1em;
}

.mg-reader-controls,
.mg-series-nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-2);
  margin-block: var(--mg-space-5);
}

.mg-reader-controls {
  background: var(--mg-surface-tint);
  border-radius: var(--mg-radius);
  padding: var(--mg-space-3) var(--mg-space-4);
  align-items: center;
}

.mg-reader-controls button {
  font: inherit;
  font-size: var(--mg-font-size-sm);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-pill);
  background: var(--mg-surface);
  color: var(--mg-text);
  padding: var(--mg-space-1) var(--mg-space-3);
  cursor: pointer;
  transition: background var(--mg-transition-fast), border-color var(--mg-transition-fast);
}

.mg-reader-controls button:hover {
  border-color: var(--mg-accent);
  background: var(--mg-accent-soft);
}

.mg-series-cover,
.mg-series img {
  max-width: 100%;
  border-radius: var(--mg-radius);
}

.mg-series-posts {
  list-style: none;
  padding-inline-start: 0;
}

.mg-bookmark {
  margin-block: var(--mg-space-5);
}

/* ------------------------------------------------------------------ *
 * 9. characters
 * ------------------------------------------------------------------ */

.mg-featured-characters,
.mg-featured-log {
  border-top: var(--mg-border-width) solid var(--mg-border);
  padding-top: var(--mg-space-4);
  margin-top: var(--mg-space-5);
}

.mg-featured-log ul {
  list-style: none;
  padding-inline-start: 0;
}

.mg-featured-log li {
  border-bottom: var(--mg-border-width) solid var(--mg-border);
  padding: var(--mg-space-2) 0;
}

.mg-post-row--notice td { background: var(--mg-surface-tint); }
.mg-mypage__summary { display: flex; align-items: center; gap: var(--mg-space-4); }
.mg-mypage__account { margin-block-start: var(--mg-space-4); }
.mg-auth { max-width: 26rem; margin-inline: auto; }
.mg-form-actions { margin-block-start: var(--mg-space-4); }

/* ------------------------------------------------------------------ *
 * 10. manage
 * ------------------------------------------------------------------ */

.mg-manage nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-3);
  background: var(--mg-surface-tint);
  border-radius: var(--mg-radius);
  padding: var(--mg-space-3) var(--mg-space-4);
  margin-bottom: var(--mg-space-5);
  font-size: var(--mg-font-size-sm);
}

/* ------------------------------------------------------------------ *
 * 11. narrow viewports
 * ------------------------------------------------------------------ */

@media (max-width: 48rem) {
  .mg-shell-main {
    padding: var(--mg-space-5) var(--mg-space-4);
  }

  body.mg-header-top .mg-shell,
  body.mg-header-left .mg-shell,
  body.mg-header-right .mg-shell {
    grid-template-areas: "header" "content";
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  body.mg-header-top .mg-shell-header,
  body.mg-header-left .mg-shell-header,
  body.mg-header-right .mg-shell-header {
    flex-direction: row;
    align-items: center;
    gap: var(--mg-space-3);
    padding: var(--mg-space-3) var(--mg-space-4);
  }

  /* On narrow screens the left/right headers are ordinary top bars, not
     sidebars. The desktop sticky/100vh/overflow rules must be undone:
     1. otherwise the header is as tall as the viewport
     2. position: sticky creates a stacking context, which traps the drawer
        (.mg-shell-nav, z-index 3) inside the header and lets the scrim
        (z-index 2, a sibling of the shell) cover it — the menu is visible
        but unclickable */
  body.mg-header-left .mg-shell-header,
  body.mg-header-right .mg-shell-header {
    position: static;
    height: auto;
    overflow-y: visible;
    border-inline: 0;
    border-bottom: var(--mg-border-width) solid var(--mg-border);
  }

  /* Lift the header above the scrim while the drawer is open. A sticky or
     fixed header (headerfix-on, bottom) makes its own stacking context, so
     the drawer inside it would otherwise sit under the scrim.

     The placement class is repeated to reach specificity (0,3,1).
     body.mg-nav-open .mg-shell-header alone is (0,2,1) and loses to
     body.mg-headerfix-on.mg-header-top .mg-shell-header. */
  body.mg-nav-open.mg-header-top .mg-shell-header,
  body.mg-nav-open.mg-header-left .mg-shell-header,
  body.mg-nav-open.mg-header-right .mg-shell-header,
  body.mg-nav-open.mg-header-bottom .mg-shell-header {
    z-index: 4;
  }

  /* With the drawer open the back-to-top button would float over the scrim. */
  body.mg-nav-open .mg-shell-totop {
    display: none;
  }

  .mg-shell-nav-toggle {
    display: block;
  }

  .mg-shell-nav {
    display: block;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: var(--mg-shell-nav-width);
    background: var(--mg-surface);
    border-inline-end: var(--mg-border-width) solid var(--mg-border);
    padding: var(--mg-space-4);
    transform: translateX(-100%);
    transition: transform var(--mg-transition);
    z-index: 3;
    overflow-y: auto;
  }

  body.mg-header-right .mg-shell-nav {
    inset-inline-start: auto;
    inset-inline-end: 0;
    border-inline-end: 0;
    border-inline-start: var(--mg-border-width) solid var(--mg-border);
    transform: translateX(100%);
  }

  body.mg-nav-open .mg-shell-nav {
    transform: translateX(0);
  }

  .mg-shell-nav-item:hover > .mg-shell-subnav,
  .mg-shell-nav-item:focus-within > .mg-shell-subnav {
    position: static;
  }

  .mg-shell-subnav {
    display: block;
    border: 0;
    box-shadow: none;
    background: transparent;
    padding: 0;
    margin-inline-start: var(--mg-space-3);
  }

  body.mg-nav-open .mg-shell-scrim {
    display: block;
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--mg-text) 25%, transparent);
    z-index: 2;
  }

  /* The bottom placement uses a bottom sheet on mobile, not a tab bar. A tab
     bar only works when labels are short, but MenuItem.title is free text the
     admin writes, so the core cannot bound its length — names like
     "자유게시판" were clipped in every slot. The dock keeps the brand, the
     toggle and the player; the menu moves into a sheet that rises over it. */
  body.mg-header-bottom .mg-shell-header {
    gap: var(--mg-space-3);
  }

  body.mg-header-bottom .mg-shell-nav {
    inset-block: auto;
    inset-inline: 0;
    bottom: var(--mg-shell-dock-height);
    width: auto;
    max-height: 60vh;
    overflow-y: auto;
    border: var(--mg-border-width) solid var(--mg-border);
    border-block-end: 0;
    border-radius: var(--mg-radius) var(--mg-radius) 0 0;
    /* Travelling only its own height (100%) leaves it short by the bottom
       offset, so the sheet still covers the dock: the menu shows instead of
       the dock and a stacked list reads as "the dock turned vertical". */
    transform: translateY(calc(100% + var(--mg-shell-dock-height)));
  }

  body.mg-nav-open.mg-header-bottom .mg-shell-nav {
    transform: translateY(0);
  }

  body.mg-header-bottom .mg-shell-account {
    display: none;
  }

  #content dl {
    grid-template-columns: 1fr;
    gap: 0;
  }

  #content dd {
    margin-bottom: var(--mg-space-3);
  }

  .mg-block-gallery,
  .mg-block-columns,
  .mg-block-gallery--cols-2,
  .mg-block-gallery--cols-3,
  .mg-block-gallery--cols-4,
  .mg-block-columns--1-1,
  .mg-block-columns--1-1-1,
  .mg-block-columns--1-2,
  .mg-block-columns--2-1 {
    grid-template-columns: 1fr;
  }

  .mg-comment--reply {
    margin-left: var(--mg-space-4);
  }
}

/* Users who ask for reduced motion get none of the transitions above. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}

.mg-block-accordion {
  display: flex;
  flex-direction: column;
  gap: var(--mg-space-2);
  margin: var(--mg-space-5) 0;
}

.mg-block-accordion__panel {
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius-sm);
  background: var(--mg-surface);
  scroll-margin-top: var(--mg-space-8);
}

.mg-block-accordion__summary {
  cursor: pointer;
  padding: var(--mg-space-3) var(--mg-space-4);
  font-family: var(--mg-font-heading);
}

.mg-block-accordion__body {
  padding: 0 var(--mg-space-4) var(--mg-space-4);
}

.mg-block-tabs {
  margin: var(--mg-space-5) 0;
}

.mg-block-tabs__list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--mg-space-2);
  border-bottom: var(--mg-border-width) solid var(--mg-border);
  margin-bottom: var(--mg-space-4);
}

.mg-block-tabs__list[hidden] { display: none; }

.mg-block-tabs__tab {
  border: var(--mg-border-width) solid transparent;
  border-radius: var(--mg-radius-pill);
  background: none;
  color: var(--mg-text-muted);
  cursor: pointer;
  padding: var(--mg-space-2) var(--mg-space-4);
  font-family: var(--mg-font-heading);
  transition: background var(--mg-transition-fast), color var(--mg-transition-fast),
    border-color var(--mg-transition-fast);
}

.mg-block-tabs__tab:hover {
  color: var(--mg-text);
  background: var(--mg-surface-tint);
}

.mg-block-tabs__tab[aria-selected="true"] {
  background: var(--mg-accent-soft);
  border-color: var(--mg-accent);
  color: var(--mg-text);
}

.mg-block-tabs__panel { display: block; }
.mg-block-tabs__panel[hidden] { display: none; }

.mg-block-tabs__title {
  font-size: var(--mg-font-size-lg);
  margin: 0 0 var(--mg-space-3);
}

.mg-block-tabs__title[hidden] { display: none; }
/* Main widgets */
.mg-block-slideshow { position: relative; }
.mg-block-slideshow__viewport { overflow: hidden; }
.mg-block-slideshow__slide { display: block; margin: 0; }
.mg-block-slideshow__slide[hidden] { display: none; }
.mg-block-slideshow__link { display: block; }
.mg-block-slideshow__caption { color: var(--mg-text-muted); }
.mg-block-slideshow__nav { display: inline-flex; }
.mg-block-slideshow__nav[hidden] { display: none; }
.mg-block-slideshow__nav--prev { margin-inline-end: var(--mg-space-2); }
.mg-block-slideshow__nav--next { margin-inline-start: var(--mg-space-2); }
.mg-block-slideshow__dots { display: flex; gap: var(--mg-space-2); }
.mg-block-slideshow__dots[hidden] { display: none; }
.mg-block-slideshow__dot { inline-size: var(--mg-space-3); block-size: var(--mg-space-3); }
.mg-block-slideshow__toggle { display: inline-flex; }
.mg-block-slideshow__toggle[hidden] { display: none; }
.mg-block-slideshow__toggle[aria-pressed="true"]::before { content: "||"; }
.mg-block-slideshow__toggle[aria-pressed="false"]::before { content: ">"; }
.mg-block-dday { padding: var(--mg-space-4); }
.mg-block-dday--today { border-color: var(--mg-accent); }
.mg-block-dday--past { color: var(--mg-text-muted); }
.mg-block-dday__label, .mg-block-dday__note { color: var(--mg-text-muted); }
.mg-block-dday__count { font-size: var(--mg-font-size-xl); }
.mg-block-dday__date { margin: 0; }
/* The month links carry a #mg-cal-<id> anchor so the reader lands back on the
   calendar instead of the top of the page. A bare anchor jump puts the section's
   top edge flush against the viewport top, scrolling the header out of view, so
   keep the same breathing room the other anchor targets use. */
.mg-block-calendar { container-type: inline-size; container-name: mg-calendar; overflow-x: auto; scroll-margin-top: var(--mg-space-8); }
.mg-block-calendar__head { display: flex; align-items: center; justify-content: space-between; gap: var(--mg-space-3); margin-block-end: var(--mg-space-3); }
.mg-block-calendar__step { padding: var(--mg-space-1) var(--mg-space-2); border-radius: var(--mg-radius-sm); color: var(--mg-link); font-weight: 700; }
.mg-block-calendar__step:hover { background: var(--mg-surface-tint); }
.mg-block-calendar__heading { text-align: center; }
.mg-block-calendar__title { margin: 0; font-size: var(--mg-font-size-xs); color: var(--mg-text-muted); font-weight: 700; }
.mg-block-calendar__month { margin: 0; font-size: var(--mg-font-size-lg); font-weight: 700; }
.mg-block-calendar__grid { inline-size: 100%; table-layout: fixed; border-collapse: collapse; }
.mg-block-calendar__grid caption { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.mg-block-calendar__grid th { padding-block: var(--mg-space-2); border-block-end: var(--mg-border-width) solid var(--mg-border-strong); font-size: var(--mg-font-size-sm); font-weight: 700; color: var(--mg-text-muted); }
.mg-block-calendar__grid th:first-child { color: var(--mg-danger); }
.mg-block-calendar__grid th:last-child { color: var(--mg-link); }
.mg-block-calendar__cell { position: relative; vertical-align: top; text-align: start; padding: var(--mg-space-1); border: var(--mg-border-width) solid var(--mg-border); }
.mg-block-calendar__cell--out { background: var(--mg-surface-tint); }
.mg-block-calendar__cell--out .mg-block-calendar__day { color: var(--mg-text-muted); font-weight: 400; }
.mg-block-calendar__cell--today { background: var(--mg-accent-soft); }
.mg-block-calendar__cell--today .mg-block-calendar__day { background: var(--mg-accent); color: var(--mg-accent-text); }
/* table-layout: fixed makes every column an equal share of the block's own
   width (18rem sidebar included), so the grid never needs the outer overflow-x
   scrollbar - only the event chip text truncates via its own ellipsis. */
.mg-block-calendar__day { display: inline-flex; align-items: center; justify-content: center; min-inline-size: 1.5rem; block-size: 1.5rem; border-radius: var(--mg-radius-pill); font-size: var(--mg-font-size-xs); font-weight: 700; }
/* Capped to two chip rows regardless of how many events land on the day, so
   switching months never reflows row heights wildly - the rest live behind
   the __more toggle instead of growing the cell (and, with it, the page). */
.mg-block-calendar__events { display: flex; flex-direction: column; gap: var(--mg-space-1); margin-block-start: var(--mg-space-1); max-block-size: calc(2 * var(--mg-font-size-xs) * 1.5 + var(--mg-space-1)); overflow: hidden; }
/* block-size is explicit, not min-block-size: a continuation tile's label is
   empty (only the first visible tile of an event carries text), and an empty
   block-level child gives the chip no content height to stand on otherwise -
   the compact dot/line mode below overrides this with its own explicit size. */
.mg-block-calendar__event { display: block; overflow: hidden; block-size: calc(var(--mg-font-size-xs) * 1.5); padding-inline: var(--mg-space-1); border-radius: var(--mg-radius-sm); background: color-mix(in srgb, currentColor 16%, var(--mg-surface)); text-align: start; font-size: var(--mg-font-size-xs); line-height: 1.5; }
.mg-block-calendar__event-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.mg-block-calendar__event--cat-1 { color: var(--mg-schedule-1); }
.mg-block-calendar__event--cat-2 { color: var(--mg-schedule-2); }
.mg-block-calendar__event--cat-3 { color: var(--mg-schedule-3); }
.mg-block-calendar__event--cat-4 { color: var(--mg-schedule-4); }
.mg-block-calendar__event--cat-5 { color: var(--mg-schedule-5); }
.mg-block-calendar__event--cat-6 { color: var(--mg-schedule-6); }
.mg-block-calendar__event--cat-7 { color: var(--mg-schedule-7); }
.mg-block-calendar__event--cat-8 { color: var(--mg-schedule-8); }
/* start/mid/end square off the edge that continues into the next day's cell so
   a multi-day event at least hints at continuity without colspan (out of scope
   for v0.3-b-11 — see docs/plans/v0.3-b-11-schedule-calendar.md §2). */
.mg-block-calendar__event--start { border-start-end-radius: 0; border-end-end-radius: 0; }
.mg-block-calendar__event--mid { border-radius: 0; }
.mg-block-calendar__event--end { border-start-start-radius: 0; border-end-start-radius: 0; }
/* "+N" overflow toggle. The panel is positioned absolute so opening it never
   changes the table's row heights (that reflow was itself pushing the page
   around under the anchor-jump from month navigation). */
.mg-block-calendar__more { margin-block-start: var(--mg-space-1); }
.mg-block-calendar__more-toggle { display: inline-block; padding: 0 var(--mg-space-1); border-radius: var(--mg-radius-sm); background: var(--mg-surface-tint); color: var(--mg-text-muted); font-size: var(--mg-font-size-xs); font-weight: 700; cursor: pointer; list-style: none; }
.mg-block-calendar__more-toggle::-webkit-details-marker { display: none; }
.mg-block-calendar__more[open] .mg-block-calendar__more-toggle { background: var(--mg-accent); color: var(--mg-accent-text); }
.mg-block-calendar__more-panel { position: absolute; z-index: 1; inset-inline-start: var(--mg-space-1); top: 100%; margin-block-start: var(--mg-space-1); min-inline-size: 10rem; max-inline-size: 16rem; padding: var(--mg-space-2); border: var(--mg-border-width) solid var(--mg-border); border-radius: var(--mg-radius-sm); background: var(--mg-surface); box-shadow: var(--mg-shadow-lift); }
.mg-block-calendar__more-item { display: flex; align-items: center; gap: var(--mg-space-1); margin: 0; font-size: var(--mg-font-size-xs); }
.mg-block-calendar__more-item + .mg-block-calendar__more-item { margin-block-start: var(--mg-space-1); }
/* Below this the column is too narrow for readable event text (the 18rem
   sidebar included) - collapse each chip to a color dot, or a thin bar for
   the days a multi-day event continues through. The full title still reaches
   the reader through the chip's title="" tooltip. */
@container mg-calendar (max-width: 26rem) {
  .mg-block-calendar__event-label { display: none; }
  .mg-block-calendar__event { inline-size: var(--mg-space-2); block-size: var(--mg-space-2); margin-inline: auto; padding: 0; background: currentColor; border-radius: var(--mg-radius-pill); }
  .mg-block-calendar__event--start, .mg-block-calendar__event--mid, .mg-block-calendar__event--end {
    inline-size: 100%; block-size: var(--mg-space-1); margin-inline: 0; border-radius: 0;
  }
}
.mg-block-calendar__legend { display: flex; flex-wrap: wrap; gap: var(--mg-space-3); margin-block-start: var(--mg-space-3); padding: 0; list-style: none; font-size: var(--mg-font-size-sm); color: var(--mg-text-muted); }
.mg-block-calendar__legend-item { display: flex; align-items: center; gap: var(--mg-space-1); }
.mg-block-calendar__swatch { flex: none; inline-size: var(--mg-space-3); block-size: var(--mg-space-3); border-radius: var(--mg-radius-pill); background: currentColor; }
.mg-block-recent-posts { margin-block: var(--mg-space-5); }
.mg-block-recent-posts__title { margin-block-end: var(--mg-space-3); }
.mg-block-login { display: grid; gap: var(--mg-space-3); }
.mg-block-login__title, .mg-block-login__me { margin: 0; }
.mg-block-login__form { display: grid; gap: var(--mg-space-3); }
.mg-block-login__field { display: grid; gap: var(--mg-space-1); }
.mg-block-login__links { display: flex; gap: var(--mg-space-2); align-items: center; }

.mg-intro-page {
  display: grid;
  min-block-size: 100vh;
  place-items: center;
  padding: var(--mg-space-5);
}

.mg-intro {
  inline-size: min(100%, var(--mg-content-width));
  padding: var(--mg-space-6);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  background: var(--mg-surface);
}

.mg-intro__title { margin-block-start: 0; }
.mg-intro__body { margin-block: var(--mg-space-5); }
.mg-intro__enter { display: flex; justify-content: center; }

.mg-popup-layer {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.mg-popup {
  position: absolute;
  pointer-events: auto;
  inline-size: min(var(--mg-popup-w), calc(100vw - var(--mg-space-6)));
  block-size: var(--mg-popup-h, auto);
  max-block-size: calc(100vh - var(--mg-space-6));
  overflow: auto;
  padding: var(--mg-space-5);
  border: var(--mg-border-width) solid var(--mg-border);
  border-radius: var(--mg-radius);
  background: var(--mg-surface);
  box-shadow: var(--mg-shadow);
}

.mg-popup--center {
  inset-block-start: 50%;
  inset-inline-start: 50%;
  translate: calc(-50% + var(--mg-popup-x)) calc(-50% + var(--mg-popup-y));
}

.mg-popup--top-left {
  inset-block-start: calc(var(--mg-space-5) + var(--mg-popup-y));
  inset-inline-start: calc(var(--mg-space-5) + var(--mg-popup-x));
}

.mg-popup--top-right {
  inset-block-start: calc(var(--mg-space-5) + var(--mg-popup-y));
  inset-inline-end: calc(var(--mg-space-5) + var(--mg-popup-x));
}

.mg-popup--bottom-left {
  inset-block-end: calc(var(--mg-space-5) + var(--mg-popup-y));
  inset-inline-start: calc(var(--mg-space-5) + var(--mg-popup-x));
}

.mg-popup--bottom-right {
  inset-block-end: calc(var(--mg-space-5) + var(--mg-popup-y));
  inset-inline-end: calc(var(--mg-space-5) + var(--mg-popup-x));
}

.mg-popup__actions { display: flex; flex-wrap: wrap; gap: var(--mg-space-2); margin-block-start: var(--mg-space-4); }
.mg-popup__body > :first-child { margin-block-start: 0; }

/* The gallery block wraps every thumbnail in <a href="원본 파일">, which is fine on a
   page but wrong inside a popup: clicking an announcement image would navigate the
   visitor away to a raw image file. Neutralise the link here only — the block markup
   is shared with pages and the sidebar and is not this stage's to change. Giving the
   gallery block a real lightbox (as character_gallery has) is the proper fix and is
   its own step; see the plan's "닫지 않는 것". */
.mg-popup .mg-block-gallery__item a { pointer-events: none; cursor: default; }
.mg-popup__form { margin: 0; }
.mg-popup__close { font: inherit; }

body:has(#content .mg-manage) .mg-popup-layer { display: none; }

@media (max-width: 48rem) {
  .mg-popup-layer {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: var(--mg-space-3);
    padding: var(--mg-space-4);
  }

  .mg-popup { position: static; translate: none; inline-size: 100%; }
}
