/* ===============================
   Bendigo-inspired Dark Theme
   with darker glass surfaces
   =============================== */

/* ===== Theme Tokens ===== */
:root {
  /* Surfaces & text */
  --midnight: #071424;
  --deep-navy: #0b1e33;
  --panel: #0f2236;
  --panel-2: #122b45;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eaf2f9;
  --muted: #a9c1cf;

  /* Accents */
  --accent-lime: #c4fa2e;
  --accent-lime-2: #a9e01f;
  --azure: #1e88e5;
  --deep-blue: #0b1429;
  --light-blue: #42b7c7;
  --teal: #0ea5a5;
  --danger: #ff3b30;

  /* Orb */
  --orb-outer: radial-gradient(
    120px 120px at 50% 50%,
    rgba(30, 136, 229, 0.45),
    rgba(14, 165, 165, 0.25),
    transparent 70%
  );
  --orb-inner: radial-gradient(
    60px 60px at 50% 50%,
    rgba(14, 165, 165, 0.95),
    rgba(30, 136, 229, 0.65),
    transparent 70%
  );

  /* Shadows/Radii */
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 12px 28px rgba(0, 0, 0, 0.3);
  --radius: 16px;
  --radius-sm: 10px;

  /* Glass presets */
  --glass-bg: rgba(8, 14, 22, 0.78); /* primary tinted glass */
  --glass-elev: rgba(
    10,
    18,
    28,
    0.86
  ); /* higher-elevation glass (modals/menus) */
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-topline: rgba(255, 255, 255, 0.08);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  height: 100%;
  overflow: hidden;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--deep-navy);
  position: relative;
  isolation: isolate;
}

/* Ambient background (slightly dimmer) */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: -20%;
  z-index: -2;
  filter: blur(60px) saturate(115%);
  pointer-events: none;
}
body::before {
  background: radial-gradient(
      600px 480px at 15% 25%,
      rgba(30, 136, 229, 0.2),
      transparent 60%
    ),
    radial-gradient(
      800px 520px at 85% 20%,
      rgba(12, 200, 180, 0.14),
      transparent 60%
    ),
    radial-gradient(
      900px 600px at 50% 110%,
      rgba(11, 21, 32, 0.8),
      transparent 70%
    ),
    linear-gradient(180deg, #081425 0%, #06101d 100%);
  animation: bgFloat1 36s ease-in-out infinite;
}
body::after {
  background: radial-gradient(
      520px 520px at 50% 40%,
      rgba(196, 250, 46, 0.08),
      transparent 62%
    ),
    radial-gradient(
      600px 420px at 10% 100%,
      rgba(30, 136, 229, 0.14),
      transparent 65%
    );
  mix-blend-mode: screen;
  animation: bgFloat2 28s ease-in-out infinite reverse;
}
@keyframes bgFloat1 {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, -2%, 0) scale(1.02);
  }
}
@keyframes bgFloat2 {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(0, 2%, 0) scale(0.98);
  }
}
@media (prefers-reduced-motion: reduce) {
  body::before,
  body::after {
    animation: none;
  }
}

/* ===== App Frame (GRID LAYOUT) ===== */
#app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px;
  height: 100dvh;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto auto 1fr auto;
  gap: 16px;
}
.heading-gradient,
#header-container,
#user-header,
#controls {
  grid-column: 1/-1;
}

/* Heading */
.heading-gradient {
  background: linear-gradient(180deg, #fff 0%, rgba(255, 255, 255, 0.6) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-align: center;
  margin: 4px;
  position: relative;
}
.heading-gradient::after {
  content: "";
  display: block;
  height: 4px;
  width: clamp(120px, 24%, 260px);
  margin: 10px auto 0;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(196, 250, 46, 1) 0%,
    rgba(11, 20, 41, 1) 50%,
    rgba(66, 183, 199, 1) 100%
  );
}

/* Header / Status */
#header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
#status {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
  box-shadow: var(--shadow-md);
}
#status.ready,
#status.connected {
  background: rgba(196, 250, 46, 0.83);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(5.7px);
  -webkit-backdrop-filter: blur(5.7px);
  border: 1px solid rgba(196, 250, 46, 0.84);
  color: #06101d;
  font-weight: 700;
}

/* Settings cog */
#config-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: radial-gradient(
    120% 120% at 30% 20%,
    rgba(196, 250, 46, 0.25),
    rgba(30, 136, 229, 0.15)
  );
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s;
}
#config-button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}
#config-button i {
  font-size: 22px;
}

