:root {
  --bg: #0b0d10;
  --bg-elevated: #14171c;
  --bg-inset: #05070a;
  --border: #2b2f36;
  --text: #e4e6ea;
  --text-muted: #8b9099;
  --accent: #f2a93c;
  --accent-hover: #ffbb5c;
  --accent-fg: #1c1206;
  --success: #238636;
  --success-hover: #2ea043;
  --danger: #f85149;
  --radius: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --hazard-stripes: repeating-linear-gradient(
    135deg,
    var(--accent) 0px,
    var(--accent) 10px,
    #1a1a1a 10px,
    #1a1a1a 20px
  );
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.015) 0px,
      rgba(255, 255, 255, 0.015) 1px,
      transparent 1px,
      transparent 12px
    ),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

body.factory-running::after {
  opacity: 1;
  animation: factory-pulse 1.6s ease-in-out infinite;
}

@keyframes factory-pulse {
  0%, 100% {
    box-shadow: inset 0 0 80px 0 rgba(242, 169, 60, 0.1);
  }
  50% {
    box-shadow: inset 0 0 140px 20px rgba(242, 169, 60, 0.22);
  }
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  padding-bottom: calc(0.75rem + 4px);
  background: var(--bg-elevated);
}

.topbar::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 4px;
  background: var(--hazard-stripes);
  background-size: 28px 28px;
  opacity: 0.25;
  transition: opacity 0.3s ease;
}

body.factory-running .topbar::after {
  opacity: 1;
  animation: hazard-scroll 0.9s linear infinite;
}

@keyframes hazard-scroll {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 28px 0;
  }
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.gear {
  flex: none;
  color: var(--accent);
  animation: gear-spin 6s linear infinite;
}

body.factory-running .gear {
  animation-duration: 0.9s;
  filter: drop-shadow(0 0 4px var(--accent));
}

@keyframes gear-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.container {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 2rem 1rem;
  flex: 1;
}

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  max-width: none;
  padding: 1rem;
}

.card {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  padding-top: calc(1.5rem + 4px);
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--hazard-stripes);
  background-size: 24px 24px;
  opacity: 0.45;
}

.auth-card {
  width: 100%;
  max-width: 360px;
}

.auth-card h1 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

h1 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.history-card {
  margin-top: 1.5rem;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.history-item {
  width: 4rem;
  height: 4rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  background: var(--bg-inset);
}

.history-item:hover {
  border-color: var(--accent);
}

.history-item-liked {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.history-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

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

.form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-row {
  display: flex;
  gap: 0.75rem;
}

.form-row .input {
  flex: 1;
}

.input {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(242, 169, 60, 0.3);
}

.textarea {
  min-height: 6rem;
  resize: vertical;
}

.btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-elevated);
  color: var(--text);
  transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
}

.btn:hover {
  border-color: var(--text-muted);
}

.btn-hiding {
  opacity: 0;
  transform: scale(0.9);
  pointer-events: none;
}

.btn-primary {
  background: var(--success);
  border-color: rgba(240, 246, 252, 0.1);
  color: #ffffff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-primary:hover {
  background: var(--success-hover);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-inset);
}

.alert {
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.alert-error {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid rgba(248, 81, 73, 0.4);
  color: #ffa198;
}

.field-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -0.25rem 0 0;
}

.result {
  margin-top: 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.result img {
  max-width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.image-reveal {
  position: relative;
  cursor: pointer;
}

.image-reveal img {
  transition: filter 0.15s ease;
}

.image-reveal.blurred img {
  filter: blur(24px);
}

.phrase {
  display: inline-block;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.phrase-hidden {
  opacity: 0;
  transform: translateY(4px);
}

/* Exactly four looks, picked at random (never twice in a row) in main.js:
   left-to-right shimmer, heartbeat pulse, and two staggered toss-up sweeps
   (per letter / per word) — the latter two need each unit in its own
   inline-block span so animation-delay can stagger them left to right. */

.phrase-anim-shimmer {
  background: linear-gradient(
    90deg,
    var(--text-muted) 0%,
    var(--text-muted) 35%,
    var(--text) 50%,
    var(--text-muted) 65%,
    var(--text-muted) 100%
  );
  background-size: 250% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: phrase-shimmer 1.6s linear infinite;
}

.phrase-anim-heartbeat {
  animation: phrase-heartbeat 1.1s ease-in-out infinite;
}

.phrase-unit {
  display: inline-block;
  white-space: pre;
}

.phrase-unit-letter {
  animation: phrase-toss 0.7s ease-in-out infinite;
}

.phrase-unit-word {
  animation: phrase-toss 0.9s ease-in-out infinite;
}

@keyframes phrase-shimmer {
  0% {
    background-position: 250% 0;
  }
  100% {
    background-position: -50% 0;
  }
}

@keyframes phrase-heartbeat {
  0%, 100% {
    color: var(--text);
  }
  14% {
    color: var(--text-muted);
  }
  28% {
    color: var(--text);
  }
  42% {
    color: var(--text-muted);
  }
  56% {
    color: var(--text);
  }
}

@keyframes phrase-toss {
  0%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-3px);
  }
  50% {
    transform: translateY(0);
  }
}

@keyframes result-enter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.result-enter {
  animation: result-enter 0.35s ease-out;
}

.image-reveal .reveal-hint {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius);
}

.image-reveal.blurred .reveal-hint {
  display: flex;
}

.rating-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
}

.btn-active {
  border-color: var(--accent);
  color: var(--accent-fg);
  background: var(--accent);
}
