* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #151419;
  --card-bg: rgba(27, 27, 29, 0.8);
  --card-bg-50: rgba(27, 27, 29, 0.5);
  --card-solid: #1B1B1D;
  --accent: #F56F10;
  --accent-border: rgba(245, 111, 16, 0.2);
  --accent-border-light: rgba(245, 111, 16, 0.15);
  --accent-glow: rgba(245, 111, 16, 0.3);
  --accent-glow-shadow: rgba(245, 111, 16, 0.6);
  --text-primary: #FFFFFF;
  --text-secondary: #E5E5EA;
  --text-placeholder: #878787;
  --user-border: rgba(229, 229, 234, 0.2);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

.hidden { display: none !important; }

/* --- Orange glow behind avatar --- */
#avatar-glow {
  position: fixed;
  top: 27dvh;
  left: 50%;
  transform: translateX(-50%);
  width: 194px;
  height: 221px;
  border-radius: 50%;
  background: var(--accent);
  filter: blur(75px);
  pointer-events: none;
  z-index: 0;
}

/* --- 3D avatar canvas --- */
#avatar-canvas {
  display: block;
  position: fixed;
  top: 16.4dvh;
  left: 0;
  right: 0;
  z-index: 1;
}

/* --- Gradient fade at bottom of avatar area --- */
#avatar-fade {
  position: fixed;
  top: 50dvh;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 0%, var(--bg) 55%);
  pointer-events: none;
  z-index: 2;
}

/* --- Top bar --- */
#top-bar {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 5.1vw;
  right: 5.1vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10;
}

#settings-btn {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#settings-btn img {
  display: block;
}

/* --- Custom prism dropdown --- */
#prism-dropdown {
  position: relative;
}

#prism-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 160px;
  height: 48px;
  padding: 0 16px;
  border-radius: 16px;
  background: #1A1A1C;
  border: 1px solid var(--accent-border-light);
  color: var(--text-primary);
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
}

#prism-dropdown-trigger:active {
  background: rgba(245, 111, 16, 0.1);
}

#prism-dropdown-trigger svg {
  margin-left: auto;
  opacity: 0.5;
  flex-shrink: 0;
}

#prism-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 160px;
  border-radius: 16px;
  background: #1A1A1C;
  border: 1px solid var(--accent-border);
  padding: 8px 0;
  z-index: 20;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s;
  pointer-events: none;
}

#prism-dropdown-menu.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.prism-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 16px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}

.prism-option:active {
  background: rgba(245, 111, 16, 0.1);
}

.prism-option .checkmark {
  width: 24px;
  height: 24px;
  opacity: 0;
  color: var(--accent);
  flex-shrink: 0;
}

.prism-option.selected .checkmark {
  opacity: 1;
}

.prism-option-delete {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: none;
  background: none;
  color: var(--text-placeholder);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
}

.prism-option-delete:active {
  opacity: 1;
  color: #ff4444;
}

/* --- Bottom UI overlay --- */
#ui-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 12px);
  pointer-events: none;
  z-index: 5;
}

/* --- Messages container --- */
#messages-container {
  width: 100%;
  max-width: 360px;
  max-height: 25dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  pointer-events: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#messages-container::-webkit-scrollbar {
  display: none;
}

#messages-container.overflowing {
  mask-image: linear-gradient(to bottom, transparent 0%, black 10%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 10%);
}

/* --- Message bubbles --- */
.message-bubble {
  width: 100%;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: opacity 0.3s;
}

.message-bubble.user {
  background: var(--card-bg-50);
  border: 1px solid var(--user-border);
}

.message-bubble.ai {
  background: var(--card-bg-50);
  border: 1px solid var(--accent-border);
}

.message-bubble.user.faded {
  opacity: 0.3;
}

/* --- Debug bar (dev only) --- */
.debug-bar {
  width: 100%;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11px;
  font-family: monospace;
  background: rgba(50, 40, 80, 0.5);
  border: 1px solid rgba(140, 100, 255, 0.3);
  color: rgba(180, 160, 255, 0.9);
}

.debug-bar-summary {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.debug-bar-details {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(140, 100, 255, 0.2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  color: rgba(160, 140, 230, 0.8);
}

/* --- Input bar --- */
#input-bar {
  width: 100%;
  max-width: 360px;
  display: flex;
  gap: 4px;
  align-items: flex-end;
  pointer-events: auto;
  margin-bottom: 8px;
}

#input-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#input-buttons-bottom {
  display: flex;
  gap: 4px;
}

#mute-button {
  width: 35px;
  height: 35px;
  border-radius: 10px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

