    /* CSS Variables for light theme */
    :root {
      --bg-color: #f7f7f8;
      --text-color: #333;
      --container-bg: #fff;
      --sidebar-bg: #fafbfc;
      --sidebar-border: #ddd;
      --header-bg: #fff;
      --header-border: #ddd;
      --chat-bg: #fff;
      --chat-border: #ddd;
      --message-user-bg: #d1e7dd;
      --message-bot-bg: #f1f1f3;
      --code-bg: #f6f8fa;
      --code-border: #d1d5da;
      --think-bg: #f0f0f0;
      --think-border: #aaa;
      --toggle-think-color: #007bff;
      --input-bg: #fff;
      --input-border: #ddd;
      --input-text-color: #333;
      --button-bg: #007bff;
      --button-hover-bg: #0056b3;
      --modal-bg: #fff;
      --modal-border: #888;
      --modal-input-bg: #fff;
      --modal-input-border: #ddd;
	    --bg: #f9f9fa;
		--fg: #222;
		--card-bg:#fff;
		--shadow: 0 2px 6px rgba(0,0,0,.1);
    }
    /* Dark theme overrides */
    .dark-theme {
      --bg-color: #121212;
      --text-color: #e0e0e0;
      --container-bg: #1e1e1e;
      --sidebar-bg: #1e1e1e;
      --sidebar-border: #333;
      --header-bg: #1e1e1e;
      --header-border: #333;
      --chat-bg: #121212;
      --chat-border: #333;
      --message-user-bg: #2a2a2a;
      --message-bot-bg: #333;
      --code-bg: #2a2a2a;
      --code-border: #555;
      --think-bg: #2a2a2a;
      --think-border: #555;
      --toggle-think-color: #66aaff;
      --input-bg: #1e1e1e;
      --input-border: #333;
      --input-text-color: #e0e0e0;
      --button-bg: #007bff;
      --button-hover-bg: #0056b3;
      --modal-bg: #1e1e1e;
      --modal-border: #333;
      --modal-input-bg: #2a2a2a;
      --modal-input-border: #555;
	   --bg:#111;
    --fg:#eee;
    --card-bg:#1b1b1b;
    --shadow:0 2px 6px rgba(0,0,0,.5);
    }
    /* Base reset */
	html, body {
	  max-width: 100vw;
	  overflow-x: hidden;
	}

	#main, #chatContainer, #chatLog {
	  max-width: 100%;
	  overflow-x: hidden;
	}
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }
    body {
      display: flex;
      height: 100vh;
      background: var(--bg-color);
      color: var(--text-color);
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    }
    /* Sidebar */
    #sidebar {
      position: relative;
      z-index: 200;
      width: 250px;
      background: var(--sidebar-bg);
      border-right: 1px solid var(--sidebar-border);
      padding: 10px;
      overflow-y: auto;
      flex-shrink: 0;
      transition: transform 0.3s ease;
    }
    #sidebar.hidden {
      transform: translateX(-260px);
    }
    #toggleSidebarBtn {
      position: fixed;
      top: 10px;
      left: 10px;
      z-index: 300;
      display: none;
      background: var(--button-bg);
      color: #fff;
      border: none;
      border-radius: 4px;
      padding: 8px 12px;
      cursor: pointer;
      font-size: 1em;
    }
    #toggleSidebarBtn:hover {
      background: var(--button-hover-bg);
    }
    #sidebar h2 {
      font-size: 1.2em;
      margin-bottom: 10px;
    }
    #sidebar input,
    #sidebar select {
      width: 100%;
      margin-bottom: 10px;
      padding: 8px;
      border-radius: 4px;
      border: 1px solid var(--input-border);
      background: var(--input-bg);
      color: var(--input-text-color);
      font-size: 1em;
      cursor: pointer;
    }
    .conversation-item {
      padding: 8px;
      margin-bottom: 6px;
      border-radius: 5px;
      cursor: pointer;
      background: var(--sidebar-bg);
      border: 1px solid transparent;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }
    .conversation-item:hover {
      border-color: var(--sidebar-border);
      background: var(--chat-bg);
    }
    /* Main content */
    #main {
      flex: 1;
      display: flex;
      flex-direction: column;
    }
    #header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 10px 15px;
      background: var(--header-bg);
      border-bottom: 1px solid var(--header-border);
    }
    #header .left,
    #header .right {
      display: flex;
      align-items: center;
      gap: 8px;
    }
    /* Chat container */
    #chatContainer {
      flex: 1;
      display: flex;
      flex-direction: column;
      background: var(--chat-bg);
      padding: 15px;
      overflow: hidden;
    }
    #chatLog {
      flex: 1;
      overflow-y: auto;
      background: var(--sidebar-bg);
      border: 1px solid var(--chat-border);
      border-radius: 5px;
      padding: 10px;
      margin-bottom: 10px;
    }
    .message {
      margin-bottom: 12px;
    }
    .message.user {
  text-align: right;           /* keeps the bubble itself on the right */
	}

	.message.user span,
	.message.user pre,
	.message.user code,
	.message.user .code-block-container {
	  text-align: left;            /* aligns text and code inside the bubble to the left */
	  display: inline-block;       /* allows left-align within right-aligned bubble */
	  max-width: 100%;             /* prevents overflow */
	}

    .message.user span {
      background: var(--message-user-bg);
      padding: 8px 12px;
      border-radius: 12px;
      display: inline-block;
      max-width: 80%;
    }
    .message.bot {
      text-align: left;
    }
    .message.bot span {
      /*background: var(--message-bot-bg);*/
      /*padding: 8px 12px;*/
      border-radius: 12px;
      display: inline-block;
      max-width: 80%;
    }
    /* Form */
    #chatForm {
      display: flex;
      gap: 8px;
    }
    #chatForm input[type="text"] {
      flex: 1;
      padding: 10px;
      border: 1px solid var(--input-border);
      border-radius: 5px;
      background: var(--input-bg);
      color: var(--input-text-color);
      font-size: 1em;
    }
    #chatForm button, .button {
	 width: 100%;
      margin-bottom: 10px;
      padding: 10px 16px;
      border: none;
      border-radius: 5px;
      background: var(--button-bg);
      color: #fff;
      font-size: 1em;
      cursor: pointer;
    }
    #chatForm button:hover {
      background: var(--button-hover-bg);
    }
    /* Modal */
    .modal {
      display: none;
      position: fixed;
      z-index: 100;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.4);
    }
    .modal-content {
      background: var(--modal-bg);
      margin: 15% auto;
      padding: 20px;
      border: 1px solid var(--modal-border);
      width: 90%;
      max-width: 300px;
      border-radius: 5px;
    }
    .modal-content .close {
      float: right;
      font-size: 24px;
      cursor: pointer;
    }
    /* Responsive */
    @media (max-width: 768px) {
      #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        z-index: 200;
		padding-top:60px;
      }
      #toggleSidebarBtn {
        display: inline-flex;
      }
      body {
        flex-direction: column;
      }
      #main {
        margin-left: 0;
      }
    }
	
	/* ===== Mobile layout: fixed header, fixed input, scroll‑only chat ===== */
