:root {
  color-scheme: dark;

  --bg0: #05070d;
  --bg1: #0a0f1a;
  --panel: rgba(10, 18, 32, 0.88);
  --panel-strong: rgba(8, 15, 28, 0.94);
  --panel-border: rgba(87, 204, 255, 0.35);
  --panel-glow: rgba(52, 190, 255, 0.28);

  --text: #eef7ff;
  --muted: #9bb3c9;
  --line: rgba(92, 140, 190, 0.28);

  --input-bg: rgba(5, 12, 24, 0.92);
  --input-border: rgba(87, 204, 255, 0.32);
  --input-border-focus: rgba(98, 220, 255, 0.95);

  --primary: #22c7ff;
  --primary-2: #79e3ff;
  --primary-dark: #0f79b8;

  --secondary: #13243d;
  --danger: #ff9c9c;
  --success: #98ffd7;
  --warning: #ffd88a;

  --shadow-soft: 0 0 20px rgba(34, 199, 255, 0.10);
  --shadow-strong: 0 18px 55px rgba(0, 0, 0, 0.50);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at 20% 20%, rgba(30, 110, 180, 0.18), transparent 30%),
    radial-gradient(circle at 80% 15%, rgba(0, 180, 255, 0.10), transparent 28%),
    radial-gradient(circle at 50% 100%, rgba(0, 120, 255, 0.12), transparent 35%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color: var(--text);
}

body {
  position: relative;
  padding: 24px;
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(255,255,255,0.015) 0px,
      rgba(255,255,255,0.015) 1px,
      transparent 2px,
      transparent 4px
    );
  opacity: 0.25;
  mix-blend-mode: screen;
}

body::after {
  background:
    radial-gradient(circle at center, rgba(34, 199, 255, 0.08), transparent 45%);
  filter: blur(24px);
  animation: ambientPulse 5s ease-in-out infinite;
}

@keyframes ambientPulse {
  0%, 100% {
    opacity: 0.45;
    transform: scale(1);
  }
  50% {
    opacity: 0.85;
    transform: scale(1.03);
  }
}

@keyframes tubeGlow {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(87, 204, 255, 0.06),
      0 0 18px rgba(34, 199, 255, 0.08),
      0 0 36px rgba(34, 199, 255, 0.10),
      0 18px 55px rgba(0, 0, 0, 0.50);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(110, 232, 255, 0.12),
      0 0 22px rgba(34, 199, 255, 0.20),
      0 0 48px rgba(34, 199, 255, 0.22),
      0 18px 55px rgba(0, 0, 0, 0.52);
  }
}

@keyframes beacon {
  0%, 100% {
    transform: scale(1);
    opacity: 0.95;
  }
  50% {
    transform: scale(1.18);
    opacity: 1;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes tokenGlow {
  from {
    background: rgba(70, 130, 180, 0.15);
  }
  to {
    background: transparent;
  }
}

/* Layout */
header,
main,
footer {
  position: relative;
  z-index: 1;
}

main {
  width: min(1100px, 100%);
  margin: 0 auto;
}

header {
  width: min(1100px, 100%);
  margin: 0 auto 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  padding: 22px 24px 18px;
  backdrop-filter: blur(12px);
  box-shadow:
    0 0 0 1px rgba(87, 204, 255, 0.06),
    0 0 20px rgba(34, 199, 255, 0.10),
    0 0 40px rgba(34, 199, 255, 0.10),
    var(--shadow-strong);
  animation: tubeGlow 2.8s ease-in-out infinite;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  padding: 1px;
  background: linear-gradient(
    135deg,
    rgba(110, 232, 255, 0.85),
    rgba(20, 134, 255, 0.25),
    rgba(110, 232, 255, 0.7)
  );
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
  opacity: 0.9;
}

header::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  pointer-events: none;
  box-shadow:
    inset 0 0 18px rgba(75, 210, 255, 0.07),
    inset 0 0 34px rgba(75, 210, 255, 0.04);
}

header h1 {
  margin: 0 0 4px;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  text-shadow:
    0 0 8px rgba(121, 227, 255, 0.18),
    0 0 18px rgba(34, 199, 255, 0.18);
}

header h3 {
  margin: 0;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.96rem;
}

header nav {
  margin-top: 10px;
}

header nav a {
  color: var(--primary-2);
  text-decoration: none;
  margin-right: 15px;
}

header nav a:hover {
  text-decoration: underline;
}

/* Main sections */
.chat-box,
.controls-row,
.slider-wrap,
#feedback-container,
#cancel-area,
#timer,
.input-area,
.roxy-help-container {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(12px);
  box-shadow:
    0 0 0 1px rgba(87, 204, 255, 0.06),
    0 0 12px rgba(34, 199, 255, 0.06),
    0 10px 30px rgba(0, 0, 0, 0.35);
}

.chat-box {
  min-height: 55vh;
  padding: 18px;
  overflow: auto;
  background: rgba(10, 18, 32, 0.76);
}

#mode-banner {
  display: none;
  text-align: center;
  margin: 0 0 14px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(23, 50, 74, 0.92), rgba(13, 28, 50, 0.92));
  border: 1px solid rgba(88, 173, 255, 0.28);
  color: var(--text);
  box-shadow: 0 0 16px rgba(34, 199, 255, 0.10);
}

