/* ── HAL Theme Variables ── */
:root {
  --hal-bg: #000000;
  --hal-text: #ffffff;
  --hal-muted: #666666;
  --hal-accent: #a855f7;
  --hal-accent-glow: rgba(168, 85, 247, 0.3);
  --hal-accent-dim: rgba(168, 85, 247, 0.12);
  --hal-surface: rgba(255, 255, 255, 0.05);
  --hal-border: rgba(255, 255, 255, 0.1);
  --hal-font: Arial, Helvetica, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--hal-bg);
  color: var(--hal-text);
  font-family: var(--hal-font);
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App Container ── */
#hal-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* ── Header ── */
.hal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  flex-shrink: 0;
  z-index: 10;
}

.hal-classic-link {
  color: var(--hal-muted);
  text-decoration: none;
  font-size: 11px;
  letter-spacing: normal;
  transition: color 0.3s;
  display: flex;
  align-items: center;
  gap: 5px;
}

.hal-classic-link:hover {
  color: var(--hal-text);
}

.hal-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hal-tagline {
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  font-weight: 500;
  min-height: 16px;
  min-width: 0;
  flex: 1;
  transition: color 0.8s ease, opacity 0.5s ease;
  opacity: 0.7;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hal-ambient-btn {
  background: none;
  border: 1px solid var(--hal-border);
  color: var(--hal-muted);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
}

.hal-ambient-btn:hover {
  color: var(--hal-text);
  border-color: var(--hal-text);
}

.hal-ambient-btn.active {
  color: var(--hal-accent);
  border-color: var(--hal-accent);
  animation: halPulseGlow 2s ease-in-out infinite;
}

@keyframes halPulseGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(168, 85, 247, 0); }
  50% { box-shadow: 0 0 8px rgba(168, 85, 247, 0.3); }
}

.hal-lang-switcher {
  display: flex;
  gap: 4px;
}

.hal-lang-btn {
  background: none;
  border: 1px solid var(--hal-border);
  color: var(--hal-muted);
  font-family: var(--hal-font);
  font-size: 11px;
  letter-spacing: normal;
  padding: 4px 10px;
  cursor: pointer;
  transition: all 0.3s;
  border-radius: 2px;
}

.hal-lang-btn:hover {
  color: var(--hal-text);
  border-color: var(--hal-text);
}

.hal-lang-btn.active {
  color: var(--hal-accent);
  border-color: var(--hal-accent);
}

/* ── Main Content ── */
.hal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  gap: 16px;
}

/* ── Boot Text ── */
.hal-boot-text {
  font-size: 11px;
  letter-spacing: normal;
  color: var(--hal-muted);
  text-align: center;
  min-height: 20px;
  opacity: 0;
  transition: opacity 0.6s;
}

.hal-boot-text.visible {
  opacity: 1;
}

/* ── Transcript ── */
.hal-transcript {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--hal-border) transparent;
  padding: 0 4px;
}

.hal-transcript:empty {
  display: none;
}

.hal-transcript::-webkit-scrollbar {
  width: 4px;
}

.hal-transcript::-webkit-scrollbar-track {
  background: transparent;
}

.hal-transcript::-webkit-scrollbar-thumb {
  background: var(--hal-border);
  border-radius: 2px;
}

.hal-msg {
  max-width: 100%;
  line-height: 1.5;
  animation: halFadeIn 0.4s ease;
}

.hal-msg.user {
  color: var(--hal-muted);
  font-size: 11px;
  letter-spacing: normal;
  text-align: right;
  padding-right: 4px;
}

.hal-msg.assistant {
  color: var(--hal-text);
  font-size: 18px;
  font-weight: 300;
  letter-spacing: normal;
  line-height: 1.6;
}

.hal-msg.assistant .hal-cursor {
  display: inline-block;
  width: 2px;
  height: 12px;
  background: var(--hal-accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: halBlink 0.8s step-end infinite;
}

.hal-msg.ghost {
  color: var(--hal-accent-glow);
  font-size: 12px;
  text-align: right;
  font-style: italic;
}

/* ── Spinner ── */
.hal-spinner {
  text-align: center;
  color: var(--hal-accent);
  font-size: 18px;
  padding: 12px 0;
  animation: halFadeIn 0.3s ease;
}

@keyframes halBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@keyframes halFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Content Display (project images) ── */
.hal-content {
  width: 100%;
  max-width: 800px;
  overflow: hidden;
}

.hal-content:empty {
  display: none;
}

.hal-content-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding: 8px 0;
}

.hal-content-strip::-webkit-scrollbar {
  display: none;
}

.hal-content-card {
  flex: 0 0 auto;
  width: 280px;
  scroll-snap-align: start;
  border-radius: 4px;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95);
  animation: halCardIn 0.5s ease forwards;
  position: relative;
}

