/* Markdown Mini window: chrome, toolbar, menus and sheets. Shared by /app and
   the home page. Measurements follow the Mac app: a 44pt toolbar strip, 30pt
   capsules, 12pt traffic lights. Tokens are scoped to .mm so the host page's
   own variables are left alone. */

.mm {
  color-scheme: light dark;
  --chrome: #ececec;
  --capsule: #ffffff;
  --capsule-edge: 0 0 0 0.5px rgba(0, 0, 0, 0.1), 0 1px 1.5px rgba(0, 0, 0, 0.07);
  --icon: rgba(0, 0, 0, 0.8);
  --hover: rgba(0, 0, 0, 0.06);
  --press: rgba(0, 0, 0, 0.12);
  --sep: rgba(0, 0, 0, 0.12);
  --doc: #ffffff;
  --divider: rgba(128, 128, 128, 0.3);
  --accent: #0a84ff;
  --menu-bg: rgba(242, 242, 244, 0.86);
  --menu-text: rgba(0, 0, 0, 0.88);
  --menu-dim: rgba(0, 0, 0, 0.4);
  --menu-edge: 0 0 0 0.5px rgba(0, 0, 0, 0.16), 0 10px 32px rgba(0, 0, 0, 0.18);
  --win-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.22), 0 22px 60px rgba(0, 0, 0, 0.28), 0 4px 14px rgba(0, 0, 0, 0.12);
  --win-inner: none;
  --sheet-bg: #f3f3f5;
  --field: #ffffff;
  --field-edge: rgba(0, 0, 0, 0.14);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  .mm {
    --chrome: #474a4b;
    --capsule: #2b2d2e;
    --capsule-edge: none;
    --icon: #dcdddd;
    --hover: rgba(255, 255, 255, 0.08);
    --press: rgba(255, 255, 255, 0.16);
    --sep: rgba(255, 255, 255, 0.12);
    --doc: #1e1e1e;
    --menu-bg: rgba(40, 40, 42, 0.86);
    --menu-text: rgba(255, 255, 255, 0.9);
    --menu-dim: rgba(255, 255, 255, 0.38);
    --menu-edge: 0 0 0 0.5px rgba(0, 0, 0, 0.6), inset 0 0 0 0.5px rgba(255, 255, 255, 0.14), 0 10px 32px rgba(0, 0, 0, 0.4);
    --win-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.8), 0 22px 60px rgba(0, 0, 0, 0.55), 0 4px 14px rgba(0, 0, 0, 0.3);
    --win-inner: inset 0 0.5px 0 rgba(255, 255, 255, 0.16);
    --sheet-bg: #2c2c2e;
    --field: #1e1e1e;
    --field-edge: rgba(255, 255, 255, 0.14);
  }
}

.mm, .mm * { box-sizing: border-box; }
.mm button { font: inherit; color: inherit; }
.mm[hidden], .mm [hidden] { display: none !important; }
.window, .menu, .sheet, .toast { font: 13px/1.3 var(--font); -webkit-font-smoothing: antialiased; }
/* While the window or the divider is dragged, the frames must not swallow the pointer. */
body.dragging iframe { pointer-events: none; }
body.dragging { user-select: none; -webkit-user-select: none; }

/* Window ------------------------------------------------------------------ */

.window {
  position: absolute; display: flex; flex-direction: column;
  min-width: 0; border-radius: 20px; overflow: hidden;
  background: var(--doc);
  box-shadow: var(--win-shadow);
  transition: transform .28s cubic-bezier(.3,.7,.2,1), opacity .22s ease;
  transform-origin: 50% 100%;
}
.window.animating { transition: left .25s cubic-bezier(.3,.7,.2,1), top .25s cubic-bezier(.3,.7,.2,1), width .25s cubic-bezier(.3,.7,.2,1), height .25s cubic-bezier(.3,.7,.2,1); }
.window.minimized { transform: translateY(60%) scale(.08); opacity: 0; pointer-events: none; }
.window::after { /* light top edge in dark mode */
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: var(--win-inner); z-index: 3;
}