.loading-message {
  text-align: center;
  color: var(--muted);
  margin: 10px 0;
  font-size: 0.95em;
}

.spinner {
  width: 24px;
  height: 24px;
  margin: 8px auto;
  border-radius: 50%;
  border: 3px solid rgba(42, 42, 58, 0.9);
  border-top-color: var(--primary-2);
  animation: spin 1.1s linear infinite;
  box-shadow: 0 0 14px rgba(34, 199, 255, 0.18);
}

/* Messages */
.user,
.roxy {
  margin: 12px 0;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  word-wrap: break-word;
  border: 1px solid rgba(87, 204, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.015);
}

.user {
  background: rgba(14, 30, 38, 0.92);
  border-left: 3px solid #57f0b5;
}

.roxy {
  background: rgba(12, 20, 34, 0.94);
  border-left: 3px solid var(--primary);
}

.roxy-output {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 6px 0 0;
  line-height: 1.55;
}

.new-token {
  animation: tokenGlow 0.35s ease;
}

.topics {
  margin: 8px 0 0;
  color: var(--muted);
}

.topic-chip {
  display: inline-block;
  margin: 4px 6px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(22, 32, 45, 0.95);
  color: #d8fff4;
  font-size: 0.85em;
  border: 1px solid rgba(87, 204, 255, 0.18);
}

.citation {
  margin-top: 8px;
  color: #9fb6cf;
}

.citation a {
  color: var(--primary-2);
  text-decoration: none;
}

.citation a:hover {
  text-decoration: underline;
}

.response-time,
.elapsed-timer {
  color: #8a9bb2;
}

#timer {
  margin-top: 12px;
  text-align: center;
  font-size: 0.92rem;
  min-height: 1.2em;
  padding: 12px 14px;
}

/* Controls */
.controls-row,
.slider-wrap,
#feedback-container,
#cancel-area,
.roxy-help-container {
  margin-top: 12px;
  padding: 14px 16px;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.95em;
}

.controls-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.slider-wrap {
  text-align: center;
}

.slider-wrap label {
  display: inline-block;
  margin-bottom: 10px;
  font-size: 0.92rem;
  font-weight: 600;
  color: #cfe9ff;
  letter-spacing: 0.02em;
}

.slider-wrap input[type="range"] {
  width: min(60%, 420px);
  accent-color: var(--primary);
}

.slider-wrap .val {
  color: #8fa8c1;
  font-size: 0.9em;
  margin-top: 8px;
}

#feedback-container {
  text-align: center;
}

#cancel-area {
  text-align: center;
}

/* Input and buttons */
input,
textarea,
select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: #ffffff;
  outline: none;
  transition:
    border-color 0.2s ease,
    box-shadow 0.2s ease,
    transform 0.15s ease,
    background 0.2s ease;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.015),
    0 0 0 rgba(0,0,0,0);
}

input::placeholder,
textarea::placeholder {
  color: #6f8ba6;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--input-border-focus);
  box-shadow:
    0 0 0 1px rgba(98, 220, 255, 0.40),
    0 0 14px rgba(34, 199, 255, 0.20),
    0 0 28px rgba(34, 199, 255, 0.12);
  background: rgba(7, 15, 28, 0.98);
  transform: translateY(-1px);
}

button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 13px 14px;
  transition:
    transform 0.16s ease,
    box-shadow 0.2s ease,
    filter 0.2s ease,
    opacity 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

button:active {
  transform: translateY(0);
}

button,
.input-area button,
#send-btn {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
  color: #03131d;
  box-shadow:
    0 0 10px rgba(34, 199, 255, 0.22),
    0 0 22px rgba(34, 199, 255, 0.16);
  text-shadow: 0 1px 0 rgba(255,255,255,0.18);
}

button.secondary,
.copy-btn,
.copy-summary-btn,
#toggle-help {
  background: linear-gradient(180deg, #122745, #0d1c32);
  color: #dff6ff;
  border: 1px solid rgba(88, 173, 255, 0.22);
  box-shadow:
    inset 0 0 10px rgba(80, 170, 255, 0.03),
    0 0 10px rgba(34, 199, 255, 0.05);
}

