@font-face {
    font-family: "Marauder";
    src: url("../assets/fonts/Marauder-wght.woff2") format("woff2");
    font-weight: 300 900;
    font-style: normal;
    font-display: swap;
  }
  @font-face {
    font-family: "Marauder";
    src: url("../assets/fonts/Marauder-Italic-wght.woff2") format("woff2");
    font-weight: 300 900;
    font-style: italic;
    font-display: swap;
  }

  @font-face {
    font-family: "Drafting";
    src: url("../assets/fonts/DraftingMono-wght.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
  }
  @font-face {
    font-family: "Drafting";
    src: url("../assets/fonts/DraftingMono-Italic-wght.woff2") format("woff2");
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
  }

  @font-face { font-family: "Jost"; src: url("../assets/fonts/Jost-VF.ttf") format("truetype"); font-weight: 100 900; font-style: normal; font-display: swap; }
  @font-face { font-family: "Bodoni"; src: url("../assets/fonts/Bodoni-VF.ttf") format("truetype"); font-weight: 300 900; font-style: normal; font-display: swap; }
  @font-face { font-family: "Bodoni"; src: url("../assets/fonts/Bodoni-Italic-VF.ttf") format("truetype"); font-weight: 300 900; font-style: italic; font-display: swap; }
  @font-face { font-family: "Besley"; src: url("../assets/fonts/Besley-wdth-wght.ttf") format("truetype"); font-weight: 300 900; font-style: normal; font-display: swap; }
  @font-face { font-family: "Drafting"; src: url("../assets/fonts/Drafting-wght.ttf") format("truetype"); font-weight: 300 900; font-style: normal; font-display: swap; }

  :root {
    --font-display: "Marauder", serif;
    --font-body: "Marauder", serif;
    --radius: 0px;
    --surface: rgba(255,255,255,0.7);
    --surface-hover: rgba(255,255,255,0.9);
    --glass: rgba(250,246,238,0.4);
    --highlight: rgba(255,255,255,0.5);
    --bg: #f3eee4;
    --bg-2: #eae3d6;
    --panel: #faf6ee;
    --line: #d9d1c2;
    --text: #2a2218;
    --muted: #6b6256;
    --accent: #9b3d35;
    --danger: #a03030;
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }
  html { height: 100%; height: 100dvh; }
  body { height: 100%; height: 100dvh; }
  body {
    font-family: var(--font-body);
    font-variation-settings: 'opsz' 14;
    font-size: 16px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
  }
  .serif { font-family: var(--font-display); font-variation-settings: 'opsz' 14; }
  button, input, textarea, select { font: inherit; color: inherit; }
  select {
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: max(8px, var(--radius));
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    -webkit-appearance: auto;
    appearance: auto;
    cursor: pointer;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  }
  select:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0,122,255,0.18);
  }
  select option {
    background: var(--panel);
    color: var(--text);
    padding: 8px 12px;
  }

  /* ---- layout ---- */
  .app { display: grid; grid-template-columns: 196px 1fr; height: 100vh; height: 100dvh; }
  .sidebar {
    border-right: 1px solid var(--line);
    background: var(--bg-2);
    display: flex;
    flex-direction: column;
    padding: 12px 8px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 196px;
    min-height: 0;
  }
  .sidebar .logo { margin-bottom: 20px; }
  .sidebar .logo img { height: 32px; width: auto; display: block; }
  .gate-card .logo img { height: 40px; width: auto; display: block; margin-bottom: 8px; }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    line-height: 1;
    text-decoration: none;
    color: var(--muted);
    font-size: 14px;
    border-radius: 0;
    border: 1px solid transparent;
    margin-bottom: 2px;
    cursor: pointer;
    background: transparent;
    text-align: left;
    width: 100%;
  }
  .nav-item svg { width: 16px; height: 16px; flex-shrink: 0; vertical-align: middle; }
  .nav-item { white-space: nowrap; }
  .nav-item:hover { color: var(--text); background: var(--bg); }
  .nav-item.active { color: var(--text); background: var(--panel); border-color: var(--line); }
  .sidebar .section-label { font-size: 11px; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); margin: 18px 0 6px 12px; }
  .search-box { margin: 12px 0 16px; }
  .search-box input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    background: var(--panel);
    font-size: 13px;
  }
  .search-box input:focus { outline: 1px solid var(--text); border-color: var(--text); }
  .main { overflow-y: auto; padding: 32px 40px; }
  .main-inner { max-width: 1200px; margin: 0 auto; }
  #view { transition: opacity .22s ease, transform .22s ease; }
  #view.view-fade { opacity: 0; transform: translateY(6px); }

  /* ---- typography ---- */
  h1 { font-family: var(--font-display); font-weight: 600; font-size: 38px; font-variation-settings: 'opsz' 30; line-height: 1.1; margin-bottom: 8px; }
  h2 { font-family: var(--font-display); font-weight: 600; font-size: 26px; font-variation-settings: 'opsz' 20; margin: 24px 0 8px; }
  h3 { font-family: var(--font-display); font-weight: 600; font-size: 20px; font-variation-settings: 'opsz' 18; margin: 16px 0 4px; }
  .muted { color: var(--muted); }
  .small { font-size: 13px; }

  /* ---- buttons ---- */
  .btn {
    display: inline-block;
    padding: 9px 18px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: max(8px, var(--radius));
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
  }
  .btn:hover { background: rgba(255,255,255,0.9); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
  .btn:active { transform: scale(0.98); }
  .btn-primary { background: #007aff; color: #fff; border-color: #007aff; }
  .btn-primary:hover { background: #0066d6; border-color: #0066d6; }
  .btn-danger { border-color: var(--danger); color: var(--danger); background: rgba(255,255,255,0.7); }
  .btn-danger:hover { background: var(--danger); color: #fff; }
  .btn-sm { padding: 6px 12px; font-size: 13px; }

  /* ---- forms ---- */
  .field { margin-bottom: 16px; }
  .field label { display: block; font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
  .field input, .field textarea, .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: max(8px, var(--radius));
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    -webkit-appearance: none;
    appearance: none;
  }
  .field textarea { min-height: 96px; resize: vertical; line-height: 1.6; }
  .field input:focus, .field textarea:focus, .field select:focus {
    outline: none;
    border-color: #007aff;
    box-shadow: 0 0 0 3px rgba(0,122,255,0.18);
    background: var(--surface-hover);
  }
  .field select {
    padding-right: 12px;
    cursor: pointer;
    -webkit-appearance: menulist;
    appearance: auto;
  }
  .field select option {
    background: var(--panel);
    color: var(--text);
    padding: 8px 12px;
  }

  /* ---- cards / lists ---- */
  .list { display: flex; flex-direction: column; gap: 8px; }
  .card {
    padding: 14px 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
  }
  .card:hover { border-color: var(--text); }
  .card .title { font-family: var(--font-display); font-size: 19px; font-weight: 500; font-variation-settings: 'opsz' 18; }
  .card .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
  .toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
  .toolbar input { padding: 8px 10px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; width: 240px; }

  /* ---- detail ---- */
  .detail-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
  .detail-header h1 { margin-bottom: 4px; }
  .detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .panel { background: var(--panel); border: 1px solid var(--line); padding: 20px; margin-bottom: 20px; }
  .panel h3 { margin-top: 0; }
  .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border: 1px solid var(--line); background: var(--bg);
    font-size: 12px; cursor: pointer;
  }
  .chip:hover { border-color: var(--accent); color: var(--accent); }
  .chip .x { color: var(--muted); }
  .chip .x:hover { color: var(--danger); }
  .empty { color: var(--muted); font-size: 14px; padding: 24px 0; text-align: center; }

  /* ---- version list ---- */
  .versions { max-height: 200px; overflow-y: auto; }
  .version-item { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
  .version-item:last-child { border-bottom: none; }

  /* ---- dashboard ---- */
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 32px; }
  .stat { background: var(--panel); border: 1px solid var(--line); padding: 20px; }
  .stat .num { font-family: var(--font-display); font-size: 44px; font-weight: 600; font-variation-settings: 'opsz' 40; }
  .stat .lbl { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }

  /* ---- export ---- */
  .export-block { background: var(--panel); border: 1px solid var(--line); padding: 24px; margin-bottom: 16px; }
  .export-block h3 { margin-top: 0; }

  /* ---- toast ---- */
  .toast {
    position: fixed; bottom: 24px; right: 24px;
    background: var(--text); color: var(--bg);
    padding: 10px 16px; font-size: 13px;
    border: 1px solid var(--text);
    opacity: 0; transition: opacity .2s; pointer-events: none;
  }
  .toast.show { opacity: 1; }

  /* ---- modal ---- */
  .modal-backdrop {
    position: fixed; inset: 0; background: rgba(42,34,24,0.4);
    display: none; align-items: center; justify-content: center; z-index: 100;
  }
  .modal-backdrop.show { display: flex; }
  .modal { background: var(--panel); border: 1px solid var(--line); border-radius: max(12px, var(--radius)); padding: 24px; width: 480px; max-width: 90vw; max-height: 80vh; overflow-y: auto; backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); box-shadow: 0 24px 64px rgba(0,0,0,0.2); opacity: 0.98; }
  .modal h2 { margin-top: 0; }

  @media (max-width: 760px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .stats { grid-template-columns: 1fr; }
  }

  /* ---- corner radius (bookmark users can choose) ---- */
  body.radius-sharp { --radius: 0px; }
  body.radius-soft { --radius: 12px; }
  body.radius-round { --radius: 24px; }
  .card, .panel, .stat, .feature, .modal, .gate-card, .export-block, .quote, .mockup, .sidebar {
    border-radius: var(--radius);
  }
  .chip, .toast, .search-box input {
    border-radius: var(--radius);
  }
  .glass-specular { border-radius: inherit; }
  body.standalone:not(.no-glass) .sidebar::before,
  body.standalone:not(.no-glass) .card::before,
  body.standalone:not(.no-glass) .panel::before,
  body.standalone:not(.no-glass) .stat::before,
  body.glass-enabled:not(.no-glass) .sidebar::before,
  body.glass-enabled:not(.no-glass) .card::before,
  body.glass-enabled:not(.no-glass) .panel::before,
  body.glass-enabled:not(.no-glass) .stat::before {
    border-radius: inherit;
  }

  /* ---- color themes ---- */
  body.theme-default { --bg:#f3eee4; --bg-2:#eae3d6; --panel:#faf6ee; --line:#d9d1c2; --text:#2a2218; --muted:#6b6256; --accent:#9b3d35; --danger:#a03030; --surface:rgba(255,255,255,0.7); --surface-hover:rgba(255,255,255,0.9); --glass:rgba(250,246,238,0.4); --highlight:rgba(255,255,255,0.5); }
  body.theme-dim { --bg:#d9d4ca; --bg-2:#cdc7bc; --panel:#e2ddd3; --line:#b8b2a6; --text:#2a2520; --muted:#5a5448; --accent:#8a3530; --danger:#a03030; --surface:rgba(255,255,255,0.5); --surface-hover:rgba(255,255,255,0.7); --glass:rgba(226,221,211,0.5); --highlight:rgba(255,255,255,0.3); }
  body.theme-dark { --bg:#0a0a0e; --bg-2:#14141a; --panel:#1e1e26; --line:#3a3a48; --text:#ffffff; --muted:#c0c0cc; --accent:#8ab8ff; --danger:#ff8a8a; --surface:rgba(255,255,255,0.08); --surface-hover:rgba(255,255,255,0.14); --glass:rgba(30,30,38,0.5); --highlight:rgba(255,255,255,0.12); }
  body.theme-ocean { --bg:#eef4f9; --bg-2:#dfe8f2; --panel:#ffffff; --line:#c9d8e8; --text:#1a2a3a; --muted:#5a7a9a; --accent:#2563eb; --danger:#dc2626; --surface:rgba(255,255,255,0.7); --surface-hover:rgba(255,255,255,0.9); --glass:rgba(255,255,255,0.4); --highlight:rgba(255,255,255,0.5); }
  body.theme-forest { --bg:#eef5ee; --bg-2:#dfeadf; --panel:#ffffff; --line:#c9dcc9; --text:#1a2e1a; --muted:#5a7a5a; --accent:#16a34a; --danger:#dc2626; --surface:rgba(255,255,255,0.7); --surface-hover:rgba(255,255,255,0.9); --glass:rgba(255,255,255,0.4); --highlight:rgba(255,255,255,0.5); }
  body.theme-rose { --bg:#fdf0f3; --bg-2:#fce4e9; --panel:#ffffff; --line:#f0c9d4; --text:#2e1a22; --muted:#9a5a6a; --accent:#e11d48; --danger:#dc2626; --surface:rgba(255,255,255,0.7); --surface-hover:rgba(255,255,255,0.9); --glass:rgba(255,255,255,0.4); --highlight:rgba(255,255,255,0.5); }
  body.theme-midnight { --bg:#0e0b1e; --bg-2:#18142e; --panel:#241e3a; --line:#4a4070; --text:#ffffff; --muted:#d0cce0; --accent:#c4a8ff; --danger:#ff9a9a; --surface:rgba(255,255,255,0.08); --surface-hover:rgba(255,255,255,0.14); --glass:rgba(36,30,58,0.5); --highlight:rgba(255,255,255,0.12); }
  body.theme-solar { --bg:#fffbeb; --bg-2:#fef3c7; --panel:#ffffff; --line:#fde68a; --text:#2e2410; --muted:#8a7a40; --accent:#d97706; --danger:#dc2626; --surface:rgba(255,255,255,0.7); --surface-hover:rgba(255,255,255,0.9); --glass:rgba(255,255,255,0.4); --highlight:rgba(255,255,255,0.5); }

  /* ---- font themes ---- */
  body.font-marauder { --font-display: "Marauder", serif; --font-body: "Marauder", serif; }
  body.font-jost { --font-display: "Jost", sans-serif; --font-body: "Jost", sans-serif; }
  body.font-bodoni { --font-display: "Bodoni 11", serif; --font-body: "Bodoni 11", serif; }
  body.font-besley { --font-display: "Besley", serif; --font-body: "Besley", serif; }
  body.font-drafting { --font-display: "Drafting", monospace; --font-body: "Drafting", monospace; }

  /* ---- mobile bottom nav (floating pill) ---- */
  .bottom-nav { display: none; position: relative; }
  .bottom-nav .nav-indicator {
    position: absolute;
    bottom: 4px;
    height: 3px;
    border-radius: 2px;
    background: var(--accent);
    transition: left .25s cubic-bezier(0.2,0.8,0.2,1), width .25s cubic-bezier(0.2,0.8,0.2,1);
    pointer-events: none;
    z-index: 1;
  }
  @media (max-width: 768px) {
    .bottom-nav {
      display: flex;
      position: fixed;
      bottom: calc(4px + env(safe-area-inset-bottom));
      left: 50%;
      transform: translateX(-50%);
      width: auto;
      max-width: calc(100vw - 24px);
      gap: 2px;
      background: var(--panel);
      border: 1px solid var(--line);
      border-radius: 999px;
      padding: 6px 8px;
      z-index: 60;
      box-shadow: 0 8px 24px rgba(42,34,24,0.18);
      backdrop-filter: blur(16px) saturate(160%);
      -webkit-backdrop-filter: blur(16px) saturate(160%);
    }
    .bottom-nav button {
      background: transparent; border: none;
      font-size: 10px; color: var(--muted);
      padding: 6px 10px;
      border-radius: 999px;
      min-width: 44px;
      min-height: 44px;
      display: flex; flex-direction: column; align-items: center; justify-content: center;
      gap: 2px;
    }
    .bottom-nav button svg { width: 22px; height: 22px; display: block; }
    .bottom-nav button span { line-height: 1; font-size: 10px; }
    .bottom-nav button { text-align: center; }
    .bottom-nav button.active { color: var(--text); background: var(--bg-2); }
    .bottom-nav button { transition: color .15s ease, background .15s ease; }
    .main { padding: 16px; padding-bottom: 0; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar input { width: 100%; }
    .btn { padding: 10px 14px; min-height: 44px; }
    h1 { font-size: 26px; }
    .stats { grid-template-columns: 1fr; }
    .features { grid-template-columns: 1fr; }
    .pricing { grid-template-columns: 1fr; }
    .testimonials { grid-template-columns: 1fr; }
    .block { grid-template-columns: 1fr; gap: 24px; }
    .mockup-body { grid-template-columns: 1fr; }
    .footer-grid { grid-template-columns: 1fr 1fr; }
    nav .nav-links { display: none; }
    .modal { width: 92vw; }
  }

  /* ---- liquid glass (standalone / bookmarked app) ---- */
  body.standalone {
    --bg: rgba(243,238,228,0.5);
    --panel: rgba(250,246,238,0.4);
    --line: rgba(217,209,194,0.5);
  }
  body.standalone {
    background: linear-gradient(135deg, #f3eee4 0%, #e8dfcf 50%, #f3eee4 100%);
    background-attachment: fixed;
    padding-top: env(safe-area-inset-top);
  }
  body.standalone:not(.no-glass) .card,
  body.standalone:not(.no-glass) .panel,
  body.standalone:not(.no-glass) .stat,
  body.standalone:not(.no-glass) .feature,
  body.standalone:not(.no-glass) .modal,
  body.standalone:not(.no-glass) .mockup,
  body.glass-enabled:not(.no-glass) .card,
  body.glass-enabled:not(.no-glass) .panel,
  body.glass-enabled:not(.no-glass) .stat,
  body.glass-enabled:not(.no-glass) .feature,
  body.glass-enabled:not(.no-glass) .modal,
  body.glass-enabled:not(.no-glass) .mockup {
    backdrop-filter: blur(40px) saturate(220%) brightness(1.05);
    -webkit-backdrop-filter: blur(40px) saturate(220%) brightness(1.05);
    background-color: var(--glass);
    border-color: rgba(255,255,255,0.3);
    box-shadow:
      0 8px 32px rgba(42,34,24,0.12),
      inset 0 1px 0 var(--highlight),
      inset 0 -1px 0 rgba(42,34,24,0.06);
    position: relative;
    overflow: hidden;
  }
  body.standalone:not(.no-glass) .card::after,
  body.standalone:not(.no-glass) .panel::after,
  body.glass-enabled:not(.no-glass) .card::after,
  body.glass-enabled:not(.no-glass) .panel::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 60%);
    mix-blend-mode: overlay;
  }
  /* sidebar glass without breaking fixed/island positioning */
  body.standalone:not(.no-glass) .sidebar,
  body.glass-enabled:not(.no-glass) .sidebar {
    backdrop-filter: blur(24px) saturate(200%);
    -webkit-backdrop-filter: blur(24px) saturate(200%);
    background-color: var(--panel);
    border-color: rgba(255,255,255,0.35);
  }
  /* bottom nav glass without breaking fixed positioning */
  body.standalone:not(.no-glass) .bottom-nav,
  body.glass-enabled:not(.no-glass) .bottom-nav {
    backdrop-filter: blur(24px) saturate(200%);
    -webkit-backdrop-filter: blur(24px) saturate(200%);
    background-color: var(--panel);
    border-color: rgba(255,255,255,0.35);
  }
  /* specular highlight that follows pointer */
  body.standalone:not(.no-glass) .card::before,
  body.standalone:not(.no-glass) .panel::before,
  body.standalone:not(.no-glass) .stat::before,
  body.glass-enabled:not(.no-glass) .card::before,
  body.glass-enabled:not(.no-glass) .panel::before,
  body.glass-enabled:not(.no-glass) .stat::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at var(--mx,50%) var(--my,50%), rgba(255,255,255,0.35) 0%, transparent 55%);
    opacity: 0.6;
    mix-blend-mode: soft-light;
  }
  /* shimmer animation */
  @keyframes glassShimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
  }
  body.standalone:not(.no-glass) .panel,
  body.glass-enabled:not(.no-glass) .panel {
    background-image: linear-gradient(110deg, transparent 30%, rgba(255,255,255,0.18) 50%, transparent 70%);
    background-size: 200% 100%;
    animation: glassShimmer 6s linear infinite;
  }

/* (sidebar-auto removed; using sidebar-island) */
  .sidebar-trigger {
    display: none;
  }
  /* ---- gate ---- */
.gate {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 300;
}
body:not(.locked) .gate { display: none; }
body.locked .app, body.locked .bottom-nav { display: none; }
.gate-card {
  width: 360px; max-width: 90vw;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 32px;
}
.gate-card .logo { font-family: var(--font-display); font-size: 28px; font-weight: 600; margin-bottom: 4px; }

/* ---- iOS / mobile optimization ---- */
html, body {
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
.app { height: 100%; height: 100dvh; overflow: hidden; }
.main {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}
.sidebar { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.modal { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
button, a, .card, .chip { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, textarea, select { -webkit-tap-highlight-color: transparent; }
/* prevent long-press selection on UI chrome */
.nav-item, .btn, .card { -webkit-user-select: none; user-select: none; }
.field input, .field textarea { -webkit-user-select: text; user-select: text; }
/* smooth momentum + no bounce on gate */
.gate { overscroll-behavior: none; }

/* ---- custom scrollbars (FACET aesthetic) ---- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(42,34,24,0.2) transparent;
}
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background: rgba(42,34,24,0.2);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: rgba(42,34,24,0.35);
  background-clip: padding-box;
}
*::-webkit-scrollbar-corner {
  background: transparent;
}
/* dark themes get lighter scrollbars */
body.theme-dark *, body.theme-midnight * {
  scrollbar-color: rgba(230,230,234,0.25) transparent;
}
body.theme-dark *::-webkit-scrollbar-thumb,
body.theme-midnight *::-webkit-scrollbar-thumb {
  background: rgba(230,230,234,0.25);
  background-clip: padding-box;
}
body.theme-dark *::-webkit-scrollbar-thumb:hover,
body.theme-midnight *::-webkit-scrollbar-thumb:hover {
  background: rgba(230,230,234,0.4);
  background-clip: padding-box;
}

/* ---- ensure no white shows at bottom ---- */
html { background-color: #f3eee4; }
body { background-color: var(--bg); }

/* ---- layout fix: remove fixed body containing block ---- */
html, body {
  height: 100%;
  overflow: hidden;
  background-color: #f3eee4;
}
body {
  position: static;
  margin: 0;
}
.app {
  position: fixed;
  inset: 0;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg);
}
.bottom-nav {
  position: fixed;
  z-index: 60;
}

/* ---- sidebar trigger strip ---- */
.sidebar-trigger {
  display: none;
}
@media (min-width: 769px) {
  body.sidebar-island .sidebar-trigger {
    display: block;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 8px;
    z-index: 65;
    cursor: pointer;
  }
  body.sidebar-island .app { grid-template-columns: 1fr; }
  body.sidebar-island .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 196px;
    height: 100%;
    max-height: 100vh;
    min-height: 0;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 70;
    box-shadow: 4px 0 32px rgba(42,34,24,0.18), inset 1px 0 0 rgba(255,255,255,0.4);
    backdrop-filter: blur(40px) saturate(220%) brightness(1.05);
    -webkit-backdrop-filter: blur(40px) saturate(220%) brightness(1.05);
    background-color: rgba(250,246,238,0.35);
    border-right: 1px solid rgba(255,255,255,0.25);
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }
  body.sidebar-island .sidebar::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 50%, rgba(255,255,255,0.1) 100%);
    mix-blend-mode: overlay;
  }
  body.sidebar-island.sidebar-revealed .sidebar {
    transform: translateX(0);
  }
}

/* ---- UI MODE: TILES (iOS Shortcuts-style, no sidebar) ---- */
body.uimode-tiles {
  --font-display: -apple-system, "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-body: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 16px;
  --bg: #f2f2f7;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --line: #e5e5ea;
  --text: #000000;
  --muted: #8e8e93;
  --accent: #007aff;
  --danger: #ff3b30;
}
body.uimode-tiles .app { grid-template-columns: 1fr; }
body.uimode-tiles .sidebar { display: none; }
body.uimode-tiles .main { background: #f2f2f7; padding: 20px 16px; padding-bottom: 100px; }
body.uimode-tiles .main-inner { max-width: 100%; }
/* top bar */
body.uimode-tiles .tiles-topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; padding: 0 4px;
}
body.uimode-tiles .tiles-topbar h1 {
  font-size: 34px; font-weight: 700; margin: 0;
  letter-spacing: -0.5px;
}
body.uimode-tiles .tiles-search {
  width: 100%; padding: 12px 16px; border: none;
  border-radius: 12px; background: rgba(118,118,128,0.12);
  font-size: 17px; margin-bottom: 16px; outline: none;
  font-family: inherit;
}
body.uimode-tiles .tiles-search:focus { background: rgba(118,118,128,0.18); }
/* category chips */
body.uimode-tiles .tiles-chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 0 4px 12px;
  scrollbar-width: none;
}
body.uimode-tiles .tiles-chips::-webkit-scrollbar { display: none; }
body.uimode-tiles .tiles-chip {
  padding: 8px 16px; border-radius: 20px; border: none;
  background: rgba(118,118,128,0.12); color: #000;
  font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer;
  font-family: inherit;
}
body.uimode-tiles .tiles-chip.active {
  background: #007aff; color: #fff;
}
/* grid of tiles */
body.uimode-tiles .tiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 14px;
  padding: 0 4px;
}
@media (min-width: 480px) {
  body.uimode-tiles .tiles-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 16px; }
}
body.uimode-tiles .tile {
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  padding: 14px;
  display: flex; flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform .15s ease, opacity .15s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
body.uimode-tiles .tile:active { transform: scale(0.96); }
body.uimode-tiles .tile .tile-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}
body.uimode-tiles .tile .tile-icon svg { width: 28px; height: 28px; stroke: #fff; }
body.uimode-tiles .tile .tile-label {
  font-size: 13px; font-weight: 600; color: #fff;
  line-height: 1.2; text-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
body.uimode-tiles .tile .tile-sub {
  font-size: 11px; color: rgba(255,255,255,0.85);
}
/* tile colors by type */
body.uimode-tiles .tile-story { background: linear-gradient(135deg, #007aff, #0051d5); }
body.uimode-tiles .tile-character { background: linear-gradient(135deg, #af52de, #8944ab); }
body.uimode-tiles .tile-world { background: linear-gradient(135deg, #34c759, #248a3d); }
body.uimode-tiles .tile-plotline { background: linear-gradient(135deg, #ff9500, #cc7700); }
body.uimode-tiles .tile-file { background: linear-gradient(135deg, #5ac8fa, #2a9fd6); }
body.uimode-tiles .tile-writing { background: linear-gradient(135deg, #ff2d55, #cc2444); }
body.uimode-tiles .tile-generic { background: linear-gradient(135deg, #8e8e93, #636366); }
/* floating action button */
body.uimode-tiles .tiles-fab {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px; width: 56px; height: 56px; border-radius: 28px;
  background: #007aff; color: #fff; border: none;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,122,255,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}
body.uimode-tiles .tiles-fab:active { transform: scale(0.94); }
/* section header */
body.uimode-tiles .tiles-section {
  font-size: 22px; font-weight: 700; margin: 24px 4px 12px;
  letter-spacing: -0.3px;
}
body.uimode-tiles .tiles-empty {
  text-align: center; padding: 60px 20px; color: #8e8e93;
}
body.uimode-tiles .tiles-empty h3 { color: #000; font-size: 20px; margin-bottom: 8px; }
/* hide default sidebar/nav in tiles mode */
body.uimode-tiles .sidebar { display: none; }
body.uimode-tiles .app { grid-template-columns: 1fr; }
body.uimode-tiles .bottom-nav { display: none; }
body.uimode-tiles .main { padding: 16px; padding-bottom: 100px; }
/* details panel (slide-in from right) */
body.uimode-tiles .tiles-detail {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 360px; max-width: 90vw;
  background: #fff; box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  transform: translateX(100%); transition: transform .25s ease;
  z-index: 80; padding: 24px; overflow-y: auto;
}
body.uimode-tiles .tiles-detail.open { transform: translateX(0); }
body.uimode-tiles .tiles-detail-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3);
  display: none; z-index: 79;
}
body.uimode-tiles .tiles-detail-backdrop.open { display: block; }

/* ---- UI MODE: TILES (Shortcuts-style, no sidebar, completely different) ---- */
body.uimode-tiles {
  --font-display: -apple-system, "SF Pro Display", "Helvetica Neue", sans-serif;
  --font-body: -apple-system, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 16px;
  --bg: #f2f2f7;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --line: #e5e5ea;
  --text: #000000;
  --muted: #8e8e93;
  --accent: #007aff;
  --danger: #ff3b30;
}
body.uimode-tiles .app { grid-template-columns: 1fr; }
body.uimode-tiles .sidebar { display: none; }
body.uimode-tiles .main { background: #f2f2f7; padding: 16px; padding-bottom: 100px; }
body.uimode-tiles .main-inner { max-width: 100%; }
body.uimode-tiles .list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
body.uimode-tiles .card {
  aspect-ratio: 1 / 1;
  border-radius: 22px;
  padding: 14px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform .15s ease, box-shadow .15s ease;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  background: linear-gradient(135deg, #8e8e93, #636366);
}
body.uimode-tiles .card:hover { transform: translateY(-4px) scale(1.02); box-shadow: 0 12px 28px rgba(0,0,0,0.15); }
body.uimode-tiles .card:active { transform: scale(0.96); }
body.uimode-tiles .card .title { font-size: 15px; font-weight: 600; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.2); line-height: 1.2; }
body.uimode-tiles .card .sub { font-size: 11px; color: rgba(255,255,255,0.85); }
body.uimode-tiles .card .btn { display: none; }
body.uimode-tiles .card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.25) 0%, transparent 60%);
  pointer-events: none;
}
body.uimode-tiles .card[data-type="story"] { background: linear-gradient(135deg, #007aff, #0051d5); }
body.uimode-tiles .card[data-type="character"] { background: linear-gradient(135deg, #af52de, #8944ab); }
body.uimode-tiles .card[data-type="world"] { background: linear-gradient(135deg, #34c759, #248a3d); }
body.uimode-tiles .card[data-type="plotline"] { background: linear-gradient(135deg, #ff9500, #cc7700); }
body.uimode-tiles .card[data-type="file"] { background: linear-gradient(135deg, #5ac8fa, #2a9fd6); }
body.uimode-tiles .card[data-type="generic"] { background: linear-gradient(135deg, #8e8e93, #636366); }
body.uimode-tiles .btn {
  padding: 12px 20px; font-size: 16px; border-radius: 14px; min-height: 48px;
  font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
body.uimode-tiles h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
body.uimode-tiles h2 { font-size: 22px; }
body.uimode-tiles h3 { font-size: 18px; }
body.uimode-tiles .stat { border-radius: 18px; padding: 20px; text-align: center; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
body.uimode-tiles .stat .num { font-size: 40px; font-weight: 700; }
body.uimode-tiles .stat .lbl { font-size: 12px; color: #8e8e93; }
body.uimode-tiles .panel { background: #fff; border-radius: 18px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border: none; }
body.uimode-tiles .field input, body.uimode-tiles .field textarea, body.uimode-tiles .field select { padding: 12px 14px; font-size: 16px; border-radius: 12px; border: none; background: rgba(118,118,128,0.12); }
body.uimode-tiles .field input:focus, body.uimode-tiles .field textarea:focus, body.uimode-tiles .field select:focus { background: rgba(118,118,128,0.18); outline: none; }
body.uimode-tiles .modal { border-radius: 20px; }
body.uimode-tiles .toast { border-radius: 14px; font-size: 15px; padding: 12px 18px; }
body.uimode-tiles .bottom-nav { display: none; }
body.uimode-tiles .toolbar { margin-bottom: 16px; }
body.uimode-tiles .search-box { display: none; }
/* floating add button */
body.uimode-tiles .tiles-fab {
  position: fixed; bottom: calc(20px + env(safe-area-inset-bottom));
  right: 20px; width: 56px; height: 56px; border-radius: 28px;
  background: #007aff; color: #fff; border: none;
  font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,122,255,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}
body.uimode-tiles .tiles-fab:active { transform: scale(0.94); }

/* ---- UI MODE: FILES (modern desktop file explorer) ---- */
body.uimode-files {
  --font-display: "Drafting", monospace;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  font-size: 13px;
  --bg: #f5f7fa;
  --bg-2: #ebedf2;
  --panel: #ffffff;
  --line: #dfe3ea;
  --text: #1a1f2e;
  --muted: #6b7280;
  --accent: #2563eb;
}
body.uimode-files .app { grid-template-columns: 220px 1fr; }
body.uimode-files .sidebar { background: #f0f2f5; border-right: 1px solid #dfe3ea; padding: 8px 4px; }
/* island mode in files theme */
body.uimode-files.sidebar-island .app { grid-template-columns: 1fr; }
body.uimode-files.sidebar-island .sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 220px;
  transform: translateX(-100%);
  transition: transform .3s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: 70;
  box-shadow: 4px 0 32px rgba(0,0,0,0.18);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background-color: rgba(240,242,245,0.85);
  border-right: 1px solid rgba(223,227,234,0.6);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  height: 100%;
  max-height: 100vh;
}
body.uimode-files.sidebar-island.sidebar-revealed .sidebar {
  transform: translateX(0);
}
body.uimode-files .sidebar .logo { padding: 8px 12px; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: #1a1f2e; }
body.uimode-files .nav-item { border-radius: 4px; margin: 1px 4px; }
body.uimode-files .nav-item.active { background: #2563eb; color: #fff; }
body.uimode-files .nav-item.active svg { stroke: #fff; }
body.uimode-files .main { background: #ffffff; }
body.uimode-files .card { border-bottom: 1px solid #f0f2f5; }
body.uimode-files .card:hover { background: #f5f7fa; }
body.uimode-files .toolbar { border-bottom: 1px solid #dfe3ea; padding-bottom: 8px; margin-bottom: 8px; }
body.uimode-files .panel { background: #f9fafb; border: 1px solid #e5e7eb; }
body.uimode-files .btn-primary { background: #2563eb; border-color: #2563eb; color: #fff; }
body.uimode-files .btn-primary:hover { background: #1d4ed8; }
body.uimode-files .bottom-nav { background: #1a1f2e; border: none; }
body.uimode-files .bottom-nav button { color: #9ca3af; }
body.uimode-files .bottom-nav button.active { color: #fff; background: #2563eb; }
body.uimode-files .bottom-nav button svg { stroke: #9ca3af; }
body.uimode-files .bottom-nav button.active svg { stroke: #fff; }
body.uimode-files .nav-indicator { background: #2563eb; }
body.uimode-files .card {
  padding: 4px 8px;
  border-radius: 4px;
  gap: 8px;
  border: 1px solid transparent;
  background: transparent;
}
body.uimode-files .card:hover { background: #ebedf2; border-color: #dfe3ea; }
body.uimode-files .card .title { font-size: 13px; font-weight: 400; }
body.uimode-files .card .sub { font-size: 11px; color: #6b7280; }
body.uimode-files .btn { padding: 4px 10px; font-size: 12px; border-radius: 4px; }
body.uimode-files h1 { font-size: 20px; font-weight: 600; }
body.uimode-files h2 { font-size: 15px; }
body.uimode-files h3 { font-size: 14px; }
body.uimode-files .nav-item { padding: 5px 8px; font-size: 12px; gap: 8px; border-radius: 4px; }
body.uimode-files .nav-item svg { width: 14px; height: 14px; }
body.uimode-files .stat { border-radius: 6px; padding: 12px; }
body.uimode-files .stat .num { font-size: 22px; font-weight: 600; }
body.uimode-files .stat .lbl { font-size: 10px; }
body.uimode-files .list { gap: 1px; }
body.uimode-files .main { padding: 12px 16px; }
body.uimode-files .panel { padding: 12px; margin-bottom: 8px; border-radius: 6px; }
body.uimode-files .field { margin-bottom: 8px; }
body.uimode-files .field input, body.uimode-files .field textarea, body.uimode-files .field select { padding: 5px 8px; font-size: 13px; border-radius: 4px; }
body.uimode-files .modal { border-radius: 8px; }
body.uimode-files .toast { border-radius: 4px; font-size: 12px; }
body.uimode-files .bottom-nav { border-radius: 8px; }
body.uimode-files .bottom-nav button { min-width: 40px; min-height: 40px; font-size: 9px; border-radius: 4px; }
body.uimode-files .bottom-nav button svg { width: 18px; height: 18px; }
body.uimode-files .toolbar { gap: 6px; }
body.uimode-files .chip { border-radius: 4px; font-size: 11px; padding: 2px 8px; }

/* ---- EXTREME MOBILE FRIENDLY ---- */
@media (max-width: 768px) {
  html, body { font-size: 17px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 12px; padding-bottom: 0; }
  .main-inner { max-width: 100%; }
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar input { width: 100%; font-size: 16px; padding: 12px; }
  .btn { min-height: 48px; padding: 12px 18px; font-size: 16px; }
  .field input, .field textarea, .field select { font-size: 16px; padding: 12px; }
  .card { padding: 16px; }
  .card .title { font-size: 18px; }
  .panel { padding: 16px; }
  h1 { font-size: 28px; }
  h2 { font-size: 22px; }
  h3 { font-size: 18px; }
  .stat { padding: 16px; }
  .stat .num { font-size: 36px; }
  .modal { width: 94vw; max-height: 85vh; padding: 18px; }
  .gate-card { width: 92vw; padding: 24px; }
  .bottom-nav { padding: 8px 12px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .bottom-nav button { min-width: 52px; min-height: 52px; font-size: 11px; }
  .bottom-nav button svg { width: 24px; height: 24px; }
  .nav-indicator { height: 3px; }
  /* prevent text selection on UI */
  .card, .btn, .nav-item { -webkit-user-select: none; user-select: none; }
  /* smooth scrolling */
  .main { -webkit-overflow-scrolling: touch; }
  /* safe areas */
  body { padding-top: env(safe-area-inset-top); }
}

/* ---- sidebar scrollable nav ---- */
.sidebar-nav {
  flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0;
  -webkit-overflow-scrolling: touch;
  direction: rtl;
}
.sidebar-nav > * { direction: ltr; }
/* discreet scrollbar */
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); }
.sidebar-nav { scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.15) transparent; }

/* ---- files mode folder tree ---- */
body.uimode-files .folder-tree { font-size: 13px; }
body.uimode-files .folder-tree span { cursor: pointer; }
body.uimode-files .folder-tree span:hover { color: var(--accent); }
body.uimode-files .breadcrumb .crumb:hover { text-decoration: underline; }

/* ---- TILES NAV (iOS-style bottom tab bar) ---- */
.tiles-nav {
  display: none;
}
body.uimode-tiles .tiles-nav {
  display: flex;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(242,242,247,0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid rgba(60,60,67,0.12);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 60;
  justify-content: space-around;
  align-items: center;
}
body.uimode-tiles .tiles-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; cursor: pointer;
  color: #8e8e93; font-size: 10px; font-weight: 500;
  padding: 4px 12px; border-radius: 8px;
  min-width: 48px; min-height: 44px;
  transition: color .15s ease;
}
body.uimode-tiles .tiles-nav button svg {
  width: 24px; height: 24px; stroke: #8e8e93;
  transition: stroke .15s ease;
}
body.uimode-tiles .tiles-nav button.active { color: #007aff; }
body.uimode-tiles .tiles-nav button.active svg { stroke: #007aff; }
