:root {
  --night: #090b12;
  --night-soft: #10131e;
  --night-raised: #161a28;
  --paper: #f7f8fc;
  --white: #fff;
  --ink: #171923;
  --muted: #73798a;
  --muted-dark: #969daf;
  --line: #e4e6ed;
  --line-dark: rgba(255, 255, 255, 0.11);
  --violet: #6958f5;
  --violet-deep: #5542ec;
  --cyan: #54d7f5;
  --green: #3ed598;
  --danger: #b84755;
  --shadow: 0 32px 90px rgba(10, 12, 22, 0.22);
  --viewport-height: 100dvh;
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--night); }
html { overflow-x: hidden; }
body { min-width: 0; color: var(--ink); overflow-x: hidden; }
button, textarea { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid rgba(84, 215, 245, 0.72);
  outline-offset: 2px;
}
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.gradio-container {
  width: 100%;
  min-height: 100vh;
  min-height: var(--viewport-height);
  margin: 0;
  padding: max(0px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) calc(36px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 10% 20%, rgba(105, 88, 245, 0.18), transparent 29rem),
    radial-gradient(circle at 92% 8%, rgba(84, 215, 245, 0.11), transparent 26rem),
    var(--night);
}

#page-header {
  max-width: 1260px;
  margin: 0 auto;
  padding: 22px 4px 18px;
}
.site-header { display: flex; align-items: center; justify-content: flex-end; gap: 24px; color: var(--white); }
.header-meta { display: flex; align-items: center; gap: 13px; color: #c2c7d3; font-size: 11px; }
.version-badge {
  padding: 5px 8px;
  border: 1px solid rgba(84, 215, 245, 0.2);
  border-radius: 999px;
  background: rgba(84, 215, 245, 0.07);
  color: var(--cyan);
  font: 650 8px/1 "SFMono-Regular", Consolas, monospace;
  letter-spacing: 0.08em;
}
.header-divider { width: 1px; height: 13px; background: var(--line-dark); }
.header-status, .live-indicator { display: inline-flex; align-items: center; gap: 7px; text-transform: uppercase; letter-spacing: 0.1em; font: 600 9px/1 "SFMono-Regular", Consolas, monospace; }
.header-status i, .live-indicator i { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(62, 213, 152, 0.12); }

#twin-shell {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 2fr);
  align-items: stretch;
  max-width: 1260px;
  min-height: 720px;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line-dark);
  border-radius: 28px;
  background: var(--night-soft);
  box-shadow: var(--shadow);
}
#profile-panel, #chat-panel { min-width: 0; }
#profile-panel {
  position: relative;
  overflow: hidden;
  background: linear-gradient(145deg, rgba(105, 88, 245, 0.16), transparent 38%), var(--night-soft);
  color: var(--white);
}
#profile-panel::after {
  position: absolute;
  right: -110px;
  bottom: -120px;
  width: 300px;
  height: 300px;
  border: 1px solid rgba(84, 215, 245, 0.12);
  border-radius: 50%;
  box-shadow: 0 0 0 40px rgba(84, 215, 245, 0.025), 0 0 0 80px rgba(105, 88, 245, 0.025);
  content: "";
  pointer-events: none;
}
#chat-panel { position: relative; display: flex; flex-direction: column; padding: 0 30px 22px; border-radius: 26px 0 0 26px; background: var(--paper); }
.profile-card { position: relative; z-index: 1; display: flex; min-height: 100%; flex-direction: column; padding: 32px; }
.profile-index { color: var(--muted-dark); font: 600 9px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.15em; }
.profile-photo-wrap { position: relative; width: 156px; height: 222px; margin: 24px 0; }
.profile-photo { display: block; width: 100%; height: 100%; border: 2px solid rgba(255, 255, 255, 0.18); border-radius: 28px; object-fit: cover; box-shadow: 0 20px 42px rgba(0, 0, 0, 0.34), 0 0 0 6px rgba(105, 88, 245, 0.1); }
.profile-photo-wrap i { position: absolute; right: -2px; bottom: 7px; width: 16px; height: 16px; border: 3px solid var(--night-soft); border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 4px rgba(84, 215, 245, 0.1); }
.profile-identity { display: flex; align-items: baseline; gap: 6px; margin: 0 0 10px; }
.profile-kicker { margin: 0; color: var(--cyan); font: 800 19px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: -0.06em; }
.profile-kicker span { color: var(--cyan); }
.profile-name { margin: 0; color: var(--cyan); font-size: 14px; font-weight: 700; letter-spacing: 0.01em; }
.profile-main h1 { max-width: 390px; margin: 0; color: var(--white); font-size: clamp(30px, 3.3vw, 46px); line-height: 1.04; letter-spacing: -0.045em; }
.profile-copy { max-width: 390px; margin: 22px 0 0; color: var(--muted-dark); font-size: 13px; line-height: 1.72; }
.expertise { margin-top: 34px; }
.expertise > p { margin: 0 0 12px; color: #656d83; font: 600 9px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.14em; }
.expertise > div { display: flex; flex-wrap: wrap; gap: 8px; }
.expertise span { padding: 8px 11px; border: 1px solid var(--line-dark); border-radius: 999px; background: rgba(255, 255, 255, 0.035); color: #c6cad5; font-size: 10px; line-height: 1; }
.profile-disclosure { display: flex; align-items: flex-start; gap: 11px; margin-top: auto; padding-top: 32px; border-top: 1px solid var(--line-dark); }
.disclosure-icon { display: grid; width: 29px; height: 29px; flex: 0 0 29px; place-items: center; border-radius: 9px; background: rgba(84, 215, 245, 0.12); color: var(--cyan); font: 700 9px/1 "SFMono-Regular", Consolas, monospace; }
.profile-disclosure p { margin: 0; color: #7f879a; font-size: 10px; line-height: 1.55; }

.chat-topbar { display: flex; min-height: 82px; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--line); }
.assistant-identity { display: flex; min-width: 0; align-items: center; gap: 11px; }
.assistant-avatar { display: block; width: 30px; height: 42px; flex: 0 0 30px; border: 2px solid rgba(105, 88, 245, 0.28); border-radius: 9px; background: var(--white); object-fit: cover; box-shadow: 0 5px 14px rgba(37, 31, 92, 0.14); }
.assistant-identity p, .assistant-identity div > span { display: block; }
.assistant-identity p { margin: 0; color: var(--ink); font-size: 13px; font-weight: 680; }
.assistant-identity div > span { margin-top: 2px; color: var(--muted); font-size: 10px; }
.chat-controls { display: flex; align-items: center; gap: 14px; }
.live-indicator { color: var(--muted); }
#sound-toggle {
  position: absolute;
  top: 24px;
  right: 132px;
  z-index: 5;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  padding: 0;
  border: 1px solid #dfe2ea;
  border-radius: 11px;
  background: var(--white);
  color: var(--violet-deep);
  cursor: pointer;
  font: 700 16px/1 Inter, sans-serif;
}
#sound-toggle::before { position: absolute; width: 44px; height: 44px; content: ""; }
#sound-toggle:hover { border-color: rgba(105, 88, 245, 0.45); background: #f0eefe; }

#twin-chat {
  height: auto;
  min-height: 430px;
  max-height: 590px;
  flex: 1 1 430px;
  margin-top: 18px;
  overflow: hidden auto;
  overscroll-behavior: contain;
  border-radius: 20px;
  background: radial-gradient(circle at 85% 5%, rgba(105, 88, 245, 0.055), transparent 20rem), #eef0f6;
  box-shadow: inset 0 0 0 1px rgba(26, 30, 45, 0.055);
  scrollbar-color: #c7cad4 transparent;
}
.message-list { display: flex; min-height: 100%; flex-direction: column; gap: 11px; padding: 18px; }
.message-row { display: flex; width: 100%; }
.message-row.user-row { justify-content: flex-end; }
.message-row.bot-row { justify-content: flex-start; }
.message {
  position: relative;
  width: max-content;
  min-width: 0;
  max-width: min(90%, 760px);
  padding: 11px 14px;
  border: 0;
  font-size: 13px;
  line-height: 1.58;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 22px rgba(24, 27, 40, 0.06);
}
.user.message { min-width: 120px; border-radius: 18px 18px 5px 18px; background: var(--violet); color: var(--white); white-space: pre-wrap; }
.bot.message { width: min(90%, 760px); min-width: min(280px, 90%); border: 1px solid rgba(23, 25, 35, 0.06); border-radius: 18px 18px 18px 5px; background: var(--white); color: var(--ink); }
.message-content > :first-child { margin-top: 0; }
.message-content > :last-child { margin-bottom: 0; }
.message-content p { margin: 0 0 9px; color: inherit; font-size: inherit; line-height: inherit; }
.message-content h1, .message-content h2, .message-content h3, .message-content h4, .message-content h5, .message-content h6 { margin: 12px 0 6px; color: inherit; font-size: 1em; line-height: 1.35; }
.message-content h1 { font-size: 1.18em; }
.message-content h2 { font-size: 1.12em; }
.message-content ul, .message-content ol { margin: 6px 0 9px; padding-left: 21px; }
.message-content li + li { margin-top: 3px; }
.message-content code { padding: 1px 4px; border-radius: 5px; background: #f0eefb; color: #4634b5; font: 0.92em/1.4 "SFMono-Regular", Consolas, monospace; }
.message-content a { color: var(--violet-deep); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.message-content a:hover { color: #3f2ad5; }
.response-status { display: inline-flex; align-items: center; gap: 8px; color: #747b8d; font-size: 12px; font-weight: 560; letter-spacing: 0.01em; }
.status-pulse { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: var(--violet); box-shadow: 0 0 0 0 rgba(105, 88, 245, 0.3); animation: twin-status-pulse 1.25s ease-out infinite; }
@keyframes twin-status-pulse { 70% { box-shadow: 0 0 0 6px rgba(105, 88, 245, 0); } 100% { box-shadow: 0 0 0 0 rgba(105, 88, 245, 0); } }
.source-footer { margin-top: 12px; padding-top: 9px; border-top: 1px solid #eceef3; color: #858b99; font-size: 9px; line-height: 1.35; }
.message-tools { display: flex; justify-content: flex-end; height: 0; opacity: 0; transition: opacity 120ms ease; }
.bot.message:hover .message-tools, .bot.message:focus-within .message-tools { opacity: 1; }
.copy-button { position: relative; top: 3px; right: -8px; display: grid; width: 28px; height: 28px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--white); color: #818797; cursor: pointer; font-size: 13px; }
.copy-button::before { position: absolute; width: 44px; height: 44px; content: ""; }
.copy-button:hover { color: var(--violet-deep); border-color: rgba(105, 88, 245, 0.35); }
.empty-chat { margin: auto; color: var(--muted); font-size: 12px; text-align: center; }
.error-message { color: #742e38; }
.retry-button { min-height: 44px; margin-top: 10px; padding: 7px 12px; border: 1px solid rgba(184, 71, 85, 0.25); border-radius: 10px; background: #fff7f8; color: var(--danger); cursor: pointer; font-size: 11px; font-weight: 650; }
.retry-button:hover { border-color: rgba(184, 71, 85, 0.5); background: #fff1f3; }


#verification-row { position: relative; display: flex; min-height: 24px; align-items: center; justify-content: flex-end; margin-top: 6px; }
#turnstile-widget { position: absolute; z-index: 4; right: 0; width: min(100%, 300px); min-height: 1px; }
#turnstile-widget iframe { max-width: 100%; }
#verification-state { display: inline-flex; min-height: 24px; align-items: center; gap: 7px; color: #969ba8; font: 600 8px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: 0.04em; text-transform: uppercase; }
#verification-state i { width: 6px; height: 6px; border-radius: 50%; background: #c4c7d0; }
#verification-row[data-state="ready"] #verification-state i { background: var(--green); }
#verification-row[data-state="error"] #verification-state i { background: var(--danger); }

#composer { display: flex; align-items: center; gap: 8px; margin-top: 3px; padding: 6px 7px 6px 17px; border: 1px solid #d7dae4; border-radius: 18px; background: var(--white); box-shadow: 0 12px 30px rgba(24, 27, 40, 0.08); }
#composer:focus-within { border-color: rgba(105, 88, 245, 0.58); box-shadow: 0 12px 30px rgba(24, 27, 40, 0.08), 0 0 0 3px rgba(105, 88, 245, 0.08); }
#message-box { width: 100%; min-width: 0; min-height: 45px; max-height: 116px; resize: none; padding: 11px 0; overflow-y: auto; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 13px; line-height: 1.45; }
#message-box::placeholder { color: #9da2af; }
#send-button { display: grid; width: 46px; min-width: 46px; height: 46px; flex: 0 0 46px; place-items: center; padding: 0; border: 0; border-radius: 14px; background: linear-gradient(135deg, var(--violet), #8d6cff); color: var(--white); box-shadow: 0 8px 20px rgba(105, 88, 245, 0.3); cursor: pointer; font-size: 23px; line-height: 1; transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease; }
#send-button:hover:not(:disabled) { transform: translateY(-1px); background: linear-gradient(135deg, var(--violet-deep), #8063f8); box-shadow: 0 11px 25px rgba(105, 88, 245, 0.38); }
#send-button:active:not(:disabled) { transform: translateY(0); }
#send-button:disabled { cursor: not-allowed; opacity: 0.42; box-shadow: none; }

.not-found-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: var(--night); color: var(--paper); }
.not-found-card { width: min(100%, 440px); padding: 32px; border: 1px solid var(--line-dark); border-radius: 22px; background: var(--night-soft); text-align: center; }
.not-found-card p { color: var(--muted-dark); line-height: 1.6; }
.not-found-card a { display: inline-flex; min-height: 44px; align-items: center; margin-top: 8px; padding: 0 18px; border-radius: 12px; background: var(--violet); color: var(--white); text-decoration: none; }
.not-found-card a:hover { background: var(--violet-deep); }

@media (max-width: 880px) {
  .gradio-container { padding-right: max(14px, env(safe-area-inset-right)); padding-bottom: calc(26px + env(safe-area-inset-bottom)); padding-left: max(14px, env(safe-area-inset-left)); }
  #page-header { padding: 16px 4px 14px; }
  #twin-shell { display: flex; min-height: 0; flex-direction: column; border-radius: 20px; }
  #profile-panel, #chat-panel { width: 100%; }
  #chat-panel { padding: 0 22px 20px; border-radius: 20px 20px 0 0; }
  .profile-card { min-height: 0; padding: 26px; }
  .profile-main h1 { max-width: 560px; font-size: 32px; }
  .profile-copy { max-width: 560px; }
  .expertise { margin-top: 24px; }
  .profile-disclosure { margin-top: 26px; padding-top: 20px; }
  .chat-topbar { min-height: 76px; }
  #twin-chat { height: 52vh; min-height: 400px; max-height: none; flex: none; }
}

@media (max-width: 560px) {
  .gradio-container { width: 100%; max-width: 100%; padding-right: max(10px, env(safe-area-inset-right)); padding-bottom: calc(14px + env(safe-area-inset-bottom)); padding-left: max(10px, env(safe-area-inset-left)); overflow-x: clip; }
  #page-header, #twin-shell { width: 100%; max-width: 100%; }
  #page-header { padding: 14px 2px 12px; }
  .site-header { gap: 10px; }
  .header-meta { flex: 0 0 auto; gap: 9px; }
  .header-meta > span:first-child, .header-divider { display: none; }
  .header-status { gap: 0; font-size: 0; }
  #twin-shell { min-width: 0; margin: 0; border-radius: 18px; }
  #profile-panel { flex: 0 0 auto; }
  .profile-card { min-height: 0; padding: 18px 20px 19px; }
  .profile-index, .profile-photo-wrap, .profile-copy, .expertise, .profile-disclosure { display: none; }
  .profile-identity { gap: 5px; margin-bottom: 7px; }
  .profile-kicker { font-size: 17px; }
  .profile-name { font-size: 12px; }
  .profile-main h1 { max-width: 100%; font-size: clamp(24px, 8vw, 30px); line-height: 1.05; }
  #chat-panel { padding: 0 12px 16px; border-radius: 0; }
  .chat-topbar { min-height: 68px; gap: 8px; }
  .assistant-identity { gap: 9px; }
  .assistant-avatar { width: 28px; height: 40px; flex-basis: 28px; border-radius: 8px; }
  .assistant-identity > div { min-width: 0; }
  .assistant-identity p, .assistant-identity div > span { overflow: hidden; max-width: calc(100vw - 164px); text-overflow: ellipsis; white-space: nowrap; }
  .live-indicator { gap: 0; font-size: 0; }
  #sound-toggle { top: 17px; right: 43px; }
  #twin-chat { height: clamp(300px, 42svh, 420px); min-height: 300px; margin-top: 12px; }
  .message-list { padding: 12px 8px; }
  .message { max-width: 96%; }
  .bot.message { width: 96%; min-width: min(280px, 96%); }
  .message-tools { opacity: 1; }
  #verification-row { min-height: 22px; overflow: visible; }
  #turnstile-widget { width: min(100%, 280px); }
  #verification-state { font-size: 7px; }
  #composer { gap: 8px; }
  #message-box { font-size: 16px; }

  :where(body.typing-mode, body:has(#message-box:focus)) #page-header,
  :where(body.typing-mode, body:has(#message-box:focus)) #profile-panel,
  :where(body.typing-mode, body:has(#message-box:focus)) #chat-heading,
  :where(body.typing-mode, body:has(#message-box:focus)) #sound-toggle,
  :where(body.typing-mode, body:has(#message-box:focus)) #verification-row { display: none; }
  :where(body.typing-mode, body:has(#message-box:focus)) .gradio-container { display: flex; min-height: var(--viewport-height); align-items: flex-end; padding-top: 8px; }
  :where(body.typing-mode, body:has(#message-box:focus)) #twin-shell { width: 100%; max-height: var(--viewport-height); }
  :where(body.typing-mode, body:has(#message-box:focus)) #chat-panel { border-radius: 18px; }
  :where(body.typing-mode, body:has(#message-box:focus)) #twin-chat { height: clamp(210px, 28svh, 240px); min-height: 210px; }
  :where(body.typing-mode, body:has(#message-box:focus)) #composer { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
