:root {
    --brand-main: #003875;
    --brand-accent: #feb82b;
    --bg: #0c1422;
    --bg-lighter: #152033e6;
    --bg-lightest: #243356cc;
    --surface: #162138d0;
    --surface-glass: rgba(22,33,56,0.70);
    --border: #25375872;
    --text: #f8faff;
    --text-muted: #99aac6;
    --chat-bot-bg: #273b5be8;
    --chat-user-bg: linear-gradient(130deg, #003875 85%, #feb82b 100%);
    --chat-bot-text: #e8eefa;
    --chat-user-text: #fff;
    --error-bg: #6d0111cc;
    --error-text: #fcbcbc;
    --glass-blur: blur(18px);
  }
  
  html, body {
    height: 100%;
    margin: 0;
    font-family: 'Segoe UI', 'Roboto', Arial, sans-serif;
    background: linear-gradient(120deg, #14213d 0%, #1a233b 60%, #0c1322 100%);
    color: var(--text);
    overflow: hidden;
  }
  
  #centering-wrapper {
    height: 100vh;
    width: 100vw;
    min-height: 100vh;
    min-width: 100vw;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Main chat container with glassmorphism */
  #chat-container {
    background: var(--surface-glass);
    box-shadow: 0 6px 48px 0 rgba(0,0,0,0.44), 0 2px 6px 0 rgba(0, 0, 0, 0.2);
    border-radius: 22px;
    width: 100%;
    max-width: 420px;
    min-width: 312px;
    display: flex;
    flex-direction: column;
    min-height: 470px;
    max-height: 92vh;
    margin: 3vh 0;
    overflow: hidden;
    border: 1.5px solid var(--border);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    transition: box-shadow 0.35s cubic-bezier(.57,1.31,.25,1);
    animation: fadeInContainer 0.6s cubic-bezier(.45,1.2,.16,1) 0s 1 backwards;
  }
  
  @keyframes fadeInContainer {
    from { opacity: 0; transform: scale(0.94);}
    to   { opacity: 1; transform: none;}
  }
  
  /* Header with logo */
  header {
    background: linear-gradient(90deg, var(--brand-main) 70%, var(--brand-accent) 120%);
    color: #fff;
    padding: 1.2rem 1rem 1.0rem 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    position: relative;
    gap: 0.9rem;
    border-bottom: 1.5px solid #ffffff11;
    box-shadow: 0 1px 8px 0 rgba(0,0,0,0.07);
  }
  
  header .logo {
    height: 35px;
    width: 35px;
    border-radius: 11px;
    background: #fff7;
    object-fit: contain;
    margin-right: 0.6rem;
    filter: drop-shadow(0 0 6px #00387555);
  }
  
  header h1 {
    font-size: 1.25rem;
    margin: 0;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-shadow: 0 2px 8px #0003;
    user-select: none;
    padding-right: 8px;
  }
  
  /* Chat area with glass and custom scrollbar */
  #chat {
    flex: 1;
    overflow-y: auto;
    padding: 1.2rem 0.6rem 1rem 0.6rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    background: var(--bg-lighter);
    scrollbar-width: thin;
    scrollbar-color: var(--brand-main) var(--bg);
    position: relative;
    transition: background 0.2s;
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
  }
  
  #chat::-webkit-scrollbar {
    width: 7px;
  }
  #chat::-webkit-scrollbar-thumb {
    background: var(--brand-main);
    border-radius: 10px;
  }
  #chat::-webkit-scrollbar-track {
    background: transparent;
  }
  
  /* Row holding bubble & avatar, flex direction per side */
  .msg-row {
    display: flex;
    align-items: flex-end;
    margin-bottom: 0.1rem;
    animation: messageIn 0.19s cubic-bezier(.58,1.4,.28,1) backwards;
    opacity: 0.98;
  }
  
  @keyframes messageIn {
    from { opacity: 0; transform: translateY(14px) scale(0.90);}
    to   { opacity: 0.98; transform: none;}
  }
  
  .msg-row.user {
    justify-content: flex-end;
  }
  
  .msg-row.bot, .msg-row.bot.error {
    justify-content: flex-start;
  }
  
  /* Bubble + avatar container */
  .msg-bubble {
    display: flex;
    align-items: flex-end;
    gap: 0.68rem;
    min-width: 0;
    max-width: 94vw;
  }
  
  .msg-row.user .msg-bubble {
    flex-direction: row-reverse;
  }
  
  .avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 7px #0138752a;
    border: 2px solid #fff7;
    background: #fff7;
    transition: box-shadow 0.2s;
    flex-shrink: 0;
    margin-bottom: 0.15rem;
    /* subtle effect on hover for fun */
  }
  .avatar:hover {
    box-shadow: 0 4px 17px #00387565, 0 0 0 2.2px #fff8;
  }
  
  /* Chat bubbles */
  .msg-text {
    max-width: 260px;
    padding: 0.88em 1.19em;
    border-radius: 1.2em;
    font-size: 1.05rem;
    line-height: 1.47;
    word-break: break-word;
    margin-bottom: 0.07em;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    position: relative;
    opacity: 0.99;
    background-clip: padding-box;
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    border: 1px solid #ffffff18;
    transition: background 0.2s, border 0.19s;
  }
  
  .msg-row.user .msg-text {
    background: var(--chat-user-bg);
    color: var(--chat-user-text);
    border-bottom-right-radius: 0.5em;
    margin-left: 2.5px;
    box-shadow: 2px 3px 12px 0 #00387533;
    border-right: 2.5px solid var(--brand-accent);
  }
  
  .msg-row.bot .msg-text {
    background: var(--chat-bot-bg);
    color: var(--chat-bot-text);
    border-bottom-left-radius: 0.55em;
    margin-right: 2.5px;
    border-left: 2.5px solid var(--brand-main);
  }
  
  .msg-row.bot.error .msg-text {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1.5px solid #ff9595b6;
  }
  
  /* Subtle pop animation for bubble */
  .msg-text {
    animation: bubblePop 0.38s cubic-bezier(.62,1.67,.54,.97) backwards;
  }
  @keyframes bubblePop {
    from { opacity: 0; transform: scale(0.66);}
    to   { opacity: 0.99; transform: none;}
  }
  
  /* Form and input with glass, blur, min animation */
  form#send {
    background: var(--bg-lightest);
    padding: 0.97rem 1.1rem 1.0rem 1.15rem;
    display: flex;
    align-items: center;
    border-top: 1.5px solid var(--border);
    gap: 0.78rem;
    transition: background 0.18s;
    backdrop-filter: blur(13px);
    -webkit-backdrop-filter: blur(13px);
  }
  
  form#send input[type="text"], 
  form#send input[type="search"],
  form#send input {
    flex: 1;
    font-size: 1.06rem;
    padding: 0.64rem 1.12rem;
    border: 1.7px solid var(--border);
    border-radius: 9px;
    background: var(--surface-glass);
    color: var(--text);
    outline: none;
    transition: border 0.18s, background 0.18s;
    box-shadow: 0 2px 14px #0038751a inset;
    min-width: 0;
  }
  form#send input:focus {
    border: 1.8px solid var(--brand-accent);
    background: var(--bg-lightest);
  }
  
  form#send button {
    height: 42px;
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0.2em;
    font-size: 1.08rem;
    background: linear-gradient(120deg, var(--brand-accent) 80%, #fffbea 115%);
    color: #1e223b;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.13s, filter 0.13s, box-shadow 0.13s;
    font-weight: 600;
    box-shadow: 0 2px 12px rgba(254,184, 43, 0.07) inset, 0 1.5px 4px #feb82b0f;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
  }
  form#send button:active {
    filter: brightness(1.05) drop-shadow(0 2px 6px #feb82b32);
  }
  form#send button:focus {
    outline: 2px solid #feb82b9c;
    box-shadow: 0 0 0 3px #feb82b47;
  }
  
  form#send button svg {
    display: block;
    margin: 0 auto;
  }
  
  @media (max-width: 520px) {
    #chat-container {
      border-radius: 0;
      max-width: 100vw;
      width: 100vw;
      height: 100vh;
      min-height: 100vh;
      margin: 0;
    }
    #chat {
      padding: 0.6rem 0.25rem 1rem 0.25rem;
    }
    header {
      padding: 0.9rem 0.5rem 0.7rem 0.7rem;
    }
  }
  
  @media (max-height: 600px) {
    #centering-wrapper {
      align-items: flex-start;
    }
    #chat-container {
      margin: 5px 0;
      min-height: unset;
      max-height: 99vh;
    }
  }
  
  /* Visually hidden helper */
  .visually-hidden {
    position: absolute;
    left: -10000px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
  ::selection {
    background: var(--brand-accent);
    color: #1a1c22;
  }