#cancel-btn {
  background: linear-gradient(180deg, #ff8d8d, #b84444) !important;
  color: #250808 !important;
  box-shadow:
    0 0 10px rgba(255, 120, 120, 0.18),
    0 0 22px rgba(255, 120, 120, 0.12) !important;
}

.input-area {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  padding: 14px;
}

.input-area input[type="text"] {
  flex: 1;
  margin: 0;
}

.input-area button {
  width: auto;
  min-width: 110px;
  white-space: nowrap;
}

/* Help */
.roxy-help-container {
  text-align: center;
}

#help-content {
  margin-top: 12px !important;
  padding: 14px !important;
  font-size: 0.95em;
  color: #d9e8f6 !important;
  text-align: left !important;
  background: rgba(8, 16, 28, 0.68) !important;
  border-radius: 12px !important;
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.4s ease-out;
  border: 1px dashed rgba(82, 157, 214, 0.28);
}

#help-content strong {
  color: var(--text);
}

#help-content ul {
  margin-top: 8px;
}

#help-content li {
  margin-bottom: 6px;
}

.small {
  margin-top: 16px;
  margin-bottom: 2px;
  color: #82a5c1;
  font-size: 0.88rem;
  line-height: 1.4;
  padding: 10px 12px;
  border: 1px dashed rgba(82, 157, 214, 0.28);
  border-radius: 12px;
  background: rgba(8, 16, 28, 0.65);
}

.msg {
  margin-top: 16px;
  min-height: 24px;
  font-size: 0.94rem;
  color: var(--danger);
  text-shadow: 0 0 8px rgba(255, 120, 120, 0.10);
}

.ok {
  color: var(--success);
  text-shadow: 0 0 10px rgba(120, 255, 210, 0.12);
}

/* Search results */
.search-results {
  display: grid;
  gap: 10px;
  margin-top: 8px;
}

.result-card {
  border: 1px solid rgba(87, 204, 255, 0.16);
  background: rgba(10, 20, 34, 0.86);
  border-radius: 14px;
  padding: 12px;
}

.result-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-index {
  font-weight: 600;
  color: #a9c6df;
}

.result-link {
  color: #dffcff;
  text-decoration: none;
  font-weight: 600;
}

.result-link:hover {
  text-decoration: underline;
}

.result-summary {
  margin: 8px 0 0;
}

.result-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.result-actions a {
  color: var(--primary-2);
}

/* Toasts */
.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: rgba(10, 18, 32, 0.96);
  color: #dfe;
  border: 1px solid rgba(87, 204, 255, 0.18);
  border-radius: 12px;
  padding: 10px 14px;
  z-index: 9999;
  transition: transform 0.25s ease, opacity 0.25s ease;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-success {
  border-color: rgba(80, 240, 180, 0.30);
}

.toast-warning {
  border-color: rgba(255, 210, 100, 0.30);
}

.toast-error {
  border-color: rgba(255, 120, 120, 0.30);
}

/* Footer */
footer {
  width: min(1100px, 100%);
  margin: 18px auto 0;
  text-align: center;
  color: #6f89a8;
  font-size: 0.8rem;
  line-height: 1.45;
  position: relative;
  z-index: 1;
}

.footer-note {
  margin-top: 18px;
  color: #6f89a8;
  font-size: 0.8rem;
  text-align: center;
  line-height: 1.45;
}

/* Links */
a {
  color: var(--primary-2);
}

/* Responsive */
@media (max-width: 900px) {
  body {
    padding: 16px;
  }

  header {
    padding: 18px 18px 16px;
  }

  .slider-wrap input[type="range"] {
    width: 85%;
  }
}

@media (max-width: 680px) {
  header h1 {
    font-size: 1.7rem;
  }

  .input-area {
    flex-direction: column;
  }

  .input-area button {
    width: 100%;
    min-width: 0;
  }

  .controls-row {
    flex-direction: column;
    gap: 10px;
  }

  .result-actions {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 520px) {
  body {
    padding: 12px;
  }

  header,
  .chat-box,
  .controls-row,
  .slider-wrap,
  #feedback-container,
  #cancel-area,
  #timer,
  .input-area,
  .roxy-help-container {
    border-radius: 18px;
  }

  header::before,
  header::after {
    border-radius: 18px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .chat-box {
    min-height: 50vh;
    padding: 14px;
  }

  .controls-row,
  .slider-wrap,
  #feedback-container,
  #cancel-area,
  #timer,
  .input-area,
  .roxy-help-container {
    padding: 12px;
  }
}