:root{
    --ink:#2A2333;
    --ink-soft:#6E6178;
    --bg:#E4E9DA;
    --card:#F1EEF3;
    --border:#C9C3CE;
    --plum:#5C3A72;
    --plum-dark:#472C59;
    --forest:#3E6B49;
    --sage:#8FAF7C;
    --lilac:#9B7EC0;
    --violet:#8B5FA3;
    --wine:#7A2F4B;
  }
  *{box-sizing:border-box;}
  body{
    margin:0;
    background:var(--bg);
    color:var(--ink);
    font-family:'Work Sans', sans-serif;
    -webkit-font-smoothing:antialiased;
  }
  h1,h2,.serif{ font-family:'Fraunces', serif; }
  .wrap{ max-width:980px; margin:0 auto; padding:32px 20px 60px; }
  header.app-header{ display:flex; flex-wrap:wrap; align-items:flex-end; justify-content:space-between; gap:12px; margin-bottom:28px; }
  header.app-header h1{ font-size:1.9rem; font-weight:700; margin:0; letter-spacing:-0.01em; }
  header.app-header p{ margin:4px 0 0; color:var(--ink-soft); font-size:0.92rem; }
  .reset-btn{ background:none; border:none; color:var(--ink-soft); font-size:0.75rem; cursor:pointer; display:inline-flex; align-items:center; gap:5px; }
  .reset-btn:hover{ color:var(--wine); }

  nav.tabs{ display:flex; gap:20px; border-bottom:1px solid var(--border); margin-bottom:26px; flex-wrap:wrap; }
  nav.tabs button{
    background:none; border:none; cursor:pointer; padding-bottom:10px; margin-bottom:-1px;
    font-family:inherit; font-size:0.9rem; font-weight:500; color:var(--ink-soft);
    display:inline-flex; align-items:center; gap:6px; border-bottom:2px solid transparent;
  }
  nav.tabs button.active{ color:var(--plum); border-bottom-color:var(--plum); }
  .icon{ width:15px; height:15px; display:inline-block; vertical-align:-3px; }

  .btn{ display:inline-flex; align-items:center; gap:6px; border-radius:7px; font-weight:500; font-size:0.85rem; padding:8px 14px; cursor:pointer; border:1px solid transparent; font-family:inherit; }
  .btn-primary{ background:var(--plum); color:#fff; }
  .btn-primary:hover{ background:var(--plum-dark); }
  .btn-ghost{ background:none; border-color:var(--border); color:var(--ink-soft); }
  .btn-small{ padding:5px 10px; font-size:0.75rem; }

  .card{ background:var(--card); border:1px solid var(--border); border-radius:10px; padding:16px; }
  .empty{ border:1px dashed var(--border); border-radius:10px; padding:34px 20px; text-align:center; display:flex; flex-direction:column; align-items:center; gap:10px; }
  .empty p.title{ font-family:'Fraunces',serif; font-weight:600; margin:0; }
  .empty p.body{ font-size:0.88rem; color:var(--ink-soft); max-width:420px; margin:0; }

  label.field{ display:flex; flex-direction:column; gap:4px; font-size:0.85rem; color:var(--ink-soft); }
  input,select,textarea{
    font-family:inherit; font-size:0.87rem; padding:7px 10px; border-radius:6px; border:1px solid var(--border);
    background:rgba(255,255,255,0.6); color:var(--ink);
  }
  input:focus,select:focus,textarea:focus{ outline:2px solid var(--lilac); outline-offset:1px; }
  input[type="color"]{ padding:2px; width:48px; height:36px; }

  .form-grid{ display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:14px; margin-bottom:20px; }
  .form-grid .span2{ grid-column:1/-1; }
  @media (max-width:640px){ .form-grid{ grid-template-columns:1fr; } }

  .stat-grid{ display:grid; grid-template-columns:repeat(6,minmax(0,1fr)); gap:10px; margin-bottom:22px; }
  @media (max-width:820px){ .stat-grid{ grid-template-columns:repeat(3,minmax(0,1fr)); } }
  @media (max-width:460px){ .stat-grid{ grid-template-columns:repeat(2,minmax(0,1fr)); } }
  .stat-tile p.label{ margin:0; font-size:0.72rem; color:var(--ink-soft); }
  .stat-tile p.value{ margin:2px 0 0; font-size:1.25rem; font-weight:700; font-family:'Fraunces',serif; }
  .stat-tile p.sub{ margin:2px 0 0; font-size:0.7rem; color:var(--ink-soft); }

  .chart-grid{ display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:18px; margin-bottom:20px; }
  @media (max-width:760px){ .chart-grid{ grid-template-columns:1fr; } }
  .chart-card p.chart-title{ margin:0 0 10px; font-size:0.88rem; font-weight:500; }
  .chart-holder{ position:relative; height:230px; }

  .yarn-grid{ display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:14px; }
  @media (max-width:900px){ .yarn-grid{ grid-template-columns:minmax(0,1fr) minmax(0,1fr); } }
  @media (max-width:560px){ .yarn-grid{ grid-template-columns:minmax(0,1fr); } }
  .yarn-card{ position:relative; padding:16px 14px 14px; padding-top:20px; min-width:0; }
  .yarn-hole{ position:absolute; top:10px; left:10px; width:11px; height:11px; border-radius:50%; background:var(--bg); border:1px solid var(--border); }
  .yarn-top{ display:flex; align-items:flex-start; justify-content:space-between; gap:8px; padding-left:12px; }
  .yarn-swatch-name{ display:flex; align-items:center; gap:10px; min-width:0; }
  .swatch{ width:28px; height:28px; border-radius:50%; flex-shrink:0; border:1px solid var(--border); }
  .yarn-name{ font-family:'Fraunces',serif; font-weight:600; margin:0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .yarn-sub{ font-size:0.75rem; color:var(--ink-soft); margin:1px 0 0; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .del-btn{ background:none; border:none; color:var(--ink-soft); cursor:pointer; padding:2px; }
  .del-btn:hover{ color:var(--wine); }
  .yarn-meta{ margin-top:12px; padding-top:9px; border-top:2px dashed var(--border); display:flex; justify-content:space-between; font-size:0.72rem; color:var(--ink-soft); }
  .yarn-bottom{ margin-top:9px; display:flex; justify-content:space-between; align-items:center; font-size:0.85rem; }
  .yarn-bottom input[type=number]{ width:56px; border:none; border-bottom:1px solid var(--border); background:transparent; padding:2px 0; border-radius:0; }

  .swatch-row{ display:flex; gap:8px; margin-top:8px; }
  .swatch-btn{ width:26px; height:26px; border-radius:50%; cursor:pointer; border:1px solid var(--border); }
  .swatch-btn.selected{ border:2px solid var(--ink); }

  .photo-dropzone{ border:1px dashed var(--border); border-radius:10px; padding:14px 16px; width:100%; max-width:200px; margin:0 auto; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:6px; text-align:center; transition:background 0.15s, border-color 0.15s; }
  .photo-dropzone-lg{ max-width:400px; padding:28px 32px; gap:10px; }
  .photo-dropzone.dragover{ background:rgba(92,58,114,0.08); border-color:var(--plum); }

  .photo-thumb-row{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:8px; }
  .photo-thumb{ position:relative; width:70px; height:70px; border-radius:8px; overflow:hidden; border:1px solid var(--border); flex-shrink:0; }
  .photo-thumb img{ width:100%; height:100%; object-fit:cover; display:block; }
  .photo-thumb-remove{ position:absolute; top:2px; right:2px; background:rgba(0,0,0,0.55); color:#fff; border-radius:50%; width:18px; height:18px; display:flex; align-items:center; justify-content:center; font-size:0.65rem; line-height:1; border:none; cursor:pointer; padding:0; }

  .showcase-grid{ display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px; }
  @media (max-width:900px){ .showcase-grid{ grid-template-columns:minmax(0,1fr) minmax(0,1fr); } }
  @media (max-width:560px){ .showcase-grid{ grid-template-columns:minmax(0,1fr); } }
  .showcase-card{ padding:0; overflow:hidden; min-width:0; }
  .showcase-photo{ width:100%; aspect-ratio:1/1; object-fit:cover; display:block; background:var(--bg); }
  .showcase-placeholder{ width:100%; aspect-ratio:1/1; display:flex; align-items:center; justify-content:center; background:var(--bg); color:var(--ink-soft); font-size:0.78rem; }
  .showcase-body{ padding:12px 14px 14px; }

  .conic-swatch{ width:56px; height:56px; border-radius:50%; border:1px solid var(--border); flex-shrink:0; }
  .color-chip-row{ display:flex; flex-wrap:wrap; gap:8px; }
  .color-chip{ display:flex; align-items:center; gap:2px; padding:3px; border-radius:8px; border:1px solid var(--border); background:rgba(255,255,255,0.5); cursor:grab; }
  .color-chip.dragging{ opacity:0.4; }
  .color-chip-swatch{ width:22px; height:22px; border-radius:50%; display:inline-block; }
  .chip-star{ background:none; border:none; cursor:pointer; font-size:0.8rem; color:var(--border); padding:0 2px; }
  .chip-star.active{ color:var(--plum); }
  .chip-remove{ background:none; border:none; cursor:pointer; font-size:0.7rem; color:var(--ink-soft); padding:0 2px; }
  /* Touch-only reorder arrows — hidden by default (mouse users drag instead),
     shown only on coarse-pointer (touch) devices regardless of screen size. */
  .chip-move{ display:none; }
  @media (pointer: coarse){
    .color-chip{ cursor:default; }
    .chip-move{ display:inline-flex; align-items:center; justify-content:center; background:none; border:none; cursor:pointer; color:var(--ink-soft); font-size:1rem; line-height:1; min-width:32px; min-height:32px; padding:0; }
    .chip-move:disabled{ opacity:0.25; cursor:default; }
    /* roomier tap targets for the other chip controls on touch */
    .chip-star{ min-width:32px; min-height:32px; font-size:1rem; }
    .chip-remove{ min-width:32px; min-height:32px; font-size:0.9rem; }
  }

  .yarn-picker{ display:flex; flex-wrap:wrap; gap:8px; max-height:130px; overflow-y:auto; padding:8px; border:1px solid var(--border); border-radius:6px; }
  .yarn-chip{ display:inline-flex; align-items:center; gap:6px; font-size:0.75rem; padding:4px 9px; border-radius:999px; border:1px solid var(--border); background:transparent; cursor:pointer; color:var(--ink); }
  .yarn-chip.checked{ background:var(--bg); }
  .yarn-chip .dot{ width:9px; height:9px; border-radius:50%; }

  .project-row{ display:flex; align-items:flex-start; gap:12px; padding:14px 4px; border-bottom:1px dashed var(--border); }
  .project-row:last-child{ border-bottom:none; }
  .status-dot{ width:10px; height:10px; border-radius:50%; flex-shrink:0; margin-top:5px; }
  .project-name{ font-size:0.92rem; font-weight:500; margin:0; }
  .project-name .pattern{ font-weight:400; color:var(--ink-soft); }
  .project-meta{ display:flex; align-items:center; gap:8px; margin-top:4px; flex-wrap:wrap; }
  .project-meta .dot{ width:9px; height:9px; border-radius:50%; }
  .project-meta .days{ font-size:0.72rem; color:var(--ink-soft); }
  select.status-select{ font-size:0.72rem; padding:4px 6px; border-radius:6px; }
  .link-strip{ display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
  .link-card{ display:flex; align-items:center; gap:6px; text-decoration:none; border:1px solid var(--border); border-radius:7px; overflow:hidden; background:rgba(255,255,255,0.4); max-width:190px; }
  .link-card img{ width:48px; height:34px; object-fit:cover; display:block; }
  .link-card .link-title{ font-size:0.7rem; color:var(--ink); padding:0 8px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
  .link-card.generic{ padding:6px 9px; gap:5px; }

  .link-input-row{ display:flex; gap:8px; }
  .link-preview-row{ display:flex; flex-wrap:wrap; gap:8px; margin-top:8px; }
  .link-preview-chip{ display:flex; align-items:center; gap:6px; border:1px solid var(--border); border-radius:7px; padding:4px 8px; font-size:0.72rem; background:rgba(255,255,255,0.5); }
  .link-preview-chip img{ width:30px; height:20px; object-fit:cover; border-radius:3px; }
  .link-preview-chip button{ background:none; border:none; color:var(--ink-soft); cursor:pointer; padding:0; }

  .palette-picks{ display:flex; flex-wrap:wrap; gap:32px; justify-content:center; padding:26px; }
  .palette-pick{ display:flex; flex-direction:column; align-items:center; gap:8px; }
  .palette-swatch{ width:64px; height:64px; border-radius:50%; border:1px solid var(--border); }
  .harmony-btn{ font-size:0.75rem; padding:6px 12px; border-radius:999px; border:1px solid var(--border); background:none; cursor:pointer; color:var(--ink-soft); }
  .harmony-btn.active{ background:var(--plum); border-color:var(--plum); color:#fff; }
  .palette-base-select{ width:100%; max-width:100%; box-sizing:border-box; text-overflow:ellipsis; }

  .brand-hint{ font-size:0.72rem; color:var(--ink-soft); margin-top:-6px; }
  .note{ font-size:0.8rem; color:var(--ink-soft); }
  ::selection{ background:#9B7EC055; }
  .offline-banner{ display:flex; align-items:center; gap:8px; background:#EFE7D8; border:1px solid var(--cardBorder,#C9BB99); color:var(--ink-soft); font-size:0.8rem; padding:8px 12px; border-radius:8px; margin-bottom:16px; }
  .offline-banner .icon{ width:16px; height:16px; flex-shrink:0; }

  /* ---- In-app modal + toast (replaces all browser dialogs) ---- */
  .wg-modal-backdrop{ position:fixed; inset:0; z-index:90; background:rgba(30,25,40,0.45); display:flex; align-items:center; justify-content:center; padding:20px; opacity:0; pointer-events:none; transition:opacity 0.16s; }
  .wg-modal-backdrop.open{ opacity:1; pointer-events:auto; }
  .wg-modal{ background:var(--card); border:1px solid var(--border); border-radius:14px; padding:20px; max-width:400px; width:100%; box-shadow:0 12px 40px rgba(0,0,0,0.25); transform:translateY(8px); transition:transform 0.16s; }
  .wg-modal-backdrop.open .wg-modal{ transform:translateY(0); }
  .wg-modal h3{ margin:0 0 8px; font-family:'Fraunces',serif; font-size:1.1rem; }
  .wg-modal p{ margin:0 0 14px; font-size:0.9rem; color:var(--ink-soft); }
  .wg-modal input{ width:100%; box-sizing:border-box; margin-bottom:14px; }
  .wg-modal-actions{ display:flex; gap:8px; justify-content:flex-end; }
  .wg-toast-wrap{ position:fixed; left:0; right:0; bottom:calc(84px + env(safe-area-inset-bottom,0)); z-index:95; display:flex; flex-direction:column; align-items:center; gap:8px; pointer-events:none; padding:0 16px; }
  @media (min-width:761px){ .wg-toast-wrap{ bottom:24px; } }
  .wg-toast{ background:var(--ink); color:#fff; border-radius:10px; padding:11px 16px; font-size:0.85rem; box-shadow:0 6px 20px rgba(0,0,0,0.25); max-width:420px; opacity:0; transform:translateY(10px); transition:opacity 0.2s, transform 0.2s; }
  .wg-toast.show{ opacity:1; transform:translateY(0); }
  .wg-toast.success{ background:var(--forest); }
  .wg-toast.error{ background:var(--wine); }
  .stash-controls{ display:flex; gap:8px; flex-wrap:wrap; margin-bottom:14px; }
  .stash-controls input, .stash-controls select{ font-size:0.82rem; }
  .ocr-scan-box{ background:rgba(255,255,255,0.55); border:1px dashed var(--border); border-radius:10px; padding:12px; transition:background 0.15s, border-color 0.15s; }
  .ocr-scan-box.dragover{ background:rgba(92,58,114,0.08); border-color:var(--plum); }

  /* Utility classes for common layout patterns used across the app. */
  .row{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
  .row-between{ display:flex; align-items:center; justify-content:space-between; gap:8px; flex-wrap:wrap; }
  .row-end{ display:flex; gap:8px; justify-content:flex-end; }
  .stack-gap{ display:flex; flex-direction:column; gap:10px; }
  .grow{ flex:1; min-width:0; }
  .full-width{ width:100%; }
  .hidden{ display:none; }
  .muted-ink{ color:var(--ink); }
  .danger-text{ color:var(--wine); }
  .ok-text{ color:var(--forest); }
  .hairline{ flex:1; height:1px; background:var(--border); }
  .mt-1{ margin-top:6px; } .mt-2{ margin-top:8px; } .mt-3{ margin-top:10px; }
  .mb-2{ margin-bottom:8px; } .mb-3{ margin-bottom:10px; } .mb-4{ margin-bottom:16px; }
  .no-margin{ margin:0; }
  .field-label{ margin:0 0 6px; display:block; }
  .auth-card{ max-width:380px; margin:24px auto 0; }
  .pick-name{ margin:0; font-weight:500; font-size:0.85rem; }

  /* ============================================================
     MOBILE — bottom nav, FAB, sheets, full-screen forms.
     Everything above is the untouched desktop layout; these
     rules only take effect at <=760px so wide screens are
     unaffected. Mobile-only chrome is display:none by default
     and switched on inside the media query.
  ============================================================ */
  .mobile-nav, .fab, .sheet-backdrop{ display:none; }

  @media (max-width:760px), (max-height:550px) and (max-width:950px){
    .wrap{ padding:16px max(20px, env(safe-area-inset-left)) 96px max(20px, env(safe-area-inset-right)); }  /* room for bottom nav; respect landscape notch/safe areas */
    .header-tagline{ display:none; }           /* reclaim top space on phones */
    .header-actions{ display:none; }           /* moves to Settings in More */
    .app-header{ margin-bottom:16px; }
    .app-header h1{ font-size:1.6rem; }
    nav.tabs{ display:none; }                   /* desktop tab row hidden */

    /* bottom nav bar */
    .mobile-nav{
      display:flex; position:fixed; left:0; right:0; bottom:0; z-index:40;
      background:var(--card); border-top:1px solid var(--border);
      padding-bottom:env(safe-area-inset-bottom, 0);
    }
    .mobile-nav button{
      flex:1; background:none; border:none; font-family:inherit; cursor:pointer;
      display:flex; flex-direction:column; align-items:center; gap:2px;
      padding:8px 2px 9px; color:var(--ink-soft); font-size:0.6rem; font-weight:500;
    }
    .mobile-nav button.active{ color:var(--plum); }
    .mobile-nav .icon{ width:21px; height:21px; }

    /* floating add button */
    .fab{
      display:flex; position:fixed; right:16px; bottom:74px; z-index:41;
      width:52px; height:52px; border-radius:50%; background:var(--plum); color:#fff;
      border:none; cursor:pointer; align-items:center; justify-content:center;
      box-shadow:0 4px 16px rgba(92,58,114,0.45);
      margin-bottom:env(safe-area-inset-bottom, 0);
    }
    .fab .icon{ width:26px; height:26px; }

    /* slide-up sheets (More / Settings) */
    .sheet-backdrop{
      display:flex; position:fixed; inset:0; z-index:50;
      background:rgba(0,0,0,0.34); align-items:flex-end;
      opacity:0; pointer-events:none; transition:opacity 0.2s;
    }
    .sheet-backdrop.open{ opacity:1; pointer-events:auto; }
    .sheet{
      width:100%; background:var(--card); border-radius:18px 18px 0 0;
      padding:8px 0 calc(14px + env(safe-area-inset-bottom, 0));
      transform:translateY(100%); transition:transform 0.28s cubic-bezier(.4,0,.2,1);
    }
    .sheet-backdrop.open .sheet{ transform:translateY(0); }
    .sheet-handle{ width:38px; height:4px; background:var(--border); border-radius:2px; margin:8px auto 12px; }
    .sheet button{
      width:100%; background:none; border:none; text-align:left; cursor:pointer;
      padding:14px 22px; font-family:inherit; font-size:0.95rem; color:var(--ink);
      display:flex; align-items:center; gap:14px;
    }
    .sheet button.active{ color:var(--plum); font-weight:600; }
    .sheet button .icon{ width:20px; height:20px; }
    .sheet-divider{ height:1px; background:var(--border); margin:6px 22px; }

    /* full-screen slide-up forms */
    .fullscreen-form{
      position:fixed; inset:0; z-index:60; background:var(--bg);
      display:flex; flex-direction:column;
      animation:formSlideUp 0.3s cubic-bezier(.4,0,.2,1);
    }
    @keyframes formSlideUp{ from{ transform:translateY(100%); } to{ transform:translateY(0); } }
    .fullscreen-form .fs-bar{
      display:flex; align-items:center; justify-content:space-between; flex-shrink:0;
      padding:12px 16px calc(12px); padding-top:calc(12px + env(safe-area-inset-top, 0));
      background:var(--card); border-bottom:1px solid var(--border);
    }
    .fullscreen-form .fs-bar .fs-title{ font-family:'Fraunces',serif; font-weight:600; font-size:1rem; }
    .fullscreen-form .fs-bar button{ background:none; border:none; font-family:inherit; font-size:0.9rem; cursor:pointer; padding:4px 2px; }
    .fullscreen-form .fs-bar .fs-cancel{ color:var(--ink-soft); }
    .fullscreen-form .fs-bar .fs-save{ color:var(--plum); font-weight:600; }
    .fullscreen-form .fs-body{ flex:1; overflow-y:auto; padding:16px 16px calc(24px + env(safe-area-inset-bottom, 0)); }
    /* inside a full-screen form, the grid always stacks and the in-form action row hides
       (the top bar's Save/Cancel take over) */
    .fullscreen-form .form-grid{ grid-template-columns:1fr; display:grid; }
    .fullscreen-form .form-actions-inline{ display:none; }

    /* forms that are NOT elevated to full-screen still stack cleanly */
    .form-grid{ grid-template-columns:1fr; }
    .stat-grid{ grid-template-columns:repeat(2,minmax(0,1fr)); }
    .chart-grid{ grid-template-columns:1fr; }
    .yarn-grid{ grid-template-columns:1fr; }
    .showcase-grid{ grid-template-columns:minmax(0,1fr) minmax(0,1fr); }

    body.form-open{ overflow:hidden; }          /* lock background scroll while a full-screen form is up */
    body.form-open .fab, body.form-open .mobile-nav{ display:none; }  /* hide app chrome behind full-screen form */
  }

  @media (max-width:420px){
    .showcase-grid{ grid-template-columns:1fr; }
  }

  /* iOS "add to home screen" hint — only shown via JS on iOS Safari when
     not already installed. Dismissible, and remembers dismissal. */
  .ios-install-hint{
    position:fixed; left:12px; right:12px; bottom:12px; z-index:70;
    background:var(--card); border:1px solid var(--border); border-radius:14px;
    padding:14px 16px; box-shadow:0 6px 24px rgba(0,0,0,0.18);
    display:flex; align-items:flex-start; gap:12px; font-size:0.85rem;
    padding-bottom:calc(14px + env(safe-area-inset-bottom, 0));
  }
  .ios-install-hint .ih-icon{ width:34px; height:34px; border-radius:8px; flex-shrink:0; }
  .ios-install-hint .ih-close{ background:none; border:none; color:var(--ink-soft); font-size:1.1rem; cursor:pointer; padding:0 2px; flex-shrink:0; }
  .ios-install-hint b{ color:var(--ink); }
