/* ============================================================
   Modular Synthesis Course at Do.w — Stylesheet
   ============================================================ */

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

/* ── DESIGN TOKENS ──────────────────────────────────────── */

:root {
  --bg:           #0a0a0f;
  --surface:      #101016;
  --surface-2:    #16161f;
  --surface-3:    #1c1c28;
  --accent-1:     #c8a96e;
  --accent-2:     #6e8ec8;
  --accent-dim:   #6b5a38;
  --text-primary: #e8e4d8;
  --text-muted:   #6a6660;
  --text-faint:   #3a3830;
  --border:       #22222e;
  --border-light: #2e2e3e;

  --tiago:  #6ec8b4;
  --diogo:  #c8a96e;
  --andre:  #a96ec8;

  --diff-easy:   #5a8a6e;
  --diff-medium: #c8a96e;
  --diff-hard:   #c86e6e;

  /* Card dimensions: fluid, capped at 380×560 */
  --card-w: min(380px, 92vw);
  --card-h: calc(var(--card-w) * 1.4737);
  --card-r: 14px;
}

/* ── BASE ───────────────────────────────────────────────── */

html {
  overflow-x: hidden; /* prevent horizontal scroll on mobile */
}

body {
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: 'IBM Plex Mono', 'Courier New', monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100dvh;
  /* safe area insets for notched phones */
  padding: 2.5rem 1rem env(safe-area-inset-bottom, 1.5rem);
  padding-bottom: max(3rem, env(safe-area-inset-bottom, 1rem) + 2rem);
  gap: 0;
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(110, 142, 200, 0.07) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at 50% 110%, rgba(200, 169, 110, 0.05) 0%, transparent 60%);
  -webkit-tap-highlight-color: transparent;
}

/* ── HEADER ─────────────────────────────────────────────── */

.site-header {
  text-align: center;
  margin-bottom: 2.5rem;
  animation: fade-in 0.8s ease forwards;
  padding: 0 0.5rem;
}

.site-header__eyebrow {
  font-size: clamp(0.55rem, 2.2vw, 0.65rem);
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent-1);
  margin-bottom: 0.75rem;
  opacity: 0.8;
}

.site-header h1 {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.4rem, 5.5vw, 2.2rem);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.site-header h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent-1);
}

.site-header__sub {
  margin-top: 0.75rem;
  font-size: clamp(0.6rem, 2.5vw, 0.7rem);
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

/* ── CARD STAGE ─────────────────────────────────────────── */

.card-stage {
  perspective: 1200px;
  width: var(--card-w);
  height: var(--card-h);
  flex-shrink: 0;
  animation: card-rise 0.7s cubic-bezier(0.4, 0, 0.2, 1) 0.1s both;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
  cursor: pointer;
}

.card.is-flipped {
  transform: rotateY(180deg);
}

.card.is-transitioning {
  pointer-events: none;
}

.card__face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--card-r);
  border: 1px solid var(--border);
  overflow: hidden;
}

/* ── CARD BACK ──────────────────────────────────────────── */

.card__face--back {
  background-color: var(--surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
}

/* Subtle grid overlay */
.card__face--back::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 39px,
      rgba(255,255,255,0.012) 39px,
      rgba(255,255,255,0.012) 40px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 39px,
      rgba(255,255,255,0.012) 39px,
      rgba(255,255,255,0.012) 40px
    );
  pointer-events: none;
}

/* Slow scan-line shimmer */
.card__face--back::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    transparent 30%,
    rgba(200, 169, 110, 0.03) 50%,
    transparent 70%
  );
  background-size: 100% 300%;
  animation: scan 7s linear infinite;
  pointer-events: none;
}

.card-back-emblem {
  position: relative;
  z-index: 1;
}

.card-back-emblem svg {
  width: clamp(80px, 25vw, 120px);
  height: clamp(80px, 25vw, 120px);
}

.card-back-wordmark {
  position: relative;
  z-index: 1;
  text-align: center;
}