.titlebar {
  flex-shrink: 0; height: 44px; display: flex; align-items: center;
  padding: 0 8px 0 0; background: var(--chrome);
  user-select: none; -webkit-user-select: none;
  touch-action: none;
}
.traffic { display: flex; gap: 8px; padding: 0 17px 0 17px; height: 100%; align-items: center; flex-shrink: 0; }
.light {
  width: 12px; height: 12px; border-radius: 50%; border: 0; padding: 0; position: relative;
  box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.18);
}
.light--close { background: #ec6765; }
.light--min { background: #f2ca44; }
.light--zoom { background: #65c466; }
.light::after {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font: 700 9px/1 var(--font); color: rgba(0, 0, 0, 0.55); opacity: 0;
}
.light--close::after { content: "×"; font-size: 11px; }
.light--min::after { content: "−"; }
.light--zoom::after { content: "+"; }
.traffic:hover .light::after { opacity: 1; }
body.inactive .light { background: rgba(128, 128, 128, 0.35); }

/* Toolbar ----------------------------------------------------------------- */

.toolbar { flex: 1; min-width: 0; height: 100%; display: flex; align-items: center; gap: 16px; }
.toolbar__flex { flex: 1; min-width: 0; align-self: stretch; }
.group {
  display: flex; align-items: center; height: 30px; padding: 0 2px; border-radius: 15px;
  background: var(--capsule); box-shadow: var(--capsule-edge); flex-shrink: 0;
}
.group--round { padding: 0; }
.tb {
  height: 26px; min-width: 30px; padding: 0 6px; border: 0; border-radius: 13px; background: none;
  display: flex; align-items: center; justify-content: center; gap: 2px;
  color: var(--icon); cursor: default; position: relative;
  -webkit-touch-callout: none;
}
.group--round .tb { height: 30px; min-width: 32px; border-radius: 15px; }
.tb:hover { background: var(--hover); }
.tb:active, .tb.pressed { background: var(--press); }
.tb.on { background: var(--accent); color: #fff; }
.tb svg { display: block; flex-shrink: 0; }
.tb .txt { font: 600 12px/1 var(--font); letter-spacing: 0.01em; }
.tb .glyph { font: 400 17px/1 var(--font); }
.tb .glyph--b { font-weight: 700; font-size: 16px; }
.tb .glyph--i { font-style: italic; font-weight: 400; font-size: 16px; }
.tb .glyph--s { text-decoration: line-through; text-decoration-thickness: 1.5px; font-size: 16px; }
.tb .chev { opacity: .7; margin-left: 1px; }
.tb--compact { padding: 0 8px 0 9px; }
/* Thin separators between the items of a native toolbar item group. */
.group--seg .tb + .tb::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px; width: 1px; background: var(--sep);
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: block; }
.dot.ring { width: 12px; height: 12px; background: none !important; border: 1.5px solid var(--c); padding: 1.5px; background-clip: content-box !important; position: relative; }
.dot.ring::after { content: ""; position: absolute; inset: 1.5px; border-radius: 50%; background: var(--c); }

/* Panes ------------------------------------------------------------------- */

.panes { flex: 1; min-height: 0; display: flex; position: relative; background: var(--doc); }
.pane { position: relative; flex: 1 1 0; min-width: 0; min-height: 0; overflow: hidden; }
.pane iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block; background: var(--doc); }
.pane.entering { flex-grow: 0.0001; }
.pane.animate { transition: flex-grow .18s cubic-bezier(.2,.8,.2,1); }
.divider { flex: 0 0 1px; background: var(--divider); position: relative; z-index: 2; }
.divider::before { content: ""; position: absolute; inset: 0 -4px; cursor: col-resize; }
.panes.stacked { flex-direction: column; }
.panes.stacked .divider::before { inset: -4px 0; cursor: row-resize; }

/* Resize handles ---------------------------------------------------------- */

.grip { position: absolute; z-index: 4; touch-action: none; }
.grip--n { top: -3px; left: 12px; right: 12px; height: 7px; cursor: ns-resize; }
.grip--s { bottom: -3px; left: 12px; right: 12px; height: 7px; cursor: ns-resize; }
.grip--e { right: -3px; top: 12px; bottom: 12px; width: 7px; cursor: ew-resize; }
.grip--w { left: -3px; top: 12px; bottom: 12px; width: 7px; cursor: ew-resize; }
.grip--ne { top: -3px; right: -3px; width: 16px; height: 16px; cursor: nesw-resize; }
.grip--sw { bottom: -3px; left: -3px; width: 16px; height: 16px; cursor: nesw-resize; }
.grip--nw { top: -3px; left: -3px; width: 16px; height: 16px; cursor: nwse-resize; }
.grip--se { bottom: -3px; right: -3px; width: 16px; height: 16px; cursor: nwse-resize; }

/* Menus ------------------------------------------------------------------- */

.menu-layer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.menu {
  position: fixed; min-width: 200px; padding: 5px; border-radius: 10px;
  background: var(--menu-bg); color: var(--menu-text);
  -webkit-backdrop-filter: blur(40px) saturate(1.8); backdrop-filter: blur(40px) saturate(1.8);
  box-shadow: var(--menu-edge); pointer-events: auto;
  user-select: none; -webkit-user-select: none;
  max-height: calc(100dvh - 40px); overflow-y: auto;
}
.menu__item {
  display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none;
  height: 24px; padding: 0 10px 0 8px; border-radius: 5px; text-align: left;
  font-size: 13px; cursor: default; white-space: nowrap;
}
a.menu__item { color: inherit; text-decoration: none; }
.menu__item:hover, .menu__item:focus-visible { background: var(--accent); color: #fff; outline: none; }
.menu__item:hover .menu__key, .menu__item:focus-visible .menu__key { color: rgba(255, 255, 255, 0.8); }
.menu__item[aria-disabled="true"] { opacity: .35; pointer-events: none; }
.menu__icon { width: 14px; display: flex; justify-content: center; flex-shrink: 0; }
.menu__label { flex: 1; }
.menu__key { color: var(--menu-dim); padding-left: 24px; letter-spacing: 0.04em; }
.menu__check { width: 12px; flex-shrink: 0; font-size: 12px; }
.menu__sep { height: 1px; margin: 5px 9px; background: var(--sep); }
.menu__head { font-size: 11px; font-weight: 600; color: var(--menu-dim); padding: 6px 10px 3px 8px; }

/* Sheets (alerts and the import dialog) ----------------------------------- */

.sheet-layer {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.18); padding: 16px;
}
.sheet {
  width: min(420px, 100%); border-radius: 16px; padding: 20px; background: var(--sheet-bg);
  box-shadow: var(--menu-edge); color: var(--menu-text);
  display: flex; flex-direction: column; gap: 12px;
}
.sheet--wide { width: min(620px, 100%); }
.sheet h2 { margin: 0; font-size: 13px; font-weight: 700; }
.sheet p { margin: 0; font-size: 12px; line-height: 1.45; color: var(--menu-dim); }
.sheet textarea {
  width: 100%; height: min(320px, 45dvh); resize: vertical; border-radius: 8px; padding: 10px 12px;
  border: 1px solid var(--field-edge); background: var(--field); color: inherit;
  font: 12px/1.5 "SF Mono", ui-monospace, Menlo, monospace; outline: none;
}
.sheet textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.sheet__buttons { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.sheet__buttons .left { margin-right: auto; }
.btn {
  height: 28px; padding: 0 14px; border-radius: 8px; border: 0; cursor: default;
  background: var(--capsule); box-shadow: var(--capsule-edge), 0 0 0 0.5px var(--field-edge); font-size: 13px;
}
.btn:hover { filter: brightness(0.97); }
.btn--primary { background: var(--accent); color: #fff; box-shadow: none; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60; transform: translate(-50%, 12px);
  padding: 8px 14px; border-radius: 10px; font-size: 13px;
  background: var(--menu-bg); color: var(--menu-text); box-shadow: var(--menu-edge);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
  opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }


/* On the home page: the window stays in the layout and moves by an offset. */
.window[data-mm-embed] { position: relative; margin-inline: auto; text-align: left; color: var(--menu-text); z-index: 5; transition: none; }
.window[data-mm-embed].returning { transition: transform .4s cubic-bezier(.3,.7,.2,1); }

@media (prefers-reduced-motion: reduce) {
  .window, .window.animating, .window.returning, .pane.animate { transition: none !important; }
}
