/* ===========================
   Reset & CSS Variables
   =========================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --cyan:    #00f7ff;
  --blue:    #0055ff;
  --purple:  #7700ff;
  --dark:    #04040f;
  --darker:  #020209;
  --glass:   rgba(4, 4, 20, 0.75);

  --glow-cyan:   0 0 8px #00f7ff, 0 0 20px rgba(0,247,255,0.4), 0 0 40px rgba(0,247,255,0.15);
  --glow-blue:   0 0 8px #0055ff, 0 0 20px rgba(0,85,255,0.4);
  --glow-red:    0 0 8px #ff4444, 0 0 20px rgba(255,68,68,0.4);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--darker);
  font-family: 'Helvetica Neue', 'Hiragino Sans', Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* ===========================
   Setup Screen
   =========================== */
#setup-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #080828 0%, var(--darker) 70%);
  z-index: 200;
  overflow: hidden;
}

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

.scan-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
  opacity: 0.4;
  animation: scan 4s linear infinite;
}
@keyframes scan {
  0%   { top: 0%; }
  100% { top: 100%; }
}

.setup-container {
  text-align: center;
  padding: 48px 40px;
  width: min(340px, 90vw);
  position: relative;
}

.setup-logo {
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 200;
  letter-spacing: 14px;
  color: var(--cyan);
  text-shadow: var(--glow-cyan);
  margin-bottom: 6px;
  animation: logo-pulse 3s ease-in-out infinite;
}
@keyframes logo-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.85; }
}

.setup-subtitle {
  font-size: 11px;
  letter-spacing: 5px;
  color: rgba(0, 247, 255, 0.5);
  margin-bottom: 52px;
}

.setup-form label {
  display: block;
  font-size: 10px;
  letter-spacing: 3px;
  color: rgba(0, 247, 255, 0.6);
  margin-bottom: 10px;
  text-align: left;
}

.setup-form input {
  width: 100%;
  background: rgba(0, 247, 255, 0.04);
  border: 1px solid rgba(0, 247, 255, 0.25);
  border-radius: 3px;
  color: #fff;
  padding: 13px 16px;
  font-size: 14px;
  outline: none;
  margin-bottom: 14px;
  transition: border-color 0.3s, box-shadow 0.3s;
  font-family: monospace;
}
.setup-form input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 12px rgba(0,247,255,0.2);
}

.setup-form button {
  width: 100%;
  background: linear-gradient(135deg,
    rgba(0,247,255,0.1) 0%,
    rgba(0,85,255,0.15) 100%);
  border: 1px solid rgba(0,247,255,0.5);
  color: var(--cyan);
  padding: 14px;
  font-size: 13px;
  letter-spacing: 5px;
  cursor: pointer;
  border-radius: 3px;
  text-shadow: 0 0 8px var(--cyan);
  box-shadow: var(--glow-cyan);
  transition: all 0.3s;
}
.setup-form button:hover,
.setup-form button:active {
  background: rgba(0, 247, 255, 0.2);
  box-shadow: 0 0 20px rgba(0,247,255,0.4), 0 0 40px rgba(0,247,255,0.2);
}

.setup-hint {
  margin-top: 20px;
  font-size: 10px;
  color: rgba(255,255,255,0.2);
  letter-spacing: 0.5px;
}

/* ===========================
   Main App
   =========================== */
#app {
  position: fixed;
  inset: 0;
}
#app.hidden { display: none; }

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ===========================
   Loading Screen
   =========================== */
#loading-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  pointer-events: none;
  transition: opacity 0.8s;
}
#loading-screen.done { opacity: 0; }

.loading-text {
  font-size: 11px;
  letter-spacing: 4px;
  color: rgba(0,247,255,0.5);
  animation: blink 1s step-end infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

.loading-bar {
  width: 160px;
  height: 2px;
  background: rgba(0,247,255,0.1);
  border-radius: 2px;
  overflow: hidden;
}
#loading-progress {
  height: 100%;
  width: 0%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  transition: width 0.3s ease;
}

/* ===========================
   Mic Button (Holographic)
   =========================== */
#mic-btn {
  position: fixed;
  top: max(24px, env(safe-area-inset-top, 24px));
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,247,255,0.12) 0%, rgba(0,247,255,0.04) 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s;
}
#mic-btn:active { transform: scale(0.92); }

.mic-ring {
  position: absolute;
  border-radius: 50%;
  border: 1px solid rgba(0,247,255,0.35);
  pointer-events: none;
}
.mic-ring-inner {
  width: 56px;
  height: 56px;
  animation: ring-idle 2.5s ease-in-out infinite;
}
.mic-ring-outer {
  width: 74px;
  height: 74px;
  animation: ring-idle 2.5s ease-in-out infinite 0.6s;
  border-color: rgba(0,247,255,0.15);
}
@keyframes ring-idle {
  0%, 100% { transform: scale(1);    opacity: 0.8; }
  50%       { transform: scale(1.04); opacity: 1;   }
}

