/* ===== THEME: LIGHT ===== */
:root{
  --bg:linear-gradient(180deg,#fafafa,#eef1f6 55%,#e9edf5);
  --panel:#fff; --surface:#fff; --surface-2:#fff;
  --ink:#0b1220; --title:#0b1220; --muted:#667085; --line:#e5e7eb;
  --blue:#2563eb; --blue-600:#1d4ed8; --blue-700:#1e40af;
  --warn:#b45309; --radius:14px;
  --panel-elev:0 6px 24px rgba(0,0,0,.06);
  --cta-ghost-border:#c9d3f7; --cta-ghost-ink:#1e293b;
}
/* ===== THEME: DARK (purplish) ===== */
html[data-theme="dark"]{
  --bg:
    radial-gradient(1000px 500px at 12% -10%, #6d28d9 0%, transparent 45%),
    radial-gradient(900px 480px at 110% 110%, #7c3aed 0%, transparent 45%),
    linear-gradient(180deg,#0b0a14 0%, #0f1021 100%);
  --panel:#111225;
  --surface:#0d0e1b;
  --surface-2:#0f1021;
  --ink:#e9e7ff; --title:#f3f2ff; --muted:#b7b4d6; --line:#2a2940;
  --blue:#7c3aed; --blue-600:#6d28d9; --blue-700:#c4b5fd;
  --warn:#f59e0b;
  --panel-elev:0 30px 80px rgba(0,0,0,.38);
  --cta-ghost-border:#3b3a55; --cta-ghost-ink:#e9e7ff;
}
*{box-sizing:border-box} html,body{height:100%}
body{margin:0;font-family:ui-sans-serif,-apple-system,Segoe UI,Roboto,Inter,Arial;background:var(--bg);color:var(--ink)}
.app{
  max-width:1200px;
  margin:32px auto;
  padding:0 16px;
}

/* Larger shell on big screens */
@media (min-width: 1440px){
  .app{
    max-width:1440px;          /* wider content */
    margin:24px auto;          /* a bit less top/bottom margin */
    padding:0 24px;            /* closer to window edges */
  }
}



.title{font-size:24px;font-weight:700;margin:0 0 14px 2px;color:var(--title)}

/* Two-column shell (right panel is now modal) */
.shell{display:grid;grid-template-columns:300px 1fr;gap:16px}

/* Panels & common */
.panel{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--panel-elev);overflow:hidden;display:flex;flex-direction:column;min-height:580px}
.panel header{padding:14px;border-bottom:1px solid var(--line);display:flex;align-items:center;justify-content:space-between}
.panel .body{padding:12px;flex:1;overflow:auto}

.btn{border:1px solid var(--blue-600);background:var(--blue);color:#fff;padding:10px 12px;border-radius:10px;font-weight:700;cursor:pointer;transition:.15s}
.btn:hover{background:var(--blue-600)}
.btn.secondary{background:transparent;color:var(--blue-700);border-color:var(--cta-ghost-border)}
html[data-theme="light"] .btn.warn{background:#f59e0b;border-color:#d97706;color:#111}
html[data-theme="dark"]  .btn.warn{background:#f59e0b;border-color:#d97706;color:#1b1329}
.btn.block{width:100%}.btn.icon{padding:8px 10px}

.small{font-size:12px;color:var(--muted)}
.list{display:flex;flex-direction:column;gap:8px}
.prompt-item{
  position:relative;
  display:flex;align-items:center;justify-content:space-between;gap:8px;
  border:1px solid var(--line);background:var(--surface);padding:10px;border-radius:10px;cursor:pointer
}
.prompt-item.active{border-color:var(--blue);outline:2px solid rgba(37,99,235,.15)}
.prompt-item .name{font-weight:600}.prompt-item .meta{font-size:12px;color:var(--muted)}

.editor{display:flex;flex-direction:column;gap:10px;height:100%}
.editor textarea{width:100%;flex:1;resize:none;border:1px solid var(--line);border-radius:12px;padding:12px 14px;font:500 14px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--surface);color:var(--ink)}

/* Toolbar: left group + right group (mode + DONE) */
.toolbar{display:flex;align-items:center;gap:10px;margin-top:10px}
.toolbar .left-group{display:flex;align-items:center;gap:10px}
.toolbar .right-group{display:flex;align-items:center;gap:10px;margin-left:auto}
.toolbar select{
  height:36px; padding:6px 10px; border-radius:10px;
  background:var(--surface); color:var(--ink); border:1px solid var(--line);
  min-width:180px;
}

/* Stats */
.statbar{display:flex; align-items:center; gap:14px; flex-wrap:wrap;color:var(--muted); font-size:12px;}
.statbar .stat{display:flex; align-items:center; gap:8px; line-height:1;}
.statbar .label{color:var(--muted); font-weight:600; letter-spacing:.01em}
.statbar .value{color:var(--ink); font-weight:800}
.pill{display:inline-flex; align-items:center; gap:6px;padding:3px 8px; border-radius:999px;background:var(--surface); border:1px solid var(--line);color:var(--ink); font-weight:700; font-size:12px;}
.pill .sub{color:var(--muted); font-weight:600}
.pill + .pill{margin-left:6px}

/* Modal (Finalize) */
.modal{position:fixed;inset:0;display:none;align-items:center;justify-content:center;background:rgba(0,0,0,.35);z-index:60}
.modal.show{display:flex}
.modal-card{width:min(900px,95%);max-height:85vh;background:var(--panel);border:1px solid var(--line);border-radius:16px;box-shadow:var(--panel-elev);padding:16px;display:flex;flex-direction:column;gap:10px}
.modal-card header{display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);padding-bottom:8px;margin:-4px 0 2px}
.modal-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}

.totals{display:flex; flex-direction:column; gap:8px; margin-bottom:8px;color:var(--muted); font-size:12px;}
.tot-row{display:flex; align-items:center; gap:12px; flex-wrap:wrap}
.tot-row .label{font-weight:700; color:var(--muted)}
.tot-row .value{font-weight:800; color:var(--ink)}
.compile textarea{height:260px;width:100%;resize:none;border:1px solid var(--line);border-radius:12px;padding:12px 14px;font:500 13px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;background:var(--surface);color:var(--ink)}

/* Toast */
.toast{position:fixed;top:24px;right:24px;z-index:80;background:var(--panel);border:1px solid var(--line);color:var(--ink);padding:10px 14px;border-radius:10px;box-shadow:var(--panel-elev);display:none}
.toast.show{display:block}

/* Auth, theme toggle, prompts modal (unchanged except responsive tweaks) */
.auth-wrap{display:flex;align-items:stretch;justify-content:center;gap:28px;height : 80%;max-width:1200px;margin:40px auto;padding:0 16px}
.hero{flex:1.2; min-height:560px; color:var(--ink); border:1px solid var(--line);border-radius:20px; padding:26px; background:var(--surface-2); box-shadow:var(--panel-elev);display:flex;flex-direction:column;gap:18px}
.hero h1{font-size:34px;line-height:1.15;margin:4px 0 2px;color:var(--title)}
.hero p{color:var(--muted);margin:0}
.features{margin-top:8px;display:grid;grid-template-columns:1fr 1fr;gap:12px}
.feat{background:var(--surface); padding:14px;border-radius:14px;border:1px solid var(--line);font-size:14px; color:var(--ink)}
.card{width:min(440px, 100%); background:var(--panel); border:1px solid var(--line); border-radius:20px; padding:22px 22px 16px;box-shadow:var(--panel-elev); display:flex; flex-direction:column; gap:14px}
.card h2{margin:0 0 4px; font-size:22px; color:var(--title)}
.field{display:flex;flex-direction:column;gap:8px}
.label{font-size:12px; color:var(--muted); font-weight:700; letter-spacing:.02em}
.input{display:flex;align-items:center;gap:8px;border:1px solid var(--line);border-radius:12px;padding:10px 12px;background:var(--surface)}
.input input{border:0;outline:none;width:100%;font-size:14px;background:transparent;color:var(--ink)}
.row{display:flex;align-items:center;justify-content:space-between;gap:12px}
.err{display:none;font-size:12px;color:#dc2626;padding:6px 8px;border:1px solid #fecaca;background:#fff1f2;border-radius:10px}

/* Theme toggle */
.theme-toggle{
  position:fixed;
  top:calc(16px + env(safe-area-inset-top));
  left:calc(16px + env(safe-area-inset-left));
  right:auto !important;
  z-index:9999;
  display:flex; align-items:center; gap:8px;
  background:var(--surface); border:1px solid var(--line); color:var(--ink);
  padding:8px 12px; border-radius:999px; font-weight:700; cursor:pointer; box-shadow:var(--panel-elev)
}
.theme-toggle span{font-size:12px;color:var(--muted)}

/* Pi label + connector line */
.editor-wrap{ position:relative; }
.active-chip{
  position:absolute; left:-10px; top:-14px;
  background:var(--surface); color:var(--ink);
  border:1px solid var(--line); padding:6px 10px; border-radius:999px;
  font-weight:700; box-shadow:var(--panel-elev); pointer-events:none; z-index:2;
}
.chip-connector{
  position:absolute; top:calc(-14px + 50%); left:calc(-10px + 100%);
  transform:translateY(-50%);
  height:2px; width:28px; background:var(--line); border-radius:2px; z-index:1; pointer-events:none;
}

/* My Prompts modal layout */
.pm-list{display:flex;flex-direction:column;gap:10px}
.pm-item{display:grid;grid-template-columns:1fr auto;gap:12px;align-items:center;border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:12px 12px 10px}
.pm-left{min-width:0}
.pm-title{font-weight:800;color:var(--ink);margin:0 0 6px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.pm-preview{color:var(--muted);font-size:12px;line-height:1.45;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;margin-bottom:6px}
.pm-stats{display:flex;gap:8px;flex-wrap:wrap}
.pm-pill{display:inline-flex;align-items:center;gap:6px;padding:3px 8px;border-radius:999px;background:var(--panel);border:1px solid var(--line);color:var(--ink);font-weight:700;font-size:12px}
.pm-pill .sub{color:var(--muted);font-weight:600}
.pm-actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap;justify-content:flex-end;min-width:280px}
.btn.sm{padding:6px 10px;border-radius:9px;font-size:13px;font-weight:700}
.btn.warn.sm{padding:6px 12px}
#promptsModal .modal-card{width:min(900px,95%);max-height:85vh;display:flex;flex-direction:column;gap:10px}
#pmList{overflow:auto;flex:1;border:1px solid var(--line);background:var(--surface);border-radius:12px;padding:10px}

/* Responsive & scroll fixes */
@media(max-width:1024px){ .shell{grid-template-columns:1fr} .panel{min-height:auto} .auth-wrap{flex-direction:column} .hero{min-height:unset} }
html, body { overflow-x: hidden !important; }
.editor textarea, #finalText { white-space: pre-wrap !important; word-break: break-word !important; overflow-wrap: anywhere !important; }

/* Hide horizontal bar entirely (WebKit) */
::-webkit-scrollbar:horizontal { height:0 !important; display:none !important; }
/* --- Kill horizontal scrollbars everywhere (page + inner panels) --- */
html, body,
.app, .shell, .panel, .panel .body,
.editor, .compile, .compile .body,
#finalizeModal .body, #promptsModal .modal-card, #pmList {
  overflow-x: hidden !important;
}

/* Panels: only vertical scrolling allowed */
.panel .body,
.compile .body {
  overflow-y: auto;
  overflow-x: hidden !important;
}

/* Prevent the absolute chip/connector from creating x-overflow */
.editor-wrap {
  overflow-x: hidden;   /* contains the active-chip + connector */
}

/* Flex children: allow shrinking so they don't push width */
.toolbar, .toolbar .left-group, .toolbar .right-group {
  min-width: 0;
}

/* If your select can push width on small viewports, allow wrap */
@media (max-width: 900px) {
  .toolbar { flex-wrap: wrap; }
}

/* Hide horizontal scrollbar in WebKit just in case */
.panel .body::-webkit-scrollbar:horizontal,
.compile .body::-webkit-scrollbar:horizontal,
#pmList::-webkit-scrollbar:horizontal {
  height: 0 !important;
  display: none !important;
}
/* Keep chip visible and inside the panel radius */
.editor-wrap { position: relative; padding-top: 8px; overflow-x: hidden; }

/* Textarea sits below the chip */
.editor textarea {
  position: relative;
  z-index: 1;                 /* lower than chip */
}

/* Chip + connector float above everything */
.active-chip {
  position: absolute;
  top: -6px;                  /* slightly overlaps the textarea */
  left: 1px;                  /* inside the rounded corner to avoid clipping */
  z-index: 5;                 /* above textarea */
  background: var(--surface); /* already set in your sheet, keep it */
  border: 1px solid var(--line);
  border-radius: 50;
  padding: 6px 6px;
  box-shadow: var(--panel-elev);
}

.chip-connector {
  position: absolute;
  top: 22px;                  /* align to chip center */
  left: calc(8px + 100%);     /* start just to the right of the chip */
  height: 2px;
  width: 28px;
  background: var(--line);
  border-radius: 2px;
  z-index: 4;                 /* above textarea, below chip text is fine */
}
/* Chip must not intercept hover or clicks */
.active-chip,
.chip-connector {
  pointer-events: none !important;
  z-index: 5; /* stays above visuals but doesn't block hover */
}

/* Restore/upgrade hover effects (desktop only) */
@media (hover:hover) and (pointer:fine) {
  .btn {
    transition: background-color .15s ease, border-color .15s ease, transform .12s ease;
  }
  .btn:hover {
    background: var(--blue-600);
    border-color: var(--blue-600);
    transform: translateY(-1px);
  }
  .btn.secondary:hover {
    background: var(--surface-2);
    border-color: var(--cta-ghost-border);
  }
  .btn.warn:hover {
    filter: brightness(0.95);
  }

  .prompt-item,
  .pm-item,
  .feat,
  .card {
    transition: border-color .15s ease, box-shadow .15s ease, transform .12s ease, background-color .15s ease;
  }
  .prompt-item:hover,
  .pm-item:hover {
    border-color: var(--blue);
    box-shadow: 0 6px 18px rgba(0,0,0,.10);
    background: var(--surface-2);
    transform: translateY(-1px);
  }

  /* Links */
  a:hover { text-decoration: underline; }
}

/* Prevent any invisible overlays from killing hover */
.modal:not(.show) { display: none; }
/* Let center column actually shrink with the window */
.shell{
  /* was: grid-template-columns: 300px 1fr; */
  grid-template-columns: 300px minmax(0, 1fr);
}

/* Stop width clamp through the flex chain */
.panel,
.panel .body,
.editor,
.toolbar,
.toolbar .left-group,
.toolbar .right-group {
  min-width: 0;
}

/* Allow vertical shrink inside flex parents (Safari/Chrome flexbox quirk) */
.panel .body,
.editor {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Make the textarea truly responsive */
.editor textarea{
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  flex: 1 1 auto;       /* grow & shrink with panel */
  min-height: 140px;    /* keep a sensible floor */
}

/* Optional: when the window gets narrow, let the toolbar wrap
   so it never forces a horizontal scrollbar. */
@media (max-width: 900px){
  .toolbar{ flex-wrap: wrap; }
}
/* ====== LARGE DESKTOP (macOS) ADJUSTMENTS ====== */
@media (min-width: 1600px) {
  /* Expand layout width and reduce side padding */
  .app {
    max-width: 1680px;
    padding: 0 48px;
    margin-top: 20px;
  }

  /* Panels: fill more horizontal space */
  .shell {
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 24px;
  }

  /* Larger type for reading comfort */
  body {
    font-size: 18px;
  }

  .title {
    font-size: 32px;
  }

  .panel header h2 {
    font-size: 22px;
  }

  .statbar {
    font-size: 14px;
  }

  /* Bigger text area */
  .editor textarea {
    font-size: 17px;
    line-height: 1.6;
    padding: 18px 20px;
  }

  /* Buttons scale up slightly */
  .btn {
    font-size: 15px;
    padding: 12px 18px;
    border-radius: 12px;
  }

  /* Prompt items */
  .prompt-item {
    font-size: 15px;
    padding: 12px 14px;
  }

  /* Modal / Card layout – less cramped */
  .modal-card,
  .card {
    padding: 28px;
    border-radius: 24px;
  }

  /* Theme toggle button scales proportionally */
  .theme-toggle {
    padding: 10px 16px;
    font-size: 14px;
  }
}

/* ULTRA-WIDE 4K displays: even larger, denser layout */
@media (min-width: 1920px) {
  .app {
    max-width: 1800px;
    padding: 0 60px;
  }

  .editor textarea {
    font-size: 18px;
  }

  .btn {
    font-size: 16px;
  }

  .panel header h2 {
    font-size: 24px;
  }
}
/* ====== TALLER LAYOUT (balanced bottom spacing) ====== */
@media (min-width: 1600px) {
  html, body {
    height: 100%;
  }

  .app {
    min-height: calc(100vh - 120px); /* smaller than before to leave a clean bottom margin */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  .shell {
    flex: 1;
    display: grid;
    align-items: stretch;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 24px;
  }

  .panel {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .editor {
    flex: 1;
    display: flex;
    flex-direction: column;
  }

  .editor textarea {
    flex: 1;
    height: auto;
    min-height: 68vh;  /* was 72vh — reduced for cleaner bottom spacing */
    max-height: none;
  }
}

/* Slightly taller panels on big screens, without touching viewport height */
@media (min-width: 1600px) {
  .app {
    margin-top: 24px;
    margin-bottom: 32px; /* nice, consistent bottom gap */
  }

  /* just make the cards a bit taller */
  .panel {
    min-height: 640px;   /* was 580px */
  }

  .editor textarea {
    min-height: 380px;   /* fixed floor; no vh so it won't run off-screen */
  }
}