:root {
  --primary-color: #0d0d0d;
  --secondary-color: #00ffff; /* Cyan */
  --accent-color: #ff00ff; /* Magenta */
  --line-color: rgba(0, 255, 255, 0.2);
  --font-family: "IBM Plex Mono", monospace;
  --button-bg: #00ffff;
  --button-text: #0d0d0d;
  --ai-message-bg: #1a1a1a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
}

body {
  background-color: var(--primary-color);
  color: var(--secondary-color);
  font-family: var(--font-family);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  text-shadow: 0 0 2px rgba(0, 255, 255, 0.4);
  animation: chromatic-aberration 5s infinite linear;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  position: relative;
}

#app::after {
  content: " ";
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.3),
    rgba(0, 0, 0, 0.3) 1px,
    transparent 1px,
    transparent 2px
  );
  z-index: 100;
  pointer-events: none;
  opacity: 0.5;
}

#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  position: relative;
  width: 100%;
  padding: 1.5rem 2.5rem;
}

#content.hidden {
  display: none;
}

#home-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 100%;
  width: 100%;
  background-color: var(--primary-color);
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  animation: fadeIn 0.5s ease-in-out;
  padding: 1rem;
}

#home-form {
  width: 100%;
  max-width: 600px;
  position: relative;
}

#home-message-input {
  width: 100%;
  background-color: transparent;
  border: 1px solid var(--line-color);
  color: var(--secondary-color);
  font-size: 1.1rem;
  padding: 1rem 3.5rem 1rem 1rem;
  border-radius: 0;
  font-family: var(--font-family);
  transition: all 0.2s ease;
  text-shadow: inherit;
}

#home-message-input::placeholder {
  color: rgba(0, 255, 255, 0.5);
  text-shadow: none;
}

#home-message-input:focus {
  outline: none;
  border-color: var(--secondary-color);
  box-shadow: 0 0 8px var(--secondary-color);
}

#home-form .send-button {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  height: calc(100% - 1rem);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.home-controls {
  width: 100%;
  max-width: 600px;
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
  font-size: 0.8rem;
}

#home-history-button {
  font-style: italic;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 800px;
  animation: fadeIn 0.5s ease-in-out;
}

.messages-container {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line-color) transparent;
}

.messages-container::-webkit-scrollbar {
  width: 6px;
}
.messages-container::-webkit-scrollbar-track {
  background: transparent;
}
.messages-container::-webkit-scrollbar-thumb {
  background-color: var(--line-color);
  border-radius: 0;
}

.message {
  padding: 0.75rem 1.25rem;
  border-radius: 0;
  max-width: 85%;
  line-height: 1.5;
  word-wrap: break-word;
  animation: messageFadeIn 0.3s ease-out;
  border: 1px solid transparent;
}

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

.user-message {
  background-color: transparent;
  color: var(--secondary-color);
  align-self: flex-end;
  border: 1px solid var(--line-color);
}

.ai-message {
  background-color: var(--ai-message-bg);
  color: var(--secondary-color);
  align-self: flex-start;
  border: 1px solid var(--line-color);
  font-size: 0.9rem;
  max-width: 90%;
}

.ai-message.processing {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  background: transparent;
  border-color: transparent;
}

.ai-message .spinner {
  margin: 0;
}

.chat-form {
  display: flex;
  flex-grow: 1;
  gap: 0.5rem;
  align-items: center;
}

#message-input {
  flex-grow: 1;
  background-color: transparent;
  border: none;
  color: var(--secondary-color);
  font-size: 1rem;
  padding: 0.5rem;
  font-family: var(--font-family);
  text-shadow: inherit;
}

#message-input:focus {
  outline: none;
}

#message-input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.send-button {
  background: none;
  border: none;
  color: var(--secondary-color);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition:
    opacity 0.2s ease,
    text-shadow 0.2s ease;
}

.send-button:hover {
  opacity: 1;
  text-shadow: 0 0 5px var(--secondary-color);
}

.send-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.system-message {
  align-self: center;
  text-align: center;
  font-size: 0.8rem;
  color: rgba(0, 255, 255, 0.5);
  width: 100%;
  padding: 0.5rem 0;
  font-style: italic;
  border: none;
}

.chat-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
  font-size: 0.8rem;
}

.control-button {
  background: none;
  border: none;
  color: var(--secondary-color);
  font-family: var(--font-family);
  cursor: pointer;
  opacity: 0.7;
  transition: all 0.2s ease;
  padding: 0;
  font-size: inherit;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.control-button:hover {
  opacity: 1;
  text-shadow: 0 0 5px var(--secondary-color);
}

.control-button#cancel-button {
  font-style: italic;
  font-size: 0.8rem;
}