#mute-button img {
  width: 35px;
  height: 35px;
  display: block;
  border-radius: 10px;
  pointer-events: none;
  -webkit-touch-callout: none;
  user-select: none;
}

#chat-input {
  flex: 1;
  height: 45px;
  border-radius: 14px;
  background: var(--card-bg);
  border: 1px solid var(--accent-border);
  padding: 0 12px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

#chat-input::placeholder {
  color: var(--text-placeholder);
}

#chat-input:focus {
  border-color: rgba(245, 111, 16, 0.4);
}

#mic-button,
#chat-send {
  width: 45px;
  height: 45px;
  border-radius: 14px;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

#mic-button img,
#chat-send img {
  display: block;
  border-radius: 14px;
  pointer-events: none;
  -webkit-touch-callout: none;
  user-select: none;
}

#mute-button.muted img {
  opacity: 0.5;
}

/* --- Mic button states --- */
#mic-button.active {
  filter: drop-shadow(0 0 12px var(--accent-glow-shadow));
}

#mic-button.active img {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow-shadow);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 12px var(--accent-glow-shadow); }
  50% { box-shadow: 0 0 24px var(--accent-glow-shadow), 0 0 48px rgba(245, 111, 16, 0.2); }
}

#mic-button.speaking img {
  background: rgba(245, 111, 16, 0.1);
  border: 1px solid rgba(245, 111, 16, 0.3);
}

/* --- Status text --- */
#status {
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-placeholder);
  text-align: center;
  pointer-events: none;
}

/* --- Prism mode: "Add file" button --- */
#add-file-btn {
  display: none;
  height: 48px;
  padding: 0 24px;
  background: var(--accent);
  border: 1px solid rgba(255, 203, 166, 0.6);
  border-radius: 14px;
  font-family: 'Play', var(--font);
  font-weight: 700;
  font-size: 16px;
  color: #FFFFFF;
  cursor: pointer;
  transition: opacity 0.2s;
}

#add-file-btn:active {
  opacity: 0.8;
}

/* --- Prism view --- */
#prism-view {
  position: fixed;
  inset: 0;
  z-index: 1;
}

#network-canvas {
  width: 100%;
  height: 100%;
}

#floating-cards {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.floating-card {
  position: absolute;
  top: 0;
  left: 0;
  background: #1A1A1C;
  border: 1px solid rgba(245, 111, 16, 0.3);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  will-change: transform, opacity;
}

/* --- Prism file list (bottom) --- */
#prism-file-list {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  max-height: 35dvh;
  overflow-y: auto;
  padding: 0 16px;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 20%);
  padding-top: 12px;
  scrollbar-width: none;
}

#prism-file-list::-webkit-scrollbar {
  display: none;
}

#prism-files {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
  margin: 0 auto;
}

.prism-file-card {
  background: #1A1A1C;
  border: 1px solid rgba(245, 111, 16, 0.3);
  border-radius: 14px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.2s;
}

.prism-file-card:active {
  background: rgba(245, 111, 16, 0.1);
}

.prism-file-card-info {
  flex: 1;
  min-width: 0;
}

.prism-file-card-label {
  font-size: 11px;
  color: var(--text-placeholder);
  margin-bottom: 2px;
}

.prism-file-card-name {
  font-size: 15px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prism-file-card-chevron {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  color: var(--text-placeholder);
  margin-left: 8px;
}

/* --- Prism mode toggle --- */
body.prism-active #avatar-canvas,
body.prism-active #avatar-fade {
  opacity: 0;
  pointer-events: none;
}

body.prism-active #avatar-glow {
  top: 31dvh;
  width: 280px;
  height: 280px;
  filter: blur(96px);
}

body.prism-active #ui-overlay {
  opacity: 0;
  visibility: hidden;
  pointer-events: none !important;
}

body.prism-active #prism-dropdown {
  display: none;
}

body.prism-active #add-file-btn {
  display: block;
}

body.prism-active #prism-view {
  display: block !important;
}

/* --- File detail backdrop (blur) --- */
#file-detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 14;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#file-detail-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* --- File detail view (bottom panel) --- */
#file-detail {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 15;
  max-height: 70dvh;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--accent-border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  padding-top: 8px;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  transform: translateY(100%);
  pointer-events: none;
  transition: transform 0.35s ease;
}

#file-detail.visible {
  transform: translateY(0);
  pointer-events: auto;
}

.panel-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  margin: 8px auto 12px;
  flex-shrink: 0;
}

#file-detail-close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-placeholder);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  transition: background 0.2s;
}

#file-detail-close:active {
  background: rgba(255, 255, 255, 0.15);
}

#file-detail-header {
  max-width: 360px;
  margin: 0 auto 16px;
  width: 100%;
  flex-shrink: 0;
}

