:root {
  --bg0: #07090e;
  --bg1: #121722;
  --ink: #f4efe6;
  --muted: #a39a8c;
  --accent: #e4572e;
  --accent-soft: rgba(228, 87, 46, 0.18);
  --line: rgba(244, 239, 230, 0.12);
  --ok: #7dce82;
  --warn: #e0b35a;
  --err: #e86a6a;
  --font-display: "Bebas Neue", "Arial Narrow", sans-serif;
  --font-body: "Manrope", Georgia, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(120% 80% at 80% -10%, rgba(228, 87, 46, 0.22), transparent 55%),
    radial-gradient(90% 70% at 10% 100%, rgba(40, 70, 110, 0.35), transparent 50%),
    linear-gradient(165deg, #0b0d12 0%, #151b28 48%, #0a0c11 100%);
  pointer-events: none;
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0, 0, 0, 0.55) 100%);
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 1;
  opacity: 0.05;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.shell {
  position: relative;
  z-index: 2;
  width: min(40rem, 100%);
  margin: 0 auto;
  padding:
    calc(1.5rem + var(--safe-top))
    calc(1.25rem + var(--safe-right))
    calc(2.5rem + var(--safe-bottom))
    calc(1.25rem + var(--safe-left));
}

.brand-block {
  margin-bottom: 2.25rem;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(3.4rem, 14vw, 5.5rem);
  letter-spacing: 0.04em;
  line-height: 0.9;
  color: var(--ink);
  text-shadow: 0 0 40px rgba(228, 87, 46, 0.25);
}

.headline {
  margin: 0.85rem 0 0.4rem;
  font-family: var(--font-body);
  font-size: clamp(1.15rem, 3.8vw, 1.45rem);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  max-width: 28rem;
  color: var(--muted);
  font-size: 0.98rem;
  line-height: 1.5;
}

.hero-code {
  min-height: 42vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0.5rem 0 1.5rem;
}

.eyebrow {
  margin: 0 0 0.65rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.code {
  margin: 0;
  font-family: var(--font-mono);
  font-size: clamp(3.2rem, 16vw, 5.8rem);
  font-weight: 600;
  letter-spacing: 0.18em;
  line-height: 1.05;
  word-break: break-all;
  transform-origin: left center;
}

.code.is-fresh {
  animation: code-in 0.55s ease-out, fresh-pulse 2.4s ease-in-out 0.55s 2;
}

.meta {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.actions {
  margin-top: 1.5rem;
}

.btn-copy {
  appearance: none;
  border: 0;
  min-height: 48px;
  min-width: min(100%, 16rem);
  padding: 0.9rem 1.4rem;
  border-radius: 999px;
  background: var(--accent);
  color: #140c09;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}

.btn-copy:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #f06a3d;
}

.btn-copy:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-copy:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-copy.is-copied {
  background: var(--ok);
  color: #102014;
}

.shell-login {
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  justify-content: center;
}

.pin-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  max-width: 22rem;
}

.pin-input {
  appearance: none;
  width: 100%;
  min-height: 4.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(18, 23, 34, 0.72);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 600;
  letter-spacing: 0.42em;
  text-align: center;
  caret-color: var(--accent);
}

.pin-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pin-input[aria-invalid="true"] {
  border-color: var(--err);
}

.pin-error {
  margin: 0;
  color: var(--err);
  font-size: 0.92rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.5rem 0 2rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.logout {
  margin-left: auto;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
}

#imap-text {
  flex: 1;
  min-width: 0;
}

.logout:hover,
.logout:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

.status-dot {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--muted);
  box-shadow: 0 0 0 4px rgba(163, 154, 140, 0.12);
}

.status-dot[data-state="ok"] {
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(125, 206, 130, 0.15);
}

.status-dot[data-state="connecting"],
.status-dot[data-state="starting"],
.status-dot[data-state="demo"] {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(224, 179, 90, 0.15);
}

.status-dot[data-state="error"],
.status-dot[data-state="unconfigured"] {
  background: var(--err);
  box-shadow: 0 0 0 4px rgba(232, 106, 106, 0.15);
}

.history h2 {
  margin: 0 0 0.85rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.history ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}

.history li.empty {
  color: var(--muted);
  border-bottom: 0;
}

.hist-code {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.08em;
}

.history li.fresh .hist-code {
  color: var(--accent);
}

.hist-time {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

@keyframes code-in {
  from {
    opacity: 0;
    transform: translateY(0.45rem) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fresh-pulse {
  0%,
  100% {
    text-shadow: 0 0 0 transparent;
  }
  50% {
    text-shadow: 0 0 28px var(--accent-soft);
  }
}

@media (min-width: 720px) {
  .shell {
    padding-top: calc(2.75rem + var(--safe-top));
  }

  .hero-code {
    min-height: 38vh;
  }
}

@media (prefers-reduced-motion: reduce) {
  .code.is-fresh,
  .btn-copy {
    animation: none !important;
    transition: none !important;
  }
}