.card-back-wordmark p:first-child {
  font-size: clamp(0.5rem, 1.8vw, 0.6rem);
  letter-spacing: 0.3em;
  color: var(--accent-dim);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.card-back-wordmark p:last-child {
  font-family: 'Playfair Display', serif;
  font-size: clamp(0.85rem, 3vw, 1rem);
  font-style: italic;
  color: var(--accent-1);
  letter-spacing: 0.1em;
}

.card-back-hint {
  position: absolute;
  bottom: 1.25rem;
  left: 0;
  right: 0;
  text-align: center;
  font-size: clamp(0.48rem, 1.8vw, 0.55rem);
  letter-spacing: 0.2em;
  color: var(--text-faint);
  text-transform: uppercase;
  z-index: 1;
}

/* ── CARD FRONT ─────────────────────────────────────────── */

.card__face--front {
  transform: rotateY(180deg);
  background-color: var(--surface-2);
  display: flex;
  flex-direction: column;
  padding: clamp(18px, 5vw, 28px) clamp(16px, 5vw, 26px) clamp(14px, 4vw, 22px);
  gap: 0;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: clamp(12px, 3.5vw, 18px);
  flex-shrink: 0;
}

.patch-type {
  font-size: clamp(0.55rem, 2vw, 0.625rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  padding: 3px 8px;
  border-radius: 3px;
}

.patch-type.is-simulation {
  color: var(--accent-2);
  border-color: rgba(110, 142, 200, 0.25);
}

.patch-type.is-challenge {
  color: var(--accent-1);
  border-color: rgba(200, 169, 110, 0.25);
}

.difficulty {
  font-size: clamp(0.65rem, 2.2vw, 0.75rem);
  letter-spacing: 0.05em;
}

.diff-easy   { color: var(--diff-easy); }
.diff-medium { color: var(--diff-medium); }
.diff-hard   { color: var(--diff-hard); }

.card-title-block {
  margin-bottom: clamp(10px, 3vw, 14px);
  flex-shrink: 0;
}

.patch-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(1.15rem, 4.5vw, 1.55rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.patch-subtitle {
  font-size: clamp(0.625rem, 2.1vw, 0.6875rem);
  color: var(--text-muted);
  margin-top: 5px;
  letter-spacing: 0.08em;
  font-style: italic;
}

.card-divider {
  height: 1px;
  background: var(--border);
  margin: clamp(8px, 2.5vw, 12px) 0;
  flex-shrink: 0;
}

/* ── INSTRUCTIONS ───────────────────────────────────────── */

.patch-instructions {
  list-style: none;
  counter-reset: step;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1.5vw, 7px);
}

.patch-instructions li {
  counter-increment: step;
  font-size: clamp(0.65rem, 2.2vw, 0.6875rem);
  line-height: 1.55;
  color: var(--text-primary);
  padding-left: 1.6em;
  position: relative;
  opacity: 0.9;
}

.patch-instructions li::before {
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: 0;
  top: 0;
  font-size: 0.6rem;
  color: var(--accent-dim);
  font-weight: 500;
  line-height: 1.8;
}

/* ── CARD FOOTER ────────────────────────────────────────── */

.card-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: clamp(5px, 1.5vw, 8px);
}

.modules-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.modules-label {
  font-size: clamp(0.5rem, 1.7vw, 0.5625rem);
  letter-spacing: 0.2em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.modules-list {
  font-size: clamp(0.6rem, 2vw, 0.6875rem);
  color: var(--text-muted);
  line-height: 1.5;
  word-break: break-word;
}

.card-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.patch-tag {
  font-size: clamp(0.575rem, 2vw, 0.625rem);
  color: var(--text-faint);
  font-style: italic;
  letter-spacing: 0.05em;
}

.assigned-person {
  font-size: clamp(0.625rem, 2.1vw, 0.6875rem);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 5px;
}

.assigned-person::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
  flex-shrink: 0;
}

/* ── TOOLTIP TERMS ──────────────────────────────────────── */

.term {
  border-bottom: 1px dashed var(--accent-dim);
  cursor: help;
  color: inherit;
  white-space: nowrap;
}

#tooltip {
  position: fixed;
  z-index: 9999;
  max-width: min(260px, 80vw);
  background: var(--surface-3);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 8px 11px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

#tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

#tooltip strong {
  display: block;
  font-size: 0.6rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-1);
  margin-bottom: 4px;
}

#tooltip p {
  font-size: 0.65rem;
  line-height: 1.5;
  color: var(--text-primary);
  opacity: 0.9;
}

/* ── CONTROLS ───────────────────────────────────────────── */

.controls {
  margin-top: 1.75rem;
  display: flex;
  gap: 0.75rem;
  align-items: center;
  animation: fade-in 0.8s ease 0.3s both;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(0.65rem, 2.5vw, 0.7rem);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
  /* minimum touch target size (WCAG / Apple HIG) */
  min-height: 44px;
  min-width: 44px;
}

