/* ------------------------------------------------------------------ */
/* MAPANDU — NEOBRUTALISM                                              */
/* Ink borders, hard offset shadows, saturated flat pops, no gradients. */
/* ------------------------------------------------------------------ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --color-bg-body: #f4f0ff;
  --color-bg-primary: #ffffff;
  --color-border: #111111;
  --color-text-dark: #111111;
  --color-text-mid: #4b4b4b;
  --color-text-light: #7a7a7a;
  --color-on-accent: #111111; /* Text on the pops — stays ink in both themes */
  --color-panel: #f0eafd;
  --color-code-bg: #f1edfb;

  /* Names kept so mdpreview keeps working; values retuned to saturated pops. */
  --pastel-lavender: #a388ee;
  --pastel-mint: #7fbc8c;
  --pastel-peach: #ff7a5c;
  --pastel-sky: #69d2e7;
  --pastel-yellow: #f4d738;
  --pastel-pink: #ffb2ef;
  --pastel-danger: #ff6b6b;

  --focus: #6d28d9;

  --border-thickness: 3px;
  --border-radius-primary: 12px;
  --shadow-sm: 3px 3px 0 0 var(--color-border);
  --shadow-md: 6px 6px 0 0 var(--color-border);

  --font-mono: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', Consolas, 'Courier New', monospace;

  --sidebar-w: 250px;
  --peek-w: 200px;
}

/* DARK MODE — dark surfaces, off-white borders, same saturated pops. */
[data-theme="dark"] {
  --color-bg-body: #14161f;
  --color-bg-primary: #1e212c;
  --color-border: #e6e9f5;
  --color-text-dark: #eceefa;
  --color-text-mid: #b0b6cf;
  --color-text-light: #838aa6;
  --color-panel: #272b39;
  --color-code-bg: #191c26;

  /* Nudged lighter so ink text on a pop still clears 4.5:1. */
  --pastel-lavender: #b39dfa;
  --pastel-mint: #8fd39d;
  --pastel-peach: #ff9070;
  --pastel-sky: #7fdcef;
  --pastel-yellow: #f6de55;
  --pastel-pink: #ffc2f3;
  --pastel-danger: #ff8b8b;

  --focus: #b39dfa;
}

html { height: 100%; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--color-bg-body);
  color: var(--color-text-dark);
  min-height: 100vh;
}

.hidden { display: none !important; }
/* Beats any per-panel display rule, whatever its specificity. */
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ------------------------------------------------------------------ */
/* SHELL — fixed sidebar, main fills the rest                           */
/* ------------------------------------------------------------------ */

body.shell {
  height: 100dvh;
  overflow: hidden;
  border: var(--border-thickness) solid var(--color-border);
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 60;
  width: var(--sidebar-w);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--color-bg-primary);
  border-right: var(--border-thickness) solid var(--color-border);
  visibility: visible;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}

/* The extra 24px clears the active tab's overhang; visibility drops the
   off-screen links out of the tab order. */
body.nav-closed .sidebar {
  transform: translateX(calc(-100% - 24px));
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s 0.28s;
}

.brand { padding: 26px 20px 22px; text-align: center; }
.brand h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1;
}
.brand p {
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--color-text-light);
}

/* ---- Nav ---- */
/* No overflow here: a scroll container would clip the active tab's overhang. */
.nav { display: flex; flex-direction: column; gap: 14px; padding-bottom: 14px; }