.hal-content-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  filter: grayscale(0.2);
  transition: filter 0.3s;
}

.hal-content-card:hover img {
  filter: grayscale(0);
}

.hal-content-card .hal-card-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 24px 12px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  font-size: 10px;
  letter-spacing: normal;
  color: var(--hal-muted);
}

.hal-content-card .hal-card-title {
  color: var(--hal-text);
  font-size: 11px;
  margin-bottom: 2px;
}

@keyframes halCardIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.hal-content-fade-out {
  animation: halCardOut 0.4s ease forwards;
}

@keyframes halCardOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.95); }
}

/* ── Visualizer ── */
.hal-visualizer-wrap {
  width: 100vw;
  margin-left: calc(-50vw + 50%);
  height: 200px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: opacity 0.5s ease;
}

#halCanvas {
  position: absolute;
  left: 0;
  width: 100%;
  height: 80vh;
  display: block;
  pointer-events: auto;
}

/* ── Status ── */
.hal-status {
  font-size: 11px;
  letter-spacing: normal;
  color: var(--hal-muted);
  text-align: center;
  min-height: 16px;
  transition: opacity 0.3s;
}

.hal-status.listening {
  color: var(--hal-accent);
}

.hal-stop-btn {
  background: none;
  border: 1px solid var(--hal-border);
  color: var(--hal-muted);
  font-family: var(--hal-font);
  font-size: 11px;
  letter-spacing: normal;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.3s;
}

.hal-stop-btn:hover {
  color: var(--hal-text);
  border-color: var(--hal-accent);
}

/* ── Input Area ── */
.hal-input-area {
  flex-shrink: 0;
  padding: 20px 24px 28px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ── Prompt Pills ── */
.hal-prompts {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 640px;
  position: relative;
  min-height: 32px;
}

.hal-prompt-pill {
  background: var(--hal-surface);
  border: 1px solid var(--hal-border);
  color: var(--hal-muted);
  font-family: var(--hal-font);
  font-size: 12px;
  letter-spacing: normal;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.3s, color 0.3s, border-color 0.3s, opacity 0.5s ease;
}

.hal-prompt-pill:hover {
  color: var(--hal-text);
  border-color: var(--hal-accent);
  background: var(--hal-accent-dim);
}

/* ── Input Row ── */
.hal-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 720px;
}

.hal-text-input {
  flex: 1;
  background: var(--hal-surface);
  border: 1px solid var(--hal-border);
  color: var(--hal-text);
  font-family: var(--hal-font);
  font-size: 14px;
  letter-spacing: normal;
  padding: 18px 22px;
  border-radius: 14px;
  outline: none;
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.06), 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: border-color 0.3s, box-shadow 0.3s;
}

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

.hal-text-input:focus {
  border-color: var(--hal-accent);
  box-shadow: 0 0 0 1px var(--hal-accent), 0 0 24px rgba(168, 85, 247, 0.15), 0 8px 28px rgba(0, 0, 0, 0.3);
}

.hal-mic-btn,
.hal-send-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 1px solid var(--hal-border);
  background: var(--hal-surface);
  color: var(--hal-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  flex-shrink: 0;
}

.hal-mic-btn:hover,
.hal-send-btn:hover {
  color: var(--hal-text);
  border-color: var(--hal-text);
}

.hal-mic-btn.active {
  color: var(--hal-accent);
  border-color: var(--hal-accent);
  background: var(--hal-accent-dim);
  box-shadow: 0 0 20px var(--hal-accent-glow);
}

.hal-send-btn {
  background: var(--hal-accent-dim);
  border-color: var(--hal-accent);
  color: var(--hal-accent);
}

.hal-send-btn:hover {
  background: var(--hal-accent);
  color: var(--hal-bg);
}

/* ── Lightbox ── */
.hal-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.hal-lightbox.active {
  opacity: 1;
  pointer-events: auto;
}

.hal-lightbox-img-wrap {
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hal-lightbox-img-wrap img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 4px;
  opacity: 0;
  transform: scale(0.96);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.hal-lightbox.active .hal-lightbox-img-wrap img {
  opacity: 1;
  transform: scale(1);
}

.hal-lightbox-close,
.hal-lightbox-prev,
.hal-lightbox-next {
  position: absolute;
  background: none;
  border: 1px solid var(--hal-border);
  color: var(--hal-muted);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 101;
}

.hal-lightbox-close:hover,
.hal-lightbox-prev:hover,
.hal-lightbox-next:hover {
  color: var(--hal-text);
  border-color: var(--hal-accent);
}

.hal-lightbox-close {
  top: 20px;
  right: 20px;
}

.hal-lightbox-prev {
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.hal-lightbox-next {
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.hal-lightbox-counter {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: normal;
  color: var(--hal-muted);
}

/* ── Responding Layout ── */
#hal-app.hal-responding .hal-main {
  justify-content: flex-start;
  padding-top: 0;
}

#hal-app.hal-responding .hal-visualizer-wrap {
  order: -1;
  height: 50px;
  min-height: 50px;
  width: 120px;
  margin-left: auto;
  margin-right: auto;
  flex-shrink: 0;
}

#hal-app.hal-responding #halCanvas {
  height: 50px;
  width: 120px;
  pointer-events: none;
}