.btn:active {
  transform: translateY(1px) !important;
}

.btn-randomize {
  background: var(--accent-1);
  color: #0a0a0a;
  padding: 12px 28px;
  font-weight: 500;
}

@media (hover: hover) {
  .btn-randomize:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(200, 169, 110, 0.3);
  }
}

.btn-randomize:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-flip {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-light);
  padding: 11px 20px;
}

@media (hover: hover) {
  .btn-flip:hover {
    transform: translateY(-2px);
    color: var(--text-primary);
    border-color: var(--text-muted);
  }
}

.btn-flip.is-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ── DRAW COUNTER ───────────────────────────────────────── */

.draw-counter {
  margin-top: 1rem;
  font-size: clamp(0.52rem, 1.8vw, 0.58rem);
  letter-spacing: 0.18em;
  color: var(--text-faint);
  text-transform: uppercase;
  animation: fade-in 0.8s ease 0.4s both;
  min-height: 1.2em;
  text-align: center;
}

/* ── LEGEND ─────────────────────────────────────────────── */

.legend {
  margin-top: 2rem;
  display: flex;
  gap: 1.5rem;
  animation: fade-in 0.8s ease 0.5s both;
  flex-wrap: wrap;
  justify-content: center;
}

.legend-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.legend-label {
  font-size: clamp(0.46rem, 1.6vw, 0.52rem);
  letter-spacing: 0.2em;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.legend-items {
  display: flex;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.legend-item {
  font-size: clamp(0.55rem, 1.8vw, 0.6rem);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── FOOTER ─────────────────────────────────────────────── */

.site-footer {
  margin-top: 2.5rem;
  text-align: center;
  animation: fade-in 0.8s ease 0.6s both;
}

.site-footer p {
  font-size: clamp(0.52rem, 1.8vw, 0.58rem);
  color: var(--text-faint);
  letter-spacing: 0.1em;
  line-height: 1.8;
}

.site-footer a {
  color: var(--accent-dim);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.site-footer a:hover,
.site-footer a:focus {
  color: var(--accent-1);
  border-bottom-color: var(--accent-dim);
  outline: none;
}

/* ── ANIMATIONS ─────────────────────────────────────────── */

@keyframes card-rise {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes scan {
  0%   { background-position: 0 -100%; }
  100% { background-position: 0 200%; }
}

/* ── LANGUAGE SWITCHER ──────────────────────────────────── */

.lang-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.lang-btn {
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(0.5rem, 1.8vw, 0.56rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  border-radius: 3px;
  padding: 4px 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  min-height: 28px;
}

.lang-btn.is-active {
  background: var(--surface-3);
  border-color: var(--border-light);
  color: var(--accent-1);
}

@media (hover: hover) {
  .lang-btn:not(.is-active):hover {
    color: var(--text-muted);
    border-color: var(--border-light);
  }
}

.lang-divider {
  color: var(--text-faint);
  font-size: 0.55rem;
  opacity: 0.5;
  user-select: none;
}

/* ── MOBILE STICKY CONTROLS ─────────────────────────────── */

@media (max-width: 600px) {
  /* Push page content up so it isn't hidden under the fixed bar */
  body {
    padding-bottom: max(6rem, env(safe-area-inset-bottom, 0px) + 5.5rem);
  }

  .controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.65rem 1.25rem max(0.75rem, env(safe-area-inset-bottom, 0px));
    background: linear-gradient(
      to top,
      rgba(10, 10, 15, 0.98) 0%,
      rgba(10, 10, 15, 0.96) 75%,
      rgba(10, 10, 15, 0) 100%
    );
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
    z-index: 200;
    justify-content: center;
    gap: 0.65rem;
    animation: none; /* prevent entrance animation glitch when fixed */
    flex-wrap: nowrap;
  }

  /* Make buttons fill more width on mobile for easy tapping */
  .btn-randomize {
    flex: 1;
    max-width: 220px;
  }

  .btn-flip:not(.is-hidden) {
    flex-shrink: 0;
  }
}

/* ── NARROW MOBILE ──────────────────────────────────────── */

@media (max-width: 380px) {
  .site-header {
    margin-bottom: 1.75rem;
  }

  .legend {
    gap: 1rem;
  }
}

/* ── REDUCED MOTION ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .card-stage { animation: none; }
  .site-header,
  .controls,
  .draw-counter,
  .legend,
  .site-footer { animation: none; opacity: 1; }
  .card__face--back::after { animation: none; }
}