.nav-item {
  position: relative;
  display: block;
  padding: 18px 12px;
  background: var(--pastel-yellow);
  border-top: var(--border-thickness) solid var(--color-border);
  border-bottom: var(--border-thickness) solid var(--color-border);
  color: var(--color-on-accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}
.nav-item:nth-child(2) { background: var(--pastel-sky); }
.nav-item:nth-child(3) { background: var(--pastel-mint); }
.nav-item:nth-child(4) { background: var(--pastel-pink); }
.nav-item:nth-child(5) { background: var(--pastel-lavender); }
.nav-item:nth-child(6) { background: var(--pastel-peach); }

.nav-item:not(.active):hover { filter: brightness(0.94); }
.nav-item:not(.active):active { transform: translateX(3px); }

/* Active tab pushes past the sidebar edge and folds under it. */
.nav-item.active {
  width: calc(100% + 22px);
  border-right: var(--border-thickness) solid var(--color-border);
  font-weight: 700;
  z-index: 2;
}
.nav-item.active::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -15px;
  width: 0;
  height: 0;
  border-top: 15px solid var(--color-border);
  border-right: 22px solid transparent;
}

.nav-tag {
  display: block;
  margin-top: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.5px;
  opacity: 0.62;
}

/* ---- Sidebar footer ---- */
.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--pastel-yellow);
  border-top: var(--border-thickness) solid var(--color-border);
}
.sidebar-foot .year { flex: 1; font-size: 14px; color: var(--color-on-accent); }

/* ---- Main ---- */
.main {
  height: 100dvh;
  margin-left: var(--sidebar-w);
  overflow-y: auto;
  transition: margin-left 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
body.nav-closed .main { margin-left: 0; }

/* ---- Show Sidebar pill (bottom-left) ---- */
.nav-peek {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 15px;
  border: var(--border-thickness) solid var(--color-border);
  border-radius: 10px;
  background: var(--pastel-lavender);
  color: var(--color-on-accent);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s, box-shadow 0.18s, opacity 0.18s;
}
/* Bottom-left on home; on a tool it sits in the gutter the tool leaves for it. */
body.tool-open .nav-peek { top: 12px; left: 16px; bottom: auto; }

.nav-peek svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.nav-peek:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
.nav-peek:active { transform: translate(3px, 3px); box-shadow: none; }

/* Nothing to show while the sidebar is open. */
body:not(.nav-closed) .nav-peek {
  opacity: 0;
  transform: translateX(-130%);
  visibility: hidden;
  transition: transform 0.18s, opacity 0.18s, visibility 0s 0.18s;
}

/* ------------------------------------------------------------------ */
/* TOOL PAGES — chrome every tool under public/<name>/ shares           */
/* ------------------------------------------------------------------ */

body.tool { height: 100%; overflow: hidden; }

.app { display: flex; flex-direction: column; height: 100%; }

.topbar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  /* One height for every tool: a bar with no buttons would otherwise collapse
     shorter than the shell's floating Show Sidebar button. */
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: var(--border-thickness) solid var(--color-border);
  background: var(--color-bg-primary);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-title { font-size: 16px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; }

/* Inside the shell the parent supplies the back link and the theme toggle,
   and leaves --peek-w of room for its floating Show Sidebar button. */
.framed .btn-back, .framed #themeSlot { display: none; }
.framed .topbar-left { padding-left: var(--peek-w); }

/* ---- Form controls ---- */
.field {
  padding: 10px 12px;
  border: var(--border-thickness) solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-primary);
  color: var(--color-text-dark);
  font-family: inherit;
  font-size: 13px;
  min-width: 0;
}
.field::placeholder { color: var(--color-text-light); }

.btn-danger  { background: var(--pastel-danger); color: var(--color-on-accent); }
.btn-accent  { background: var(--pastel-mint);   color: var(--color-on-accent); }
.btn-quiet   { background: var(--color-panel);   color: var(--color-text-dark); }

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  padding: 11px 14px;
  border: var(--border-thickness) solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-primary);
  color: var(--color-text-dark);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.1s;
  white-space: nowrap;
}
.btn:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); filter: brightness(0.97); }
.btn:active { transform: translate(3px, 3px); box-shadow: none; filter: none; }

.btn-back   { background: var(--pastel-sky);    color: var(--color-on-accent); }
.btn-import { background: var(--pastel-yellow); color: var(--color-on-accent); }
.btn-export { background: var(--pastel-peach);  color: var(--color-on-accent); }