#file-detail-title {
  font-family: 'Play', var(--font);
  font-weight: 700;
  font-size: 22px;
  color: var(--text-primary);
  margin-bottom: 6px;
  padding-right: 44px;
}

#file-detail-desc {
  font-size: 14px;
  color: var(--text-placeholder);
  line-height: 1.4;
}

#file-detail-content {
  max-width: 360px;
  margin: 0 auto;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#file-detail-entry {
  background: #1A1A1C;
  border: 1px solid rgba(245, 111, 16, 0.3);
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#file-detail-entry-name {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#file-detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#file-detail-download,
#file-detail-delete {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--accent-border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

#file-detail-download {
  color: var(--accent);
}

#file-detail-download:active {
  background: rgba(245, 111, 16, 0.15);
}

#file-detail-delete {
  color: #ff4444;
  border-color: rgba(255, 68, 68, 0.2);
}

#file-detail-delete:active {
  background: rgba(255, 68, 68, 0.15);
}

#file-detail-chunks {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: none;
}

#file-detail-chunks::-webkit-scrollbar {
  display: none;
}

.chunk-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

body.file-detail-active #prism-file-list {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* --- Auth panel transition targets --- */
#avatar-glow {
  transition: top 0.5s ease, width 0.5s ease, height 0.5s ease;
}
#avatar-canvas {
  transition: top 0.5s ease, transform 0.5s ease;
}
#avatar-fade {
  transition: opacity 0.5s ease;
}
#ui-overlay {
  transition: opacity 0.5s ease;
}
#top-bar {
  transition: opacity 0.5s ease;
}

/* --- Auth active: avatar shrinks and rises --- */
body.auth-active #avatar-glow {
  top: 18dvh;
  width: 156px;
  height: 156px;
}

body.auth-active #avatar-canvas {
  top: 6.8dvh;
  transform: scale(0.66);
  transform-origin: top center;
}

body.auth-active #avatar-fade {
  opacity: 0;
}

body.auth-active #ui-overlay {
  opacity: 0;
  pointer-events: none !important;
}

body.auth-active #top-bar {
  opacity: 0;
  pointer-events: none;
}

/* --- Auth panel --- */
#auth-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

#auth-panel.visible {
  pointer-events: auto;
}

#auth-card {
  width: 344px;
  max-width: calc(100% - 48px);
  background: var(--card-solid);
  border: 1px solid var(--accent);
  border-radius: 32px;
  padding: 20px;
  margin-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.4s ease, opacity 0.3s ease;
}

#auth-panel.visible #auth-card {
  transform: translateY(0);
  opacity: 1;
}

#auth-title {
  font-family: 'Play', var(--font);
  font-weight: 700;
  font-size: 28px;
  color: #FBFBFB;
  margin-top: 4px;
}

#auth-desc {
  font-size: 14px;
  line-height: 1.3;
  color: var(--text-placeholder);
  text-align: center;
  max-width: 280px;
  margin-bottom: 4px;
}

#auth-error {
  width: 304px;
  max-width: 100%;
  font-size: 14px;
  color: #ff5555;
  text-align: center;
  margin: 4px 0;
}

.auth-input {
  width: 304px;
  max-width: 100%;
  height: 50px;
  background: #262626;
  border-radius: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 13px;
}

.auth-input img {
  flex-shrink: 0;
  opacity: 0.7;
}

.auth-input input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
}

.auth-input input::placeholder {
  color: var(--text-placeholder);
}

#auth-or {
  font-size: 14px;
  color: var(--text-placeholder);
  text-align: center;
  margin: 4px 0;
}

#auth-google {
  width: 304px;
  max-width: 100%;
  height: 50px;
  background: #FBFBFB;
  border: none;
  border-radius: 50px;
  display: flex;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
  padding: 0;
}

#auth-google img {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

#auth-google span {
  flex: 1;
  font-family: var(--font);
  font-weight: 510;
  font-size: 16px;
  color: #1B1B1D;
  text-align: center;
  padding-right: 50px;
}

#auth-switch {
  font-size: 16px;
  color: var(--text-placeholder);
  text-align: center;
  margin: 8px 0;
}

#auth-switch-link {
  color: var(--text-placeholder);
  text-decoration: underline;
  cursor: pointer;
}

#auth-submit {
  width: 304px;
  max-width: 100%;
  height: 50px;
  background: var(--accent);
  border: none;
  border-radius: 16px;
  font-family: 'Play', var(--font);
  font-weight: 700;
  font-size: 16px;
  color: #FFFFFF;
  cursor: pointer;
  transition: opacity 0.2s;
}

#auth-submit:active {
  opacity: 0.8;
}
