:root {
    --bg: #0b0e14; --panel: #131822; --border: #222b3a;
    --accent: #00e5ff; --accent-dim: rgba(0,229,255,0.12);
    --text: #e6edf3; --muted: #8b949e; --success: #2ea043;
  }
  * { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; user-select: none; }
  html, body { max-width: 100vw; overflow-x: hidden; }
  body { background: var(--bg); color: var(--text); display: flex; height: 100dvh; overflow: hidden; position: relative; }
    .msg, textarea, input { user-select: text; -webkit-user-select: text; -webkit-touch-callout: default; }

  .sidebar { width: 300px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 18px; gap: 14px; overflow-y: auto; z-index: 100; transition: transform 0.25s ease; }
  .overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.65); z-index: 90; backdrop-filter: blur(3px); }
  .menu-btn { display: none; background: transparent; border: 1px solid var(--border); color: var(--accent); border-radius: 8px; min-width: 44px; min-height: 44px; padding: 6px 10px; font-size: 18px; cursor: pointer; margin-right: 10px; }

  .brand { font-size: 16px; font-weight: 700; letter-spacing: 1.2px; color: var(--accent); display: flex; align-items: center; gap: 8px; }
  .badge { font-size: 10.5px; background: var(--accent-dim); color: var(--accent); padding: 2px 7px; border-radius: 12px; border: 1px solid var(--accent); }
  .section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
  select, input[type="text"] { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--border); padding: 10px 11px; border-radius: 8px; font-size: 13.5px; outline: none; }
  select:focus, input:focus { border-color: var(--accent); }
  .btn { width: 100%; background: var(--border); color: var(--text); border: 1px solid #303c52; padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; transition: 0.15s; text-align: left; display: flex; align-items: center; justify-content: space-between; }
  .btn:hover, .btn:active { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
  .card { background: rgba(255,255,255,0.02); border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
  .lan-box { font-size: 12px; color: var(--muted); line-height: 1.5; word-break: break-all; }
  .lan-box code { color: var(--accent); font-family: ui-monospace, SFMono-Regular, monospace; }

  .main { flex: 1; display: flex; flex-direction: column; position: relative; min-width: 0; max-width: 100vw; overflow: hidden; }
  .topbar { height: 56px; min-height: 56px; flex-shrink: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 58px 0 14px; background: rgba(19,24,34,0.85); backdrop-filter: blur(8px); }
  .status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--success); display: inline-block; margin-right: 6px; box-shadow: 0 0 8px var(--success); }
  @media (display-mode: standalone) { .install-top-btn { display: none; } }
  .install-top-btn { background: var(--accent-dim); color: var(--accent); border: 1px solid var(--accent); padding: 6px 11px; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; }

  .chat-box { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }
  .msg { max-width: 85%; padding: 13px 16px; border-radius: 14px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
  .msg.user { align-self: flex-end; background: #1b2838; border: 1px solid #2b425e; color: #fff; border-bottom-right-radius: 4px; }
    .msg.arcane { position: relative; padding-bottom: 34px !important; }
  .copy-btn { position: absolute; bottom: 8px; right: 12px; background: rgba(0,229,255,0.06); border: 1px solid rgba(0,229,255,0.25); color: rgba(0,229,255,0.8); font-size: 11px; padding: 3px 9px; border-radius: 6px; cursor: pointer; font-weight: 500; opacity: 0.6; transition: opacity 0.2s, background 0.2s; -webkit-tap-highlight-color: transparent; z-index: 5; }
  .copy-btn:hover, .copy-btn:active { opacity: 1; background: rgba(0,229,255,0.18); color: var(--accent); }
  .cursor { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: middle; margin-left: 3px; animation: blink 0.8s infinite; }
  @keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.2; } }

  .dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
  .dots span { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: bounce 1.2s infinite ease-in-out; }
  .dots span:nth-child(2) { animation-delay: 0.2s; }
  .dots span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1.2); opacity: 1; } }

  .composer { padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .file-pill { display: none; align-items: center; justify-content: space-between; background: var(--accent-dim); border: 1px solid var(--accent); color: var(--accent); padding: 6px 12px; border-radius: 8px; font-size: 12.5px; }
  .input-row { display: flex; gap: 8px; align-items: center; }
  .input-row textarea { flex: 1; height: 46px; max-height: 120px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 15px; resize: none; outline: none; }
  .input-row textarea:focus { border-color: var(--accent); }
  .send-btn { width: 82px; height: 46px; border-radius: 12px; font-weight: 700; cursor: pointer; background: var(--accent); color: #000; border: none; font-size: 14px; }
  .attach-btn { height: 46px; padding: 0 14px; border-radius: 12px; background: var(--bg); color: var(--text); border: 1px solid var(--border); cursor: pointer; font-size: 17px; }

  .modal-bg { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.75); z-index: 6000; align-items: center; justify-content: center; padding: 20px; }
  .modal { background: var(--panel); border: 1px solid var(--accent); border-radius: 14px; max-width: 420px; width: 100%; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
  .modal h3 { color: var(--accent); font-size: 16px; }
  .modal p, .modal li { font-size: 13.5px; color: var(--text); line-height: 1.5; }
  .modal ol { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }

  @media (max-width: 768px) {
    .sidebar { position: fixed; top: 0; bottom: 0; left: 0; transform: translateX(-100%); width: min(290px, 84vw); z-index: 5500; box-shadow: 10px 0 30px rgba(0,0,0,0.6); }
    .sidebar.open { transform: translateX(0); }
    .overlay { z-index: 5400; }
    .overlay.open { display: block; }
    .menu-btn { display: inline-flex; align-items: center; justify-content: center; margin-right: 6px; }
    .topbar { height: 52px; min-height: 52px; padding: 0 54px 0 8px; gap: 6px; }
    .chat-box { padding: 14px 12px; gap: 12px; }
    .msg { max-width: 92%; font-size: 15px; }
    .msg.user { max-width: calc(100% - 42px); }
  }
  @media (max-width: 480px) {
    .topbar > div:first-child > span:last-child { display: none; }
    .install-top-btn { padding: 5px 8px; font-size: 11px; white-space: nowrap; }
  }

.msg, .msg *, textarea, input {
    user-select: text !important;
    -webkit-user-select: text !important;
    -webkit-touch-callout: default !important;
  }
  .msg.arcane {
    position: relative !important;
  }
  .msg.arcane.has-copy {
    padding-bottom: 32px !important;
  }
  .arcane-copy-btn {
    position: absolute;
    bottom: 6px;
    right: 10px;
    background: rgba(0, 229, 255, 0.05);
    border: 1px solid rgba(0, 229, 255, 0.18);
    color: rgba(0, 229, 255, 0.75);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    opacity: 0.45;
    transition: opacity 0.2s, background 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none !important;
    -webkit-user-select: none !important;
    z-index: 10;
  }
  .arcane-copy-btn:hover, .arcane-copy-btn:active {
    opacity: 1;
    background: rgba(0, 229, 255, 0.18);
    color: #00e5ff;
  }

#sidebar, .sidebar {
    display: flex !important;
    flex-direction: column !important;
  }
  .arcane-mode-wrap {
    padding: 12px 12px 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 8px;
    flex-shrink: 0;
  }
  .arcane-mode-select {
    width: 100%;
    background: #141923;
    color: #fff;
    border: 1px solid rgba(0, 229, 255, 0.35);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, #00e5ff 50%), linear-gradient(135deg, #00e5ff 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(1em + 2px), calc(100% - 13px) calc(1em + 2px);
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
  }
  .arcane-chat-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 4px 12px 14px 12px;
    flex: 1;
    overflow: hidden;
  }
  #arcaneStudioSection {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 12px;
  }
  .arcane-new-chat-btn {
    width: 100%;
    background: linear-gradient(135deg, #00e5ff, #00b8d4);
    color: #06080c;
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 2px 10px rgba(0, 229, 255, 0.2);
    flex-shrink: 0;
  }
  .arcane-new-chat-btn:active {
    transform: scale(0.98);
  }
  .arcane-hist-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 6px;
    padding: 0 4px;
    font-weight: 600;
    flex-shrink: 0;
  }
  .arcane-hist-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    padding-right: 2px;
  }
  .arcane-hist-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 9px;
    padding: 9px 10px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    flex-shrink: 0;
  }
  .arcane-hist-item.active {
    background: rgba(0, 229, 255, 0.1);
    border-color: rgba(0, 229, 255, 0.4);
    color: #fff;
  }
  .arcane-hist-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    padding-right: 8px;
  }
  .arcane-hist-del {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 4px;
  }
  .arcane-hist-del:hover {
    color: #ff5252;
  }
  /* Settings Footer & Collapsible Share Panel */
  .arcane-settings-footer {
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 10px 12px;
    background: rgba(10, 13, 20, 0.95);
    flex-shrink: 0;
  }
  .arcane-settings-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    color: rgba(255, 255, 255, 0.88);
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.15s, border-color 0.15s;
  }
  .arcane-settings-btn:hover, .arcane-settings-btn.open {
    background: rgba(0, 229, 255, 0.09);
    border-color: rgba(0, 229, 255, 0.35);
    color: #fff;
  }
  .arcane-settings-drawer {
    display: none;
    margin-top: 8px;
    background: #111620;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px;
    max-height: 44vh;
    overflow-y: auto;
  }
  .arcane-settings-drawer.open {
    display: block;
  }
  .arcane-share-toggle {
    width: 100%;
    background: rgba(0, 229, 255, 0.07);
    border: 1px solid rgba(0, 229, 255, 0.25);
    color: #00e5ff;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .arcane-share-body {
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    text-align: center;
  }
  .arcane-share-body.open {
    display: block;
  }
