/* Enhancements: interactive terminal, now-playing widget, theme variables.
   --tc is an "r, g, b" triplet set by terminal.js; --term is the rgb() color. */

:root {
  --tc: 0, 255, 0;
  --term: rgb(0, 255, 0);
}

/* Old audio buttons are superseded by the Now Playing widget. Keep the
   elements in the DOM (legacy JS references them) but never show them. */
#mute-button,
#mobile-audio-button { display: none !important; }

/* About button repositioned to top-left so it clears the Now Playing widget. */
#about-button {
  top: 10px !important;
  left: 10px !important;
  bottom: auto !important;
  background: rgba(0, 0, 0, 0.72) !important;
  color: var(--term) !important;
  border-color: var(--term) !important;
  box-shadow: 0 0 12px rgba(var(--tc), 0.3) !important;
}

/* ---- Terminal launcher button ---- */
#kg-terminal-launch {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.75);
  color: var(--term);
  border: 1px solid var(--term);
  border-radius: 4px;
  padding: 8px 14px;
  font-family: 'Source Code Pro', monospace;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(var(--tc), 0.35);
  transition: all 0.2s ease;
}

#kg-terminal-launch:hover {
  background: rgba(var(--tc), 0.12);
  transform: translateY(-2px);
  box-shadow: 0 0 18px rgba(var(--tc), 0.55);
}

/* ---- Interactive terminal overlay ---- */
#kg-terminal {
  position: fixed;
  inset: 0;
  z-index: 100001;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

#kg-terminal.open {
  display: flex;
}

.kgt-window {
  width: min(720px, 92vw);
  height: min(560px, 82vh);
  background: rgba(0, 0, 0, 0.94);
  border: 1px solid var(--term);
  border-radius: 6px;
  box-shadow: 0 0 40px rgba(var(--tc), 0.4), inset 0 0 20px rgba(var(--tc), 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Source Code Pro', 'Courier New', monospace;
  animation: kgt-pop 0.18s ease;
}

@keyframes kgt-pop {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.kgt-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(var(--tc), 0.08);
  border-bottom: 1px solid var(--term);
  flex: 0 0 auto;
}

.kgt-title {
  color: var(--term);
  font-size: 13px;
  text-shadow: 0 0 5px rgba(var(--tc), 0.5);
}

.kgt-x {
  color: var(--term);
  cursor: pointer;
  font-size: 14px;
  padding: 0 4px;
  transition: transform 0.15s ease;
}

.kgt-x:hover {
  transform: scale(1.25);
}

.kgt-body {
  flex: 1 1 auto;
  padding: 14px;
  overflow-y: auto;
  color: var(--term);
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}

.kgt-body::-webkit-scrollbar {
  width: 6px;
}
.kgt-body::-webkit-scrollbar-thumb {
  background: rgba(var(--tc), 0.4);
  border-radius: 3px;
}

.kgt-out-line {
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: 0 0 4px rgba(var(--tc), 0.4);
  margin-bottom: 2px;
}

.kgt-out-line a {
  color: #fff;
  text-decoration: underline;
}

.kgt-sys { color: #fff; opacity: 0.9; }
.kgt-err { color: #ff5f56; text-shadow: 0 0 4px rgba(255, 95, 86, 0.5); }
.kgt-prompt { color: var(--term); opacity: 0.9; }

.kgt-art {
  color: var(--term);
  font-size: 11px;
  line-height: 1.15;
  text-shadow: 0 0 6px rgba(var(--tc), 0.6);
  overflow-x: auto;
}

.kgt-caret { animation: kgt-blink 1s step-end infinite; }
@keyframes kgt-blink { 50% { opacity: 0; } }

.kgt-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.kgt-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--term);
  font-family: inherit;
  font-size: 14px;
  caret-color: var(--term);
  text-shadow: 0 0 4px rgba(var(--tc), 0.4);
}

/* ---- Now Playing widget ---- */
#kg-nowplaying {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 9997;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid var(--term);
  border-radius: 20px;
  padding: 7px 16px 7px 12px;
  color: var(--term);
  font-family: 'Source Code Pro', monospace;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 0 12px rgba(var(--tc), 0.3);
  transition: all 0.2s ease;
}

#kg-nowplaying:hover {
  background: rgba(var(--tc), 0.12);
  box-shadow: 0 0 18px rgba(var(--tc), 0.5);
}

.kg-np-text {
  text-shadow: 0 0 4px rgba(var(--tc), 0.4);
  white-space: nowrap;
}

.kg-eq {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  width: 20px;
}

.kg-eq i {
  display: block;
  width: 3px;
  background: var(--term);
  box-shadow: 0 0 4px rgba(var(--tc), 0.6);
  animation: kg-eq-bounce 0.9s ease-in-out infinite;
}

.kg-eq i:nth-child(1) { height: 40%; animation-delay: 0s; }
.kg-eq i:nth-child(2) { height: 90%; animation-delay: 0.2s; }
.kg-eq i:nth-child(3) { height: 60%; animation-delay: 0.4s; }
.kg-eq i:nth-child(4) { height: 80%; animation-delay: 0.1s; }

@keyframes kg-eq-bounce {
  0%, 100% { transform: scaleY(0.35); }
  50% { transform: scaleY(1); }
}

/* Paused state: freeze bars flat */
#kg-nowplaying.kg-paused .kg-eq i {
  animation-play-state: paused;
  height: 20%;
}
#kg-nowplaying.kg-paused .kg-np-text { opacity: 0.55; }

/* ---- Reduced motion: calm everything down ---- */
@media (prefers-reduced-motion: reduce) {
  .matrix-bg { animation: none !important; }
  .kg-eq i { animation: none !important; height: 50% !important; }
  .kgt-caret { animation: none !important; }
  #kg-terminal-launch:hover,
  #kg-nowplaying:hover { transform: none; }
}

/* ---- Mobile ----
   Three controls, three corners: About = top-left, Now Playing = bottom-left,
   terminal launcher = bottom-right. Kept compact so nothing overlaps on a
   narrow (~320px) screen. */
@media only screen and (max-width: 768px) {
  #about-button {
    top: 12px !important;
    left: 12px !important;
    bottom: auto !important;
    padding: 6px 12px !important;
    font-size: 12px !important;
  }

  #kg-nowplaying {
    font-size: 11px;
    padding: 6px 12px 6px 10px;
    bottom: 14px;
    left: 12px;
    max-width: 58vw;
  }
  .kg-np-text {
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #kg-terminal-launch {
    bottom: 14px;
    right: 12px;
    padding: 6px 12px;
    font-size: 12px;
  }

  /* Anchor the terminal near the top with a little padding so it can't
     overflow the screen, and the input stays reachable above the keyboard.
     dvh tracks the *visible* viewport (shrinks when the keyboard opens). */
  #kg-terminal {
    align-items: flex-start;
    padding: 10px;
  }
  .kgt-window {
    width: 100%;
    height: 78vh;        /* fallback for older mobile browsers */
    height: 78dvh;
    max-height: 78dvh;
  }
  .kgt-body { font-size: 13px; padding: 12px; }
}

/* Extra-narrow phones: drop the Now Playing label, keep just the EQ bars,
   so it can never collide with the terminal launcher. */
@media only screen and (max-width: 380px) {
  .kg-np-text { display: none; }
  #kg-nowplaying { padding: 8px 10px; border-radius: 18px; }
}