/* User chip + dropdown */
#user-header {
  display: flex;
  justify-content: center;
  margin: 6px 0 0;
}
#user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  user-select: none;
  box-shadow: var(--shadow-md);
}
#user-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--light-blue);
}
/* DARK GLASS DROPDOWN */
.dropdown-content {
  position: absolute;
  top: 48px;
  left: 0;
  width: 140px;
  background: var(--glass-elev);
  backdrop-filter: blur(10px) saturate(110%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 8px;
  display: none;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
  z-index: 10;
}
#user-box.open .dropdown-content {
  display: block;
}
.voice-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  transition: background 0.15s ease, transform 0.12s ease;
  cursor: pointer;
}
.voice-option:hover {
  background: rgba(255, 255, 255, 0.03);
  transform: translateY(-1px);
}
.voice-option.selected {
  outline: 1px solid rgba(196, 250, 46, 0.35);
  background: rgba(196, 250, 46, 0.08);
}
.voice-icon {
  opacity: 0.9;
}
.voice-name {
  color: var(--text);
}

/* ===== Content: Orb & Chat ===== */
#orb-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
}
#pulsating-orb {
  width: clamp(72px, 26vw, 360px);
  height: clamp(72px, 26vw, 360px);
  border-radius: 50%;
  background: var(--orb-outer);
  position: relative;
  filter: drop-shadow(0 30px 50px rgba(0, 0, 0, 0.35));
  animation: float 6s ease-in-out infinite;
  outline: 1px solid rgba(255, 255, 255, 0.06);
  outline-offset: -1px;
}
#pulsating-orb .inner-glow {
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  background: var(--orb-inner);
  animation: pulse 2.8s ease-in-out infinite;
}
#pulsating-orb .voice-waves::before,
#pulsating-orb .voice-waves::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid rgba(14, 165, 165, 0.35);
  animation: wave 3.6s ease-in-out infinite;
}
#pulsating-orb .voice-waves::after {
  animation-delay: 1.8s;
  border-color: rgba(30, 136, 229, 0.35);
}
.role-label {
  font-weight: 800;
  color: var(--accent-lime);
  margin-top: 10px;
}

/* CHAT: dark tinted glass (high readability) */
#chat-container {
  overflow: auto;
  padding: 16px 18px;
  min-height: 200px;
  background: rgba(62, 96, 130, 0.13);
  border-radius: 16px;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(62, 96, 130, 0.3);
}

/* ===== Controls (sticky) ===== */
#controls {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(
    to top,
    rgba(7, 20, 36, 0.96),
    rgba(7, 20, 36, 0)
  );
  padding: 10px 0 calc(10px + var(--safe-bottom));
}
#status-text {
  color: #b7d8ff;
  font-size: 0.9rem;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
#buttons-container {
  display: flex;
  gap: 16px;
  align-items: center;
}
.control-button {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background-color 0.2s;
  background: radial-gradient(
    140% 140% at 30% 20%,
    var(--accent-lime),
    var(--accent-lime-2)
  );
  color: #06101d;
  outline: 2px solid rgba(196, 250, 46, 0.15);
}
.control-button.danger {
  background: #ff3b30;
  color: #fff;
  outline-color: rgba(255, 59, 48, 0.25);
}
.control-button:hover {
  transform: translateY(-1px) scale(1.03);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
}
.control-button i {
  font-size: 26px;
}

/* ===== Modal (SETTINGS) – dark glass, no gradients ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  z-index: 100;
}
.modal.open {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-content {
  position: relative;
  width: min(860px, calc(100% - 24px));
  min-height: 60%;
  border-radius: 20px;
  background: rgba(10, 12, 16, 0.92); /* near-black glass */
  backdrop-filter: blur(14px) saturate(120%);
  border: 1px solid rgba(66, 183, 199, 0.22); /* subtle blue edge */
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* ambient purple/blue glow */
.modal-content::before {
  content: "";
  position: absolute;
  inset: -25% -15% auto auto;
  width: 520px;
  height: 520px;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    240px 240px at 25% 75%,
    rgba(66, 183, 199, 0.22),
    transparent 68%
  );
  filter: blur(34px);
}
.modal-content::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 20px;
  box-shadow: inset 0 0 0 1px rgba(66, 183, 199, 0.14);
}
.modal-header {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid rgba(66, 183, 199, 0.18);
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.3px;
  color: var(--light-blue);
}
.close-modal {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(66, 183, 199, 0.24);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.close-modal:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  background: rgba(66, 183, 199, 0.12);
}

.modal-body {
  position: relative;
  z-index: 1;
  padding: 18px;
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-footer {
  position: relative;
  z-index: 1;
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid rgba(66, 183, 199, 0.18);
}

.modal-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 12px 0;
  z-index: 1;
}
.tab {
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(66, 183, 199, 0.18);
  color: var(--muted);
  transition: background 0.15s ease, transform 0.12s ease,
    border-color 0.15s ease;
}
.tab:hover {
  transform: translateY(-1px);
}
.tab.active {
  color: var(--text);
  background: rgba(66, 183, 199, 0.12);
  border-color: rgba(66, 183, 199, 0.35);
}