.control-button#cancel-button:hover {
  color: var(--accent-color);
  text-shadow: 0 0 5px var(--accent-color);
}

.chat-controls .separator {
  opacity: 0.5;
  color: var(--secondary-color);
  user-select: none;
}

.control-button#clear-history-button:hover {
  color: var(--accent-color);
  text-shadow: 0 0 5px var(--accent-color);
}

.chat-input-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line-color);
  font-size: 0.8rem;
}

.chat-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding-bottom: 1rem;
}

.chat-header .scythe-header {
  margin-bottom: 0;
  text-align: left;
}

.scythe-header {
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  margin-bottom: 1rem;
  color: var(--secondary-color);
  letter-spacing: 2px;
}

.glitch {
  position: relative;
  animation: glitch 5s infinite steps(8);
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--primary-color);
  overflow: hidden;
  clip: rect(0, 900px, 0, 0);
}

.glitch::before {
  left: -1px;
  text-shadow: 1px 0 var(--accent-color);
  animation: glitch 3s infinite linear alternate-reverse;
}

.glitch::after {
  left: 1px;
  text-shadow: -1px 0 var(--secondary-color);
  animation: glitch 2s infinite linear alternate-reverse;
}

@keyframes glitch {
  0% {
    clip: rect(42px, 9999px, 44px, 0);
  }
  5% {
    clip: rect(12px, 9999px, 59px, 0);
  }
  10% {
    clip: rect(45px, 9999px, 23px, 0);
  }
  15% {
    clip: rect(62px, 9999px, 72px, 0);
  }
  20% {
    clip: rect(89px, 9999px, 48px, 0);
  }
  25% {
    clip: rect(41px, 9999px, 63px, 0);
  }
  30% {
    clip: rect(2px, 9999px, 83px, 0);
  }
  35% {
    clip: rect(13px, 9999px, 32px, 0);
  }
  40% {
    clip: rect(56px, 9999px, 74px, 0);
  }
  45% {
    clip: rect(23px, 9999px, 88px, 0);
  }
  50% {
    clip: rect(77px, 9999px, 22px, 0);
  }
  55% {
    clip: rect(42px, 9999px, 99px, 0);
  }
  60% {
    clip: rect(11px, 9999px, 33px, 0);
  }
  65% {
    clip: rect(88px, 9999px, 45px, 0);
  }
  70% {
    clip: rect(23px, 9999px, 55px, 0);
  }
  75% {
    clip: rect(65px, 9999px, 1px, 0);
  }
  80% {
    clip: rect(99px, 9999px, 43px, 0);
  }
  85% {
    clip: rect(33px, 9999px, 78px, 0);
  }
  90% {
    clip: rect(54px, 9999px, 21px, 0);
  }
  95% {
    clip: rect(2px, 9999px, 75px, 0);
  }
  100% {
    clip: rect(82px, 9999px, 41px, 0);
  }
}

@keyframes chromatic-aberration {
  0% {
    text-shadow:
      1px 0 0 rgba(255, 0, 255, 0.7),
      -1px 0 0 rgba(0, 255, 255, 0.7);
  }
  25% {
    text-shadow:
      -1px 0 0 rgba(255, 0, 255, 0.7),
      1px 0 0 rgba(0, 255, 255, 0.7);
  }
  50% {
    text-shadow:
      1px 2px 0 rgba(255, 0, 255, 0.7),
      -1px -2px 0 rgba(0, 255, 255, 0.7);
  }
  75% {
    text-shadow:
      -1px -2px 0 rgba(255, 0, 255, 0.7),
      1px 2px 0 rgba(0, 255, 255, 0.7);
  }
  100% {
    text-shadow:
      1px 0 0 rgba(255, 0, 255, 0.7),
      -1px 0 0 rgba(0, 255, 255, 0.7);
  }
}

@keyframes tool-appear-glitch {
  0% {
    opacity: 0;
    transform: translateX(-5px);
    text-shadow:
      2px 0 0 var(--accent-color),
      -2px 0 0 var(--secondary-color);
  }
  25% {
    opacity: 1;
    transform: translateX(5px);
    text-shadow:
      -2px 0 0 var(--accent-color),
      2px 0 0 var(--secondary-color);
  }
  50% {
    transform: translateX(-3px);
    text-shadow:
      1px 0 0 var(--accent-color),
      -1px 0 0 var(--secondary-color);
  }
  75% {
    transform: translateX(3px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
    text-shadow: inherit;
  }
}

#scanline-overlay {
  position: fixed;
  width: 100%;
  height: 100px; /* Height of the effect area */
  left: 0;
  top: 0;
  z-index: 999;
  pointer-events: none;
  transform: translateY(-100px); /* Start off-screen */
  animation: scanline-move 8s linear infinite;
  will-change: transform;
}