/* Square icon button used in the sidebar footer. */
.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: var(--border-thickness) solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-primary);
  color: var(--color-text-dark);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s, box-shadow 0.1s;
}
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); }
.icon-btn:active { transform: translate(2px, 2px); box-shadow: none; }

/* ---- Panels ---- */
/* No max-width: a panel fills the arena it sits in. */
.panel { padding: 34px clamp(20px, 5vw, 56px) 96px; }

/* A real tool gets the bare arena. */
.panel.panel-tool { height: 100%; padding: 0; }
.tool-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--color-bg-primary);
}

/* Clear the top-left Show Sidebar button when it is on screen. */
body.tool-open.nav-closed .panel:not(.panel-tool) { padding-top: 64px; }

/* Home is just a line of text centred in the arena. */
.panel.panel-home {
  padding: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
}
.arena-note {
  font-size: clamp(15px, 2.4vw, 20px);
  letter-spacing: 1px;
  text-align: center;
  color: var(--color-text-mid);
}

/* ------------------------------------------------------------------ */
/* RESPONSIVE — sidebar becomes an overlay drawer                       */
/* ------------------------------------------------------------------ */

@media (max-width: 860px) {
  body.shell { border: none; }

  .main { margin-left: 0; }
  .panel { padding: 26px 18px 100px; }

  /* Overlay instead of push, so content never reflows behind the drawer. */
  .sidebar { width: min(84vw, var(--sidebar-w)); box-shadow: var(--shadow-md); }

  .nav-item.active { width: 100%; border-right: none; }
  .nav-item.active::after { display: none; }

  .scrim {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(17, 17, 17, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s;
  }
  body:not(.nav-closed) .scrim { opacity: 1; pointer-events: auto; }
}

@media (min-width: 861px) {
  .scrim { display: none; }
}

/* Too narrow for the label: the button falls back to its icon. */
@media (max-width: 640px) {
  :root { --peek-w: 66px; }
  body.tool-open .nav-peek { padding: 11px; }
  body.tool-open .peek-label { display: none; }
}

/* Short viewport (landscape phone): scroll the nav and drop the overhang,
   otherwise the footer and its theme toggle fall off the bottom. */
@media (max-height: 580px) {
  .nav { overflow-y: auto; }
  .nav-item { padding: 13px 12px; }
  .nav-item.active { width: 100%; border-right: none; }
  .nav-item.active::after { display: none; }
  .brand { padding: 16px 20px 14px; }
  .brand h1 { font-size: 22px; }
}

/* ---- Page load / navigation motion ---- */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: 160ms ease-in both fade-out; }
::view-transition-new(root) { animation: 260ms ease-out both fade-in; }

@keyframes fade-out { to { opacity: 0; transform: translateY(-8px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

.panel:not([hidden]), .app { animation: rise 240ms ease-out both; }

/* ---- Theme toggle (injected by theme.js) ---- */
.theme-toggle {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 11px;
  border: var(--border-thickness) solid var(--color-border);
  border-radius: var(--border-radius-primary);
  background: var(--pastel-lavender);
  color: var(--color-on-accent);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s, box-shadow 0.1s, filter 0.1s;
}
.theme-toggle.inline {
  position: static;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 8px;
  flex-shrink: 0;
}
.theme-toggle:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-md); filter: brightness(0.97); }
.theme-toggle:active { transform: translate(3px, 3px); box-shadow: none; filter: none; }
.theme-toggle svg { width: 17px; height: 17px; stroke: var(--color-on-accent); fill: none; stroke-width: 2.2; stroke-linecap: round; }
[data-theme="light"] .moon, [data-theme="dark"] .sun { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .panel, .app { animation: none; }
  .btn:hover, .btn:active, .icon-btn:hover, .icon-btn:active,
  .nav-peek:hover, .nav-peek:active,
  .theme-toggle:hover, .theme-toggle:active { transform: none; }
}
