:root {
    --bg: #ffffff;
    --text: #000000;
    --muted: #444444;
    --border: #d8d2c3;
    --panel-bg: #e8e3d5;
    --user-bg: #ddd8ca;
    --assistant-bg: #ede9db;

    --panel-body-size: 17px;
    --panel-body-line-height: 1.7;
    --panel-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;

    --panel-top: 110px;
    --panel-width: 360px;
    --panel-expanded-width: 420px;
    --panel-inner-padding: 18px;
    --panel-input-min-height: 84px;

    --window-btn-size: 24px;
    --window-btn-radius: 8px;
    --window-btn-font-size: 13px;
    --panel-title-size: 15px;
  }

  #openBtn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1.5px solid #1a1a1a;
    background: #e8e3d5;
    color: #000000;
    font-size: 14px;
    cursor: pointer;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    font-family: var(--panel-font-family);
  }

  #openBtn:hover {
    background: #ddd8ca;
  }

  #miniCard {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: none;
    width: 188px;
    padding: 8px 14px;
    border-radius: 16px;
    border: 1.5px solid #1a1a1a;
    background: #e8e3d5;
    color: #000000;
    z-index: 9999;
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    font-family: var(--panel-font-family);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
    overflow: hidden;
  }

  #miniCard::before {
    content: "";
    position: absolute;
    inset: -20%;
    background: linear-gradient(
      115deg,
      rgba(255,255,255,0) 30%,
      rgba(255,255,255,0.08) 48%,
      rgba(255,255,255,0.03) 55%,
      rgba(255,255,255,0) 70%
    );
    transform: translateX(-120%) rotate(8deg);
    animation: miniCardSheen 10s ease-in-out infinite;
    pointer-events: none;
  }

  #miniCard:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(0,0,0,0.10);
    background: #dcd7c9;
  }

  #miniCard .mini-kicker {
    position: relative;
    z-index: 1;
    font-size: 14px;
    font-weight: 600;
    color: #555555;
    margin-bottom: 9px;
    line-height: 1.40;
  }

  #miniBtn {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    min-width: 150px;
    margin: 0 auto;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #111111;
    background: #111111;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    transition: background 0.18s ease, transform 0.18s ease;
    text-align: center;
  }

  #miniBtn:hover {
    background: #222222;
  }

  #mobileAskBtn {
    display: none;
  }

  @keyframes miniCardSheen {
    0% {
      transform: translateX(-120%) rotate(8deg);
      opacity: 0;
    }
    8% {
      opacity: 1;
    }
    22% {
      transform: translateX(120%) rotate(8deg);
      opacity: 1;
    }
    30% {
      opacity: 0;
    }
    100% {
      transform: translateX(120%) rotate(8deg);
      opacity: 0;
    }
  }

  #panel {
    position: fixed;
    top: var(--panel-top, 110px);
    right: calc(-1 * var(--panel-width, 360px));
    width: var(--panel-width, 360px);
    min-width: var(--panel-width, 360px);
    height: calc(100vh - var(--panel-top, 110px));
    background: var(--panel-bg);
    border-top: 1.5px solid #1a1a1a;
    border-left: 1.5px solid #1a1a1a;
    box-shadow: -8px 0 24px rgba(0,0,0,0.06);
    transition: right 0.25s ease, opacity 0.2s ease;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    color: #000000;
    font-family: var(--panel-font-family);
  }

  #panel.open {
    right: 0;
  }

  #panel.minimized {
    display: none;
  }

  #panel.expanded {
    width: var(--panel-expanded-width, 420px);
    min-width: var(--panel-expanded-width, 420px);
    right: 0;
  }

  #panelHeader {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #e8e3d5;
    color: #000000;
  }

  #panelTitle {
    font-weight: 600;
    font-size: var(--panel-title-size);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  #panelActions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
  }

  .window-btn-group {
    display: inline-flex;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: 8px;
    overflow: hidden;
  }

  .window-btn {
    width: var(--window-btn-size);
    height: var(--window-btn-size);
    border: none;
    border-right: 1px solid rgba(0,0,0,0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    font-size: var(--window-btn-font-size);
    font-weight: 700;
    color: rgba(0,0,0,0.78);
    transition: transform 0.08s ease, filter 0.08s ease, opacity 0.08s ease, background 0.08s ease;
  }

  .window-btn:last-child {
    border-right: none;
  }

  .window-btn:hover {
    filter: brightness(0.92);
  }

  .window-btn:active {
    transform: scale(0.96);
  }

  .window-btn-min {
    background: #f5c400;
  }

  .window-btn-max {
    background: #3dd163;
  }

  .window-btn-close {
    background: #f05a52;
  }

  #messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--panel-inner-padding);
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .msg {
    max-width: 100%;
    padding: 12px 14px;
    border-radius: 14px;
    word-wrap: break-word;
    color: #000000;
    font-family: var(--panel-font-family);
  }

  .msg.user {
    align-self: flex-end;
    background: var(--user-bg);
    border: 1px solid #ddd3be;
    white-space: pre-wrap;
    font-size: var(--panel-body-size);
    line-height: var(--panel-body-line-height);
  }

  .msg.assistant-wrap {
    align-self: flex-start;
    width: 100%;
    max-width: 100%;
  }

  .msg.assistant {
    background: var(--assistant-bg);
    border: 1px solid var(--border);
    color: #000000;
    white-space: normal;
    font-size: var(--panel-body-size);
    line-height: var(--panel-body-line-height);
  }

  .msg.thinking,
  .msg.status {
    align-self: flex-start;
    background: transparent;
    border: none;
    color: var(--muted);
    font-style: italic;
    padding-left: 0;
    white-space: pre-wrap;
    font-size: var(--panel-body-size);
    line-height: var(--panel-body-line-height);
    font-family: var(--panel-font-family);
  }

  .msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    padding-left: 4px;
  }

  .msg-action-btn {
    border: 1px solid var(--border);
    background: transparent;
    color: #555555;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    font-family: var(--panel-font-family);
  }

  .msg-action-btn:hover {
    background: rgba(0,0,0,0.03);
  }

  .msg.assistant,
  .msg.assistant * {
    color: #000000 !important;
    font-family: var(--panel-font-family) !important;
  }

  .msg.assistant p,
  .msg.assistant li,
  .msg.assistant ul,
  .msg.assistant ol,
  .msg.user,
  .msg.thinking,
  .msg.status {
    font-size: var(--panel-body-size) !important;
    line-height: var(--panel-body-line-height) !important;
  }

  .msg.assistant p {
    display: block !important;
    margin: 0 0 10px 0 !important;
  }

  .msg.assistant p:last-child {
    margin-bottom: 0 !important;
  }

  .msg.assistant ul {
    display: block !important;
    list-style: disc outside !important;
    margin: 6px 0 10px 20px !important;
    padding-left: 18px !important;
  }

  .msg.assistant ol {
    display: block !important;
    list-style: decimal outside !important;
    margin: 6px 0 10px 20px !important;
    padding-left: 18px !important;
  }

  .msg.assistant li {
    display: list-item !important;
    margin: 4px 0 !important;
  }

  .msg.assistant ul ul,
  .msg.assistant ol ul,
  .msg.assistant ul ol,
  .msg.assistant ol ol {
    margin-top: 4px !important;
    margin-bottom: 4px !important;
  }

  .msg.assistant strong,
  .msg.assistant b {
    font-weight: 700 !important;
  }

  .msg.assistant em,
  .msg.assistant i {
    font-style: italic !important;
  }

  .msg.assistant blockquote {
    margin: 10px 0 !important;
    padding: 8px 12px !important;
    border-left: 3px solid #cfc6b3 !important;
    background: rgba(0,0,0,0.03) !important;
    color: #222222 !important;
  }

  .msg.assistant hr {
    border: none !important;
    border-top: 1px solid var(--border) !important;
    margin: 12px 0 !important;
  }

  .msg.assistant code {
    display: inline !important;
    background: rgba(0,0,0,0.06) !important;
    padding: 1px 4px !important;
    border-radius: 4px !important;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace !important;
    font-size: 0.9em !important;
  }

  .msg.assistant pre {
    display: block !important;
    background: rgba(0,0,0,0.06) !important;
    padding: 10px !important;
    border-radius: 8px !important;
    overflow-x: auto !important;
    margin: 8px 0 10px 0 !important;
  }

  .msg.assistant pre code {
    display: block !important;
    background: transparent !important;
    padding: 0 !important;
  }

  .msg.assistant table {
    display: block !important;
    width: 100% !important;
    overflow-x: auto !important;
    border-collapse: collapse !important;
    margin: 8px 0 10px 0 !important;
  }

  .msg.assistant th,
  .msg.assistant td {
    border: 1px solid var(--border) !important;
    padding: 6px 8px !important;
    text-align: left !important;
    vertical-align: top !important;
  }

  .msg.assistant h1 {
    display: block !important;
    font-size: 1.08em !important;
    line-height: 1.27 !important;
    margin: 0 0 6px 0 !important;
    font-weight: 700 !important;
  }

  .msg.assistant h2 {
    display: block !important;
    font-size: 1.03em !important;
    line-height: 1.27 !important;
    margin: 0 0 6px 0 !important;
    font-weight: 700 !important;
  }

  .msg.assistant h3,
  .msg.assistant h4,
  .msg.assistant h5,
  .msg.assistant h6 {
    display: block !important;
    font-size: 0.99em !important;
    line-height: 1.27 !important;
    margin: 0 0 6px 0 !important;
    font-weight: 700 !important;
  }

  #inputArea {
    border-top: 1px solid var(--border);
    background: #e8e3d5;
    padding: 12px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
  }

  #input {
    flex: 1;
    min-height: var(--panel-input-min-height);
    padding: 12px 14px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 12px;
    outline: none;
    background: #f5f2ea;
    color: #000000;
    font-family: var(--panel-font-family);
    resize: vertical;
  }

  #input::placeholder {
    color: #777777;
  }

  #input:focus {
    border-color: #b9ad95;
  }

  #sendBtn {
    padding: 0 14px;
    height: 44px;
    border: 1px solid #111111;
    border-radius: 12px;
    background: #111111;
    color: white;
    font-size: 14px;
    cursor: pointer;
  }

  #sendBtn:disabled {
    opacity: 0.5;
    cursor: default;
  }

  @media (max-width: 768px) {
    #openBtn,
    #miniCard {
      display: none !important;
    }

    #mobileAskBtn {
      position: fixed;
      right: 8px;
      bottom: 12px;
      width: 30px;
      height: 33px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 0;
      border-radius: 14px;
      border: 1.5px solid #1a1a1a;
      background: #e8e3d5;
      color: #111111;
      font-family: var(--panel-font-family);
      text-align: center;
      z-index: 9999;
      box-shadow: 0 2px 8px rgba(0,0,0,0.06);
      cursor: pointer;
      padding: 0;
    }

    #mobileAskBtn:hover {
      background: #ddd8ca;
    }

    #mobileAskBtn .ask-ai-label {
      font-size: 8px;
      font-weight: 700;
      line-height: 1;
      letter-spacing: 0;
    }

    #mobileAskBtn .ask-ai-sparkle {
      font-size: 10px;
      line-height: 1;
      margin-top: 1px;
    }

    #panel {
      top: auto;
      right: -100vw;
      bottom: 0;
      width: 100vw;
      min-width: 100vw;
      height: calc(100vh - 140px);
      border-left: none;
      border-top: 1px solid var(--border);
      border-top-left-radius: 18px;
      border-top-right-radius: 18px;
      box-shadow: 0 -8px 24px rgba(0,0,0,0.10);
    }

    #panel.open {
      right: 0;
    }

    #panelHeader {
      padding: 16px;
    }

    #messages {
      padding: 16px;
    }

    #inputArea {
      padding: 12px 16px 16px 16px;
    }

    #input {
      min-height: 72px;
      font-size: 16px;
    }

    #sendBtn {
      height: 46px;
      min-width: 72px;
    }

    .window-btn {
      width: 24px;
      height: 24px;
      font-size: 12px;
    }
  }

  @media (min-width: 600px) and (max-width: 768px) {
    #mobileAskBtn {
      width: 32px;
      height: 32px;
      right: 10px;
      bottom: 14px;
    }

    #mobileAskBtn .ask-ai-label {
      font-size: 7px;
    }

    #mobileAskBtn .ask-ai-sparkle {
      font-size: 9px;
    }
  }