@media (max-width: 768px) {

  /* 1. Header is pinned to the top */
  #header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 250;                  /* sits above messages */
	height:60px;
	padding-left: 60px;
  }

  /* 2. Input form is pinned to the bottom */
  #chatForm {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--header-bg);  /* same colour as header for continuity */
    z-index: 250;
    padding: 8px;                  /* keep original gap */
  }

  /* 3. Sidebar (settings menu) slides in but is also fixed */
  #sidebar {
    position: fixed;               /* was absolute */
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-260px); /* hidden state */
    z-index: 200;
  }
  #sidebar:not(.hidden) {
    transform: translateX(0);       /* visible state */
  }

  /* 4. Only the message list scrolls */
  #chatContainer {
    position: relative;
    height: 100vh;                  /* full viewport */
    padding-top: 56px;              /* header height */
    padding-bottom: 72px;           /* input height */
  }
  #chatLog {
    height: 100%;
    overflow-y: auto;               /* sole scrollable area */
  }

  /* 5. Toggle button always visible on top of header */
  #toggleSidebarBtn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 350;                   /* above sidebar */
  }
}


	mjx-container {   /* $$ … $$ blocks  */
	  display: inline-block;            /* already block, but explicit for some browsers */
	  margin: 1em 0;            /* ⇦ adjust to taste */
	}
	
	#chatForm textarea#userInput {
  flex: 1;
  min-height: 38px;         /* visually matches input height */
  max-height: 220px;        /* ~10 rows */
  padding: 10px;
  border: 1px solid var(--input-border);
  border-radius: 5px;
  background: var(--input-bg);
  color: var(--input-text-color);
  font-size: 1em;
  line-height: 1.3;
  resize: none;             /* no manual resize, auto only */
  box-sizing: border-box;
  transition: border 0.2s;
}
#chatForm textarea#userInput:disabled {
  background: var(--input-bg);
  color: var(--input-text-color);
  opacity: 0.7;
}

