:root {
  color-scheme: dark;
  --bg-0: #05070d;
  --bg-1: #0a0f1c;
  --bg-2: #0e1526;
  --panel: #0d1424cc;
  --panel-border: #1e2c46;
  --cyan: #38e0ff;
  --cyan-soft: #7be9ff;
  --cyan-dim: #1c5b6e;
  --text-hi: #eaf6ff;
  --text-mid: #9fb3c8;
  --text-dim: #5c7086;
  --danger: #ff5d6c;
  --danger-glow: #ff5d6c55;
  --ok: #38e0ff;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, #0f2438 0%, transparent 55%),
    radial-gradient(ellipse 100% 60% at 50% 110%, #0a1830 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-0) 100%);
  color: var(--text-hi);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font-family: inherit;
}

.view {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}

/* Atribut hidden musi vyhrat nad display: flex u konkretnich view
   (UA stylesheet ma nizsi specificitu nez ID selektory nize). */
[hidden] {
  display: none !important;
}

/* ---------- Login view ---------- */

#loginView {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-left: calc(20px + var(--safe-l));
  padding-right: calc(20px + var(--safe-r));
}

.login-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  text-align: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.brand-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid var(--cyan);
  box-shadow:
    0 0 20px 2px #38e0ff66,
    inset 0 0 16px #38e0ff44;
  position: relative;
}

.brand-ring::before {
  content: "";
  position: absolute;
  inset: 16px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--cyan-soft) 0%, transparent 70%);
  filter: blur(1px);
}

.brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-hi);
  text-shadow: 0 0 18px #38e0ff55;
}

.subtitle {
  margin: 0;
  color: var(--text-mid);
  font-size: 15px;
}

#loginForm {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#tokenInput {
  width: 100%;
  padding: 16px 18px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--bg-2);
  color: var(--text-hi);
  font-size: 16px;
  outline: none;
  letter-spacing: 0.04em;
  user-select: text;
  -webkit-user-select: text;
}

#tokenInput:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px #38e0ff2e;
}

#loginSubmit {
  width: 100%;
  padding: 16px 18px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, #1fb9dd, #0f8fb0);
  color: #06131a;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 24px -6px #38e0ff88;
}

#loginSubmit:active {
  transform: scale(0.98);
}

#loginSubmit:disabled {
  opacity: 0.55;
  box-shadow: none;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* ---------- Main view ---------- */

#mainView {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px calc(18px + var(--safe-r)) 10px calc(18px + var(--safe-l));
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-mid);
}

.reset-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text-mid);
  display: flex;
  align-items: center;
  justify-content: center;
}

.reset-btn:active {
  color: var(--cyan);
  border-color: var(--cyan-dim);
  transform: scale(0.94);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 20px calc(20px + var(--safe-r)) calc(28px + var(--safe-b)) calc(20px + var(--safe-l));
  min-height: 0;
}

.mic-wrap {
  position: relative;
  width: 190px;
  height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-glow {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, #38e0ff3d 0%, transparent 68%);
  opacity: 0.7;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.mic-btn {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: 2px solid var(--cyan-dim);
  background: radial-gradient(circle at 50% 38%, #142234 0%, #0a1220 70%);
  color: var(--cyan-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 0 0 1px #0006,
    0 10px 30px -8px #000c,
    0 0 26px -4px #38e0ff55,
    inset 0 0 24px -6px #38e0ff33;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.15s ease;
}

.mic-btn:active {
  transform: scale(0.96);
}

.mic-btn .spinner-icon {
  display: none;
  position: absolute;
}

.mic-btn svg path {
  transition: opacity 0.2s ease;
}

/* idle */
#mainView.state-idle .mic-btn {
  border-color: var(--cyan-dim);
  box-shadow:
    0 0 0 1px #0006,
    0 10px 30px -8px #000c,
    0 0 26px -4px #38e0ff55,
    inset 0 0 24px -6px #38e0ff33;
}

/* recording: pulsing red ring */
#mainView.state-recording .mic-btn {
  border-color: var(--danger);
  color: #ffb3ba;
  animation: pulseRing 1.1s ease-in-out infinite;
}

#mainView.state-recording .mic-glow {
  background: radial-gradient(circle, #ff5d6c4a 0%, transparent 68%);
  opacity: 1;
}

@keyframes pulseRing {
  0%, 100% {
    box-shadow:
      0 0 0 1px #0006,
      0 10px 30px -8px #000c,
      0 0 0 0 #ff5d6c66,
      inset 0 0 24px -6px #ff5d6c44;
  }
  50% {
    box-shadow:
      0 0 0 1px #0006,
      0 10px 30px -8px #000c,
      0 0 0 16px #ff5d6c00,
      inset 0 0 30px -4px #ff5d6c66;
  }
}

/* thinking: spinner replaces mic icon */
#mainView.state-thinking .mic-btn {
  border-color: var(--cyan);
  pointer-events: none;
}

#mainView.state-thinking .mic-btn .mic-icon {
  display: none;
}

#mainView.state-thinking .mic-btn .spinner-icon {
  display: block;
  color: var(--cyan);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* speaking: animated glow */
#mainView.state-speaking .mic-btn {
  border-color: var(--cyan);
  animation: speakPulse 0.85s ease-in-out infinite;
}

#mainView.state-speaking .mic-glow {
  opacity: 1;
  animation: speakGlow 0.85s ease-in-out infinite;
}

@keyframes speakPulse {
  0%, 100% { box-shadow: 0 0 0 1px #0006, 0 10px 30px -8px #000c, 0 0 20px -2px #38e0ff88, inset 0 0 24px -6px #38e0ff55; }
  50% { box-shadow: 0 0 0 1px #0006, 0 10px 30px -8px #000c, 0 0 36px 4px #38e0ffaa, inset 0 0 30px -4px #38e0ff88; }
}

@keyframes speakGlow {
  0%, 100% { transform: scale(1); opacity: 0.7; }
  50% { transform: scale(1.08); opacity: 1; }
}

.status-text {
  margin: 0;
  font-size: 16px;
  color: var(--text-mid);
  letter-spacing: 0.02em;
  min-height: 1.4em;
  text-align: center;
}

.replay-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--cyan-dim);
  background: #0d1a24;
  color: var(--cyan-soft);
  font-size: 14px;
  font-weight: 600;
}

.replay-btn:active {
  transform: scale(0.97);
}

.transcript-box {
  width: 100%;
  max-width: 480px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  border-radius: 18px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  backdrop-filter: blur(8px);
  max-height: 34vh;
  overflow-y: auto;
}

.line {
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text-hi);
  user-select: text;
  -webkit-user-select: text;
}

.line-label {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.line-you .line-label {
  color: var(--text-mid);
}

.line-jarovis .line-label {
  color: var(--cyan);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  background: #1a0f14;
  border: 1px solid #ff5d6c66;
  color: #ffd9dc;
  padding: 13px 18px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 10px 30px -8px #000c, 0 0 20px -4px var(--danger-glow);
  z-index: 50;
  text-align: center;
}

.toast.toast-ok {
  background: #0d1a1e;
  border-color: #38e0ff66;
  color: #d8f6ff;
  box-shadow: 0 10px 30px -8px #000c, 0 0 20px -4px #38e0ff55;
}

@media (min-width: 560px) {
  .mic-wrap {
    width: 220px;
    height: 220px;
  }
  .mic-btn {
    width: 172px;
    height: 172px;
  }
}