.tab-content {
  display: none;
  padding: 12px;
  border-radius: 16px;
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(66, 183, 199, 0.16);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
.tab-content.active {
  display: flex;
  flex: 1;
  flex-direction: column;
}

/* inputs inside settings only */
.modal-content select,
.modal-content textarea {
  background: rgba(8, 14, 22, 0.65);
  border: 1px solid rgba(66, 183, 199, 0.18);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, box-shadow 0.15s ease,
    background 0.15s ease;
}
.modal-content select:focus,
.modal-content textarea:focus {
  border-color: rgba(66, 183, 199, 0.55);
  box-shadow: 0 0 0 3px rgba(66, 183, 199, 0.18);
  background: rgba(8, 14, 22, 0.72);
}

.form-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
#prompt-tab {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.5rem;
}
#prompt-select-container {
  flex: 0 0 auto;
}
#prompt-select-container label {
  margin-bottom: 0.25rem;
}
#prompt-editor-container {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
}
#prompt-editor-container label {
  margin-bottom: 0.25rem;
}
#prompt-editor {
  flex: 1 1 auto;
  min-height: 0;
  resize: none;
  overflow: auto;
  margin-top: 0.5rem;
}

label {
  color: var(--muted);
  font-size: 13px;
}
select,
textarea {
  background: rgba(8, 14, 22, 0.65);
  border: 1px solid var(--glass-border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}
textarea {
  resize: vertical;
  min-height: 140px;
}

/* Secondary buttons */
.button {
  padding: 14px 22px;
  border-radius: 12px;
  border: 1px solid rgb(205, 41, 41);
  font-weight: 800;
  letter-spacing: 0.2px;
  background: rgba(205, 41, 41, 0.55);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s, background 0.2s,
    border-color 0.2s;
}
.button.primary {
  border-color: rgb(196, 250, 46);
  background: rgba(196, 250, 46, 0.55);
  color: #ffffff;
}
.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ===== Animations ===== */
@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.95;
  }
  50% {
    transform: scale(1.05);
    opacity: 1;
  }
}
@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}
@keyframes wave {
  0% {
    transform: scale(1);
    opacity: 0.55;
  }
  60% {
    transform: scale(1.2);
    opacity: 0.15;
  }
  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

/* ===== Responsive Rules (unchanged behavior) ===== */
@media (min-width: 900px) {
  #app {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto minmax(340px, 1fr) auto;
    gap: 20px;
  }
  .heading-gradient,
  .heading-gradient #header-container,
  #user-header,
  #controls {
    grid-column: 1/-1;
  }
  #orb-container {
    align-self: center;
  }
  #chat-container {
    align-self: stretch;
    height: 100%;
    max-height: 62vh;
    overflow: auto;
  }
  #pulsating-orb {
    width: clamp(120px, 22vw, 320px);
    height: clamp(120px, 22vw, 320px);
  }
}
@media (min-width: 1200px) and (min-height: 800px) {
  #chat-container {
    max-height: 68vh;
  }
  #pulsating-orb {
    width: clamp(160px, 22vw, 360px);
    height: clamp(160px, 22vw, 360px);
  }
}
@media (min-width: 700px) and (max-height: 800px) {
  #app {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto auto minmax(300px, 1fr) auto;
    gap: 18px;
  }
  #pulsating-orb {
    width: clamp(96px, 18vw, 200px);
    height: clamp(96px, 18vw, 200px);
  }
  #chat-container {
    max-height: 58vh;
  }
  #controls {
    padding-bottom: 8px;
  }
}
@media (min-height: 800px) {
  #controls {
    padding-bottom: calc(16px + var(--safe-bottom));
  }
}
@media (max-width: 420px) {
  #orb-container {
    min-height: 3vh;
  }
  #controls {
    gap: 0;
  }
  h1 {
    padding: 0;
  }
  #chat-container {
    min-height: 260px;
  }
}
@media (max-width: 380px) and (max-height: 740px) {
  #pulsating-orb {
    width: 64px;
    height: 64px;
  }
  #chat-container {
    min-height: 220px;
    max-height: 38vh;
  }
  #controls {
    padding-bottom: 4px;
  }
}
@media (min-width: 380px) and (max-width: 432px) and (min-height: 700px) and (max-height: 940px) {
  #pulsating-orb {
    width: 100px;
    height: 100px;
  }
  #chat-container {
    max-height: 45vh;
  }
  #controls {
    padding-bottom: 8px;
  }
}