/* For code block containers */
.code-block-container {
  margin: 1em 0;
  background: var(--code-bg, #23272e);
  border: 1px solid var(--code-border, #444);
  border-radius: 8px;
  padding: 0.5em 0.75em;
  overflow-x: auto;
  max-width: 100%;
  box-sizing: border-box;
}

/* For code inside blocks */
.code-block {
  background: none;        /* already styled by container */
  color: inherit;
  font-family: 'Fira Mono', 'Consolas', 'Menlo', 'Monaco', 'Liberation Mono', monospace;
  font-size: 1em;
  line-height: 1.5;
  white-space: pre;
  word-break: normal;
  overflow-x: auto;
  margin: 0;
  padding: 0;
}

/* Prevents code from wrapping, adds horizontal scroll if too long */
.code-block code {
  display: block;
  white-space: pre;
  overflow-x: auto;
  padding-bottom: 2px;
}

/* Make sure chat log never overflows */
#chatLog {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 700px) {
  .code-block-container {
    font-size: 0.92em;
    padding: 0.3em 0.3em;
    border-radius: 4px;
  }
}

.copy-button {
  float: right;
  margin-left: 8px;
  margin-top: 2px;
  background: var(--button-bg, #444);
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 0.9em;
}
#scrollToBottomBtn {
  transition: opacity 0.2s;
  opacity: 1;
  pointer-events: auto;
}
#scrollToBottomBtn[style*="display: none"] {
  opacity: 0;
  pointer-events: none;
}
#scrollToBottomBtn button:active {
  opacity: 1;
}

/* =======  CARD  ======= */

main{
  flex:1;
  max-width:1200px;
  margin:auto;
  padding:1rem;
  display:grid;
  gap:1rem;
  grid-template-columns:repeat(auto-fill,minmax(240px,1fr));
}

.card{
  background:var(--card-bg);
  border-radius:.6rem;
  overflow:hidden;
  display:flex;
  flex-direction:column;
  box-shadow:var(--shadow);
  transition:transform .15s ease;
}
.card:hover{transform:translateY(-4px)}
.card img{
  width:100%;
  /*height:240px;*/
  object-fit:cover;
}
.card>section{padding:0.8rem 1rem 1rem}
.card h2{font-size:1.15rem;margin-bottom:.35rem}
.card p.desc{font-size:.9rem;margin-bottom:.6rem;line-height:1.35}
ul.traits{list-style:none;font-size:.85rem;margin-bottom:.6rem}
ul.traits li{margin:.15rem 0}
.details-block{font-size:.8rem;margin-top:.4rem;line-height:1.3}
details summary{cursor:pointer;margin:.4rem 0;font-weight:600}
pre{font-family:monospace;font-size:.75rem;overflow-x:auto}

/* === tweak: make visual‑detail lines smaller === */
.visual p{
  font-size: 0.85rem;   /* smaller text */
  line-height: 1.25;    /* slightly tighter */
  margin: 0.15rem 0;    /* reduce vertical gap */
}


/* ======  MOBILE: one‑card‑at‑a‑time  ====== */
@media (max-width: 600px) {
  main {               /* the grid wrapper */
    grid-template-columns: 1fr;   /* exactly one column */
    gap: 0.5rem;                  /* keep a small vertical gap */
    padding: 0.5rem;              /* tighter side padding */
  }

  .card {
    border-radius: 0.4rem;
    box-shadow: var(--shadow);
  }

  .card img {          
    /*height: 42vh; */
  }
}

/* === Start‑Chat button refresh === */
.start-chat{
  display:block;                 /* makes it span the width */
  width: calc(100% - 2rem);      /* nearly full card minus side padding */
  margin: 0.6rem auto;           /* centered with a bit of breathing room */
  padding: 0.55rem 0;            /* comfortable click target */

  background:#007bff;            /* Bootstrap‑style blue */
  color:#fff;
  font-size:0.95rem;
  font-weight:600;
  text-align:center;
  text-decoration:none;

  border:none;
  border-radius:0.45rem;
  box-shadow:0 2px 4px rgba(0,0,0,.15);
  cursor:pointer;
  transition:background .18s ease, transform .12s ease;
}

.start-chat:hover{
  background:#005ed3;
  transform:translateY(-2px);
}

.start-chat:active{
  background:#004bb0;
  transform:translateY(0);
}


/* === GENERATOR === */

.section { margin-bottom: 1.5em; }
label { display: block; margin: 0.5em 0 0.2em; }
.slider { width: 100%; }
#output { 
	white-space: pre-wrap;
	background: var(--chat-bg);
	padding: 1em;
	border: 1px solid #ccc;
}

/* new character container */
#newContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  padding: 50px;
}

/* character generator interest selector */
#interestContainer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 1em;
}
#interestsSelect, #chosenInterests {
  width: 220px;
  height: 200px;
  font-size: 1em;
  resize: none;
}
#interestBtns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: center;
}