.mic-icon {
  width: 22px;
  height: 22px;
  color: var(--cyan);
  filter: drop-shadow(0 0 5px var(--cyan));
  position: relative;
  z-index: 1;
  transition: color 0.3s, filter 0.3s;
}

.mic-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0,247,255,0.15) 0%, transparent 70%);
  pointer-events: none;
}

/* Listening state */
#mic-btn.listening .mic-ring-inner {
  animation: ring-active 0.6s ease-in-out infinite;
  border-color: rgba(255, 80, 80, 0.7);
}
#mic-btn.listening .mic-ring-outer {
  animation: ring-active 0.6s ease-in-out infinite 0.15s;
  border-color: rgba(255, 80, 80, 0.3);
}
#mic-btn.listening .mic-icon {
  color: #ff5050;
  filter: drop-shadow(0 0 8px #ff5050);
}
#mic-btn.listening .mic-glow {
  background: radial-gradient(circle, rgba(255,80,80,0.2) 0%, transparent 70%);
}
@keyframes ring-active {
  0%, 100% { transform: scale(1);    opacity: 1;   }
  50%       { transform: scale(1.12); opacity: 0.8; }
}

/* Processing state */
#mic-btn.processing .mic-ring-inner {
  animation: ring-spin 1.5s linear infinite;
  border-color: rgba(0, 150, 255, 0.6);
  border-top-color: var(--cyan);
}
#mic-btn.processing .mic-ring-outer { opacity: 0.2; }
#mic-btn.processing .mic-icon {
  color: var(--blue);
  filter: drop-shadow(0 0 5px var(--blue));
}
@keyframes ring-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ===========================
   Status Bar
   =========================== */
#status-bar {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom, 28px));
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 50;
  pointer-events: none;
}

.status-line {
  width: 24px;
  height: 1px;
  background: rgba(0,247,255,0.3);
}

#status-text {
  font-size: 10px;
  letter-spacing: 2.5px;
  color: rgba(0, 247, 255, 0.55);
  text-shadow: 0 0 10px rgba(0,247,255,0.3);
  transition: color 0.3s;
}

/* ===========================
   Message Box
   =========================== */
#message-box {
  position: fixed;
  bottom: max(75px, env(safe-area-inset-bottom, 75px));
  left: 20px;
  right: 20px;
  background: var(--glass);
  border: 1px solid rgba(0,247,255,0.2);
  border-radius: 6px;
  padding: 14px 18px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 50;
  max-height: 180px;
  overflow-y: auto;
  animation: msg-in 0.3s ease;
}
#message-box.hidden { display: none; }

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

/* Corner decorations */
.message-corner {
  position: absolute;
  width: 8px;
  height: 8px;
  border-color: var(--cyan);
  border-style: solid;
  opacity: 0.6;
}
.message-corner.tl { top: -1px; left: -1px;  border-width: 1px 0 0 1px; }
.message-corner.tr { top: -1px; right: -1px; border-width: 1px 1px 0 0; }
.message-corner.bl { bottom: -1px; left: -1px;  border-width: 0 0 1px 1px; }
.message-corner.br { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; }

#message-text {
  font-size: 13px;
  line-height: 1.7;
  color: rgba(255,255,255,0.88);
  word-break: break-word;
}

/* ===========================
   Manual Overlay
   =========================== */
#manual-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 2, 9, 0.92);
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fade-in 0.3s ease;
}
#manual-overlay.hidden { display: none; }

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.manual-container {
  width: min(400px, 92vw);
  max-height: 82vh;
  background: rgba(4, 4, 22, 0.95);
  border: 1px solid rgba(0,247,255,0.25);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(0,247,255,0.08);
}

.manual-header {
  padding: 16px 20px;
  border-bottom: 1px solid rgba(0,247,255,0.15);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.manual-title {
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--cyan);
  text-shadow: 0 0 8px var(--cyan);
}
.manual-header button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.35);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}
.manual-header button:hover { color: rgba(255,255,255,0.7); }

.manual-content {
  padding: 24px 20px;
  overflow-y: auto;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  line-height: 1.85;
  -webkit-overflow-scrolling: touch;
}
.manual-content h3 {
  color: var(--cyan);
  font-size: 11px;
  letter-spacing: 2px;
  margin: 20px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0,247,255,0.15);
}
.manual-content h3:first-child { margin-top: 0; }
.manual-content p  { margin-bottom: 10px; }
.manual-content strong { color: rgba(255,255,255,0.95); }