#scanline-overlay::before,
#scanline-overlay::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

#scanline-overlay::before {
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(255, 0, 255, 0.05) 48%,
    rgba(255, 0, 255, 0.1) 50%,
    rgba(255, 0, 255, 0.05) 52%,
    transparent 100%
  );
  backdrop-filter: blur(0.5px);
  animation: scanline-glitch 0.2s steps(1) infinite;
}

#scanline-overlay::after {
  background: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 255, 255, 0.05) 48%,
    rgba(0, 255, 255, 0.1) 50%,
    rgba(0, 255, 255, 0.05) 52%,
    transparent 100%
  );
  backdrop-filter: blur(0.5px);
  animation: scanline-glitch 0.2s steps(1) infinite reverse;
  animation-delay: 0.05s;
}

@keyframes scanline-move {
  100% {
    transform: translateY(100vh);
  }
}

@keyframes scanline-glitch {
  0% {
    transform: translateX(2px);
    clip-path: inset(10% 0 85% 0);
  }
  20% {
    transform: translateX(-3px);
    clip-path: inset(40% 0 42% 0);
  }
  40% {
    transform: translateX(1px);
    clip-path: inset(80% 0 5% 0);
  }
  60% {
    transform: translateX(3px);
    clip-path: inset(25% 0 60% 0);
  }
  80% {
    transform: translateX(-2px);
    clip-path: inset(55% 0 30% 0);
  }
  100% {
    transform: translateX(1px);
    clip-path: inset(90% 0 5% 0);
  }
}

.ai-message.tool-message {
  background-color: transparent;
  border: 1px dashed rgba(0, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: rgba(0, 255, 255, 0.6);
  animation: tool-appear-glitch 0.4s forwards;
}

.tool-reason {
  font-style: italic;
  color: rgba(0, 255, 255, 0.7);
}

.tool-name {
  color: rgba(0, 255, 255, 0.8);
  font-weight: 500;
}

.tool-parameters {
  margin-top: 0.25rem;
}

.tool-parameters summary {
  cursor: pointer;
  font-size: 0.9em;
  color: rgba(0, 255, 255, 0.7);
  outline: none;
  user-select: none;
  transition: color 0.2s ease;
}

.tool-parameters summary:hover {
  color: var(--secondary-color);
}

.tool-parameters pre {
  background-color: rgba(0, 255, 255, 0.05);
  padding: 0.75rem;
  border-radius: 0;
  margin-top: 0.5rem;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 0.9em;
  border: 1px solid var(--line-color);
  color: rgba(0, 255, 255, 0.9);
  text-shadow: none;
}

.ai-message .content-chunk {
  /* Use pre-wrap in JS to preserve whitespace, but display inline for flow */
  display: inline;
  animation: glitch-in 0.4s forwards;
  opacity: 0;
}

@keyframes glitch-in {
  0% {
    opacity: 0;
    transform: translate(-5px, 2px);
    text-shadow:
      1px 0 var(--accent-color),
      -1px 0 var(--secondary-color);
  }
  20% {
    opacity: 0.8;
    transform: translate(3px, -1px);
  }
  40% {
    opacity: 0.5;
    transform: translate(-3px, 1px);
    text-shadow: none;
  }
  60% {
    opacity: 1;
    transform: translate(2px, 2px);
  }
  80% {
    opacity: 1;
    transform: translate(-1px, -1px);
  }
  100% {
    opacity: 1;
    transform: translate(0, 0);
  }
}

.flashing-underscore {
  animation: blink 1s step-end infinite;
}

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

#history-screen {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  height: 100%;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 10;
  animation: fadeIn 0.5s ease-in-out;
  padding: 1.5rem 2.5rem;
  overflow-y: auto;
  background-color: var(--primary-color);
}

#history-screen.hidden {
  display: none;
}

.history-list {
  list-style: none;
  width: 100%;
  margin-top: 1rem;
  flex-grow: 1;
}

.history-item {
  border: 1px solid var(--line-color);
  margin-bottom: 1rem;
  transition: all 0.2s ease;
}

.history-item:hover {
  border-color: var(--secondary-color);
  box-shadow: 0 0 8px var(--secondary-color);
}

.history-item a {
  display: block;
  padding: 1rem 1.25rem;
  color: var(--secondary-color);
  text-decoration: none;
}

.session-preview {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  opacity: 0.8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-id {
  font-size: 0.7rem;
  opacity: 0.5;
  word-break: break-all;
}

.history-item-none {
  color: rgba(0, 255, 255, 0.7);
  font-style: italic;
}
@media (max-width: 768px) {
  #content {
    padding: 1rem 1.5rem;
  }
}