#hal-app.hal-responding .hal-transcript {
  flex: 1;
  min-height: 0;
  padding-top: 8px;
}

#hal-app.hal-responding .hal-boot-text {
  display: none;
}

/* ── Inline Project Cards (inside transcript) ── */
.hal-inline-content {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px 0;
}

.hal-inline-content::-webkit-scrollbar {
  display: none;
}

.hal-inline-card {
  flex: 0 0 auto;
  width: 160px;
  border-radius: 4px;
  overflow: hidden;
  opacity: 0;
  transform: scale(0.95);
  animation: halCardIn 0.5s ease forwards;
  position: relative;
  cursor: pointer;
}

.hal-inline-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  filter: grayscale(0.2);
  transition: filter 0.3s;
}

.hal-inline-card:hover img {
  filter: grayscale(0);
}

.hal-inline-card .hal-card-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 8px 6px;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  font-size: 9px;
  color: var(--hal-muted);
}

.hal-inline-card .hal-card-title {
  color: var(--hal-text);
  font-size: 10px;
  margin-bottom: 1px;
}

/* ── Grid View (inline in transcript) ── */
.hal-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 540px;
  animation: halFadeIn 0.4s ease;
}

.hal-grid.hal-grid-1 { grid-template-columns: 1fr; max-width: 200px; }
.hal-grid.hal-grid-2 { grid-template-columns: repeat(2, 1fr); }

.hal-grid-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  animation: halGridItemIn 0.4s ease forwards;
  background: var(--hal-surface);
}

.hal-grid-item img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  display: block;
  filter: grayscale(0.3) brightness(0.85);
  transition: filter 0.3s, transform 0.3s;
}

.hal-grid-item:hover img {
  filter: grayscale(0) brightness(1);
  transform: scale(1.03);
}

.hal-grid-item .hal-grid-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 10px 8px;
  background: linear-gradient(to top, rgba(0,0,0,0.85), transparent);
}

.hal-grid-item .hal-grid-title {
  color: var(--hal-text);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.3;
}

.hal-grid-item .hal-grid-sub {
  color: var(--hal-muted);
  font-size: 9px;
  margin-top: 2px;
}

.hal-grid-item .hal-grid-index {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.6);
  color: var(--hal-muted);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 3px;
}

@keyframes halGridItemIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  .hal-msg,
  .hal-content-card {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

/* ── Mobile ── */
@media (max-width: 700px) {
  .hal-header {
    padding: 12px 16px;
    flex-wrap: wrap;
  }

  .hal-header .hal-tagline {
    order: 3;
    flex: 0 0 100%;
    padding: 6px 0 0;
    font-size: 9px;
  }

  .hal-main {
    padding: 0 16px;
    gap: 12px;
  }

  .hal-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .hal-grid.hal-grid-1 { grid-template-columns: 1fr; }

  .hal-visualizer-wrap {
    height: 120px;
  }

  .hal-inline-card {
    width: 120px;
  }

  .hal-input-area {
    padding: 12px 0 calc(20px + env(safe-area-inset-bottom, 0px));
    gap: 12px;
  }

  /* Horizontal swipeable pill strip on mobile */
  .hal-prompts {
    gap: 8px;
    flex-wrap: nowrap;
    justify-content: flex-start;
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    padding: 4px 16px;
    margin: 0 -16px;
    min-height: 0;
    scrollbar-width: none; /* Firefox */
  }

  .hal-prompts::-webkit-scrollbar {
    display: none; /* WebKit */
  }

  .hal-prompt-pill {
    font-size: 13px;
    padding: 8px 14px;
    white-space: nowrap;
    text-align: center;
    flex-shrink: 0;
    scroll-snap-align: start;
  }

  .hal-prompt-pill.hal-pill-hidden {
    display: none;
  }

  .hal-input-row {
    padding: 0 16px;
  }

  .hal-text-input {
    font-size: 16px; /* prevent iOS zoom */
    padding: 14px 18px;
    border-radius: 12px;
  }

  .hal-mic-btn,
  .hal-send-btn {
    width: 48px;
    height: 48px;
    font-size: 17px;
  }

  .hal-content-card {
    width: 220px;
  }

  .hal-msg.assistant {
    font-size: 16px;
  }

  #hal-app.hal-responding .hal-visualizer-wrap {
    height: 40px;
    min-height: 40px;
    width: 100px;
  }

  #hal-app.hal-responding #halCanvas {
    height: 40px;
    width: 100px;
  }
}
