/* ==========================================================================
   Godmode :: The Gate
   Landing-page puzzle gate. Adversarial DOM, time + score, leaderboard.
   ========================================================================== */

#godmode-gate {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #000;
  color: #00ff41;
  font-family: "JetBrains Mono", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  animation: gate-fade-in 0.5s ease-out;
}

#godmode-gate.fading {
  opacity: 0;
  transition: opacity 0.8s ease-out;
}

#godmode-gate.granting .gate-frame {
  animation: gate-glitch 1.2s steps(8) forwards;
}

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

@keyframes gate-glitch {
  0%   { transform: translate(0,0); filter: hue-rotate(0deg); }
  20%  { transform: translate(-3px, 2px); filter: hue-rotate(45deg); }
  40%  { transform: translate(2px, -2px); filter: hue-rotate(-30deg); }
  60%  { transform: translate(-1px, 1px); filter: hue-rotate(60deg); }
  80%  { transform: translate(1px, 0); filter: hue-rotate(-15deg); }
  100% { transform: translate(0,0); filter: none; }
}

.gate-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(0, 255, 65, 0.08), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(0, 255, 65, 0.05), transparent 40%),
    repeating-linear-gradient(0deg, transparent 0, transparent 2px, rgba(0,255,65,0.025) 2px, rgba(0,255,65,0.025) 3px);
  pointer-events: none;
}

.gate-frame {
  position: relative;
  width: min(900px, 100%);
  border: 1px solid #0f3a0f;
  background: rgba(3, 8, 3, 0.95);
  padding: 32px;
  box-shadow:
    0 0 0 1px rgba(0,255,65,0.15) inset,
    0 0 60px rgba(0,255,65,0.15);
}

.gate-frame::before,
.gate-frame::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #00ff41;
}
.gate-frame::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.gate-frame::after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.gate-header { text-align: center; margin-bottom: 24px; }

.gate-tag {
  font-size: 11px;
  letter-spacing: 0.4em;
  color: #00cc33;
  margin-bottom: 12px;
}

.gate-title {
  font-size: clamp(28px, 5vw, 48px);
  font-weight: 800;
  letter-spacing: 0.05em;
  margin: 0 0 8px;
  color: #00ff41;
  text-shadow: 0 0 20px rgba(0,255,65,0.4);
}

.gate-sub {
  font-size: 14px;
  color: #00aa2a;
  margin: 0;
}

.gate-puzzle {
  margin: 24px 0;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.gate-status {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 12px;
  border-top: 1px solid #0f3a0f;
  border-bottom: 1px solid #0f3a0f;
  padding: 12px 0;
  margin: 16px 0;
}
.gate-stat .lab { color: #065a20; margin-right: 6px; }
.gate-stat span:not(.lab) { color: #00ff41; font-weight: 600; }

.gate-footer {
  display: flex;
  gap: 24px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 11px;
  margin-top: 16px;
}
.gate-footer a {
  color: #065a20;
  text-decoration: none;
  border-bottom: 1px dotted #064016;
  transition: color 0.15s;
}
.gate-footer a:hover { color: #00ff41; border-bottom-color: #00ff41; }

/* ====================== puzzle 1: the real door ====================== */
.door-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 520px;
}
@media (max-width: 520px) {
  .door-grid { grid-template-columns: repeat(3, 1fr); }
}
.door-btn {
  background: rgba(0,255,65,0.04);
  border: 1px solid #0f3a0f;
  color: #00aa2a;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 18px 8px;
  cursor: pointer;
  transition: all 0.12s;
  letter-spacing: 0.05em;
}
.door-btn:hover {
  background: rgba(0,255,65,0.10);
  color: #00ff41;
  border-color: #00ff41;
  box-shadow: 0 0 16px rgba(0,255,65,0.3);
}
.door-btn.door-fail {
  background: rgba(255, 51, 51, 0.2);
  border-color: #ff3333;
  color: #ff6666;
  animation: gate-shake 0.3s;
}

@keyframes gate-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* ====================== puzzle 2: the sigil ====================== */
.sigil-display {
  font-size: 64px;
  letter-spacing: 0.1em;
  color: #00ff41;
  text-shadow: 0 0 30px rgba(0,255,65,0.6);
  margin-bottom: 16px;
  display: flex;
  gap: 8px;
}
.sigil-glyph {
  display: inline-block;
  animation: sigil-pulse 1.4s ease-in-out infinite;
}
.sigil-glyph:nth-child(2n) { animation-delay: 0.2s; }
.sigil-glyph:nth-child(3n) { animation-delay: 0.4s; }

@keyframes sigil-pulse {
  0%, 100% { opacity: 0.6; transform: translateY(0); }
  50%      { opacity: 1; transform: translateY(-2px); }
}

.sigil-hint {
  font-size: 12px;
  color: #065a20;
  margin: 8px 0 16px;
  text-align: center;
  max-width: 480px;
}

.sigil-source {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.sigil-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.sigil-form input,
.gate-modal input {
  background: #000;
  border: 1px solid #0f3a0f;
  color: #00ff41;
  font-family: inherit;
  font-size: 16px;
  padding: 12px 16px;
  outline: none;
  width: 220px;
  text-align: center;
  letter-spacing: 0.1em;
}
.sigil-form input:focus,
.gate-modal input:focus {
  border-color: #00ff41;
  box-shadow: 0 0 12px rgba(0,255,65,0.3);
}
.sigil-fail {
  border-color: #ff3333 !important;
  animation: gate-shake 0.3s;
}

.sigil-form button,
.gate-modal button {
  background: #00ff41;
  color: #000;
  border: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 12px 20px;
  cursor: pointer;
  letter-spacing: 0.1em;
  transition: all 0.12s;
}
.sigil-form button:hover,
.gate-modal button:hover {
  background: #66ff85;
  box-shadow: 0 0 20px rgba(0,255,65,0.5);
}
.gate-modal button#skip-submit,
.gate-modal button#pass-cancel {
  background: transparent;
  color: #065a20;
  border: 1px solid #0f3a0f;
}
.gate-modal button#skip-submit:hover,
.gate-modal button#pass-cancel:hover {
  color: #00ff41;
  border-color: #00ff41;
  box-shadow: none;
}

/* ====================== puzzle 3: the vault ====================== */
.vault-source {
  background: #000;
  border: 1px solid #0f3a0f;
  padding: 16px;
  width: 100%;
  max-width: 640px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.vault-source pre {
  margin: 0;
  font-size: 11px;
  color: #00aa2a;
  font-family: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}
.vault-hint {
  font-size: 12px;
  color: #065a20;
  margin: 6px 0;
  text-align: center;
}
.vault-hint-cmd {
  font-family: inherit;
  font-size: 13px;
  background: rgba(0,255,65,0.05);
  border: 1px dashed #0f3a0f;
  padding: 8px 14px;
  color: #00ff41;
  margin: 4px 0 12px;
}
.vault-state {
  font-size: 12px;
  color: #00aa2a;
  margin-top: 8px;
  text-align: center;
}
.vault-state code { color: #00ff41; }

/* ====================== modals (submit / leaderboard / pass) ====================== */
.gate-modal {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: gate-fade-in 0.25s ease-out;
}
.gate-modal-card {
  background: rgba(3,8,3,0.98);
  border: 1px solid #00ff41;
  box-shadow: 0 0 40px rgba(0,255,65,0.4);
  padding: 32px;
  max-width: 560px;
  width: 100%;
  text-align: center;
}
.gate-modal-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  color: #00ff41;
  letter-spacing: 0.05em;
}
.gate-modal-card p {
  font-size: 13px;
  color: #00aa2a;
  margin: 4px 0 16px;
}
.gate-modal-card .modal-sub {
  font-size: 12px;
  color: #065a20;
  margin: 12px 0 16px;
}
.gate-modal form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.gate-modal input { width: 100%; max-width: 320px; }
.gate-modal form > button { width: 100%; max-width: 320px; }
.gate-modal .submit-error {
  width: 100%; max-width: 320px;
  background: rgba(255, 60, 60, 0.08);
  border: 1px solid #c33;
  color: #ff6a6a;
  padding: 8px 10px;
  font-size: 11px;
  line-height: 1.35;
  text-align: left;
}

/* ====================== leaderboard ====================== */
.leaderboard {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin: 16px 0;
}
.leaderboard th,
.leaderboard td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #0f3a0f;
}
.leaderboard th {
  color: #065a20;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 10px;
}
.leaderboard td { color: #00aa2a; }
.leaderboard tr.mine td {
  color: #00ff41;
  background: rgba(0,255,65,0.08);
  font-weight: 700;
}
.leaderboard tr:hover td {
  background: rgba(0,255,65,0.04);
}

/* ====================== mobile screen ====================== */
.gate-mobile .gate-title {
  font-size: clamp(20px, 6vw, 28px);
  letter-spacing: 0.04em;
}
.gate-mobile .gate-sub {
  font-size: 13px;
  max-width: 480px;
  margin: 0 auto;
}
.gate-mobile-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 24px 0 16px;
}
.gate-mobile-btn {
  display: block;
  background: rgba(0,255,65,0.04);
  border: 1px solid #0f3a0f;
  color: #00aa2a;
  font-family: inherit;
  text-decoration: none;
  text-align: center;
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}
.gate-mobile-btn .m-btn-label {
  display: block;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.gate-mobile-btn .m-btn-sub {
  display: block;
  font-size: 11px;
  color: #065a20;
  letter-spacing: 0.04em;
  line-height: 1.4;
}
.gate-mobile-btn:hover,
.gate-mobile-btn:active {
  background: rgba(0,255,65,0.10);
  color: #00ff41;
  border-color: #00ff41;
  box-shadow: 0 0 16px rgba(0,255,65,0.25);
}
.gate-mobile-btn.primary {
  background: rgba(0,255,65,0.08);
  border-color: #00aa2a;
  color: #00ff41;
}
.gate-mobile-btn.primary:hover,
.gate-mobile-btn.primary:active {
  background: rgba(0,255,65,0.16);
  box-shadow: 0 0 24px rgba(0,255,65,0.35);
}
#gate-mobile-desktop {
  font-size: 11px;
}

/* ====================== share row ====================== */
.gate-share {
  margin: 16px 0 12px;
  border-top: 1px dashed #0f3a0f;
  padding-top: 12px;
}
.gate-share-pre {
  margin: 8px 0 4px;
  padding-top: 10px;
  text-align: center;
}
.gate-share-label {
  display: block;
  font-size: 10px;
  color: #065a20;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.gate-share-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.gate-share-btn {
  background: transparent !important;
  color: #00aa2a !important;
  border: 1px solid #0f3a0f !important;
  font-family: inherit;
  padding: 8px !important;
  cursor: pointer;
  transition: all 0.12s;
  width: 38px !important;
  height: 38px !important;
  max-width: none !important;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.gate-share-icon {
  width: 18px;
  height: 18px;
  display: block;
  pointer-events: none;
}
.gate-share-btn:hover {
  background: rgba(0,255,65,0.06) !important;
  color: #00ff41 !important;
  border-color: #00ff41 !important;
  box-shadow: 0 0 12px rgba(0,255,65,0.2) !important;
}
.gate-share-btn-ok {
  color: #00ff41 !important;
  border-color: #00ff41 !important;
  background: rgba(0,255,65,0.08) !important;
}

/* ====================== mobile fit (no scroll, no top-cut) ====================== */
@media (max-width: 768px) {
  /* align-items: center on a scrollable flex container clips the top of
     overflowing content. Anchor to start so users can always reach the top. */
  #godmode-gate {
    align-items: flex-start;
    padding: 10px;
  }
  /* Use dynamic viewport unit so the iOS Safari URL bar doesn't hide content */
  #godmode-gate .gate-frame.gate-mobile {
    padding: 14px 14px 10px;
    width: 100%;
    min-height: calc(100dvh - 20px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .gate-mobile .gate-header { margin-bottom: 0; }
  .gate-mobile .gate-tag {
    font-size: 9px;
    letter-spacing: 0.3em;
    margin-bottom: 6px;
  }
  .gate-mobile .gate-title {
    font-size: clamp(18px, 5.6vw, 22px);
    margin: 0 0 4px;
  }
  .gate-mobile .gate-sub { font-size: 12px; line-height: 1.35; }

  .gate-mobile .gate-mobile-actions {
    margin: 0;
    gap: 8px;
    flex: 1;
    justify-content: center;
  }
  .gate-mobile .gate-mobile-btn { padding: 12px 12px; }
  .gate-mobile .gate-mobile-btn .m-btn-label {
    font-size: 13px;
    margin-bottom: 3px;
  }
  .gate-mobile .gate-mobile-btn .m-btn-sub {
    font-size: 10px;
    line-height: 1.3;
  }

  .gate-mobile .gate-share-pre {
    margin: 0;
    padding-top: 8px;
  }
  .gate-mobile .gate-share-label {
    font-size: 9px;
    margin-bottom: 6px;
  }
  .gate-mobile .gate-share-row { gap: 6px; }
  .gate-mobile .gate-share-btn {
    width: 34px !important;
    height: 34px !important;
    padding: 6px !important;
  }
  .gate-mobile .gate-share-icon { width: 16px; height: 16px; }

  .gate-mobile .gate-footer {
    margin-top: 0;
    font-size: 10px;
  }
  .gate-mobile #gate-mobile-desktop { font-size: 10px; }

  /* Corner brackets shrink so they don't crowd a tight frame */
  #godmode-gate .gate-frame.gate-mobile::before,
  #godmode-gate .gate-frame.gate-mobile::after {
    width: 12px;
    height: 12px;
  }
}

/* ====================== entry granted ====================== */
.entry-grant {
  font-size: clamp(32px, 6vw, 64px);
  font-weight: 800;
  letter-spacing: 0.15em;
  color: #00ff41;
  text-shadow: 0 0 30px rgba(0,255,65,0.8), 0 0 60px rgba(0,255,65,0.4);
  text-align: center;
  padding: 80px 24px;
  animation: grant-pulse 0.5s ease-out;
}

@keyframes grant-pulse {
  0%   { transform: scale(0.8); opacity: 0; }
  50%  { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Embedded mode — homepage section, not fullscreen overlay.
   Reuses every .gate-frame inner style (header, status, puzzles, share, etc.)
   but drops fixed positioning so the gate sits inline. Modals are scoped to
   the host via .gate-modal-layer instead of the page.
   ========================================================================== */
.gate-frame.gate-embedded {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  color: #00ff41;
  font-family: "JetBrains Mono", monospace;
  background: rgba(3, 8, 3, 0.95);
  border: 1px solid #0f3a0f;
  padding: 32px;
  box-shadow:
    0 0 0 1px rgba(0,255,65,0.15) inset,
    0 0 60px rgba(0,255,65,0.15);
  box-sizing: border-box;
}

.gate-frame.gate-embedded::before,
.gate-frame.gate-embedded::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid #00ff41;
}
.gate-frame.gate-embedded::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.gate-frame.gate-embedded::after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

@media (max-width: 768px) {
  .gate-frame.gate-embedded { padding: 18px 14px; }
}

.gate-modal-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  z-index: 5;
  padding: 16px;
}
.gate-modal-layer:empty { display: none; }

.gate-frame.gate-embedded .gate-modal {
  position: relative;
  inset: auto;
  background: transparent;
  padding: 0;
  max-height: 100%;
  overflow-y: auto;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gate-modal-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.gate-modal-actions a {
  color: #065a20;
  text-decoration: none;
  border-bottom: 1px dotted #064016;
  font-size: 11px;
  letter-spacing: 0.05em;
}
.gate-modal-actions a:hover { color: #00ff41; border-bottom-color: #00ff41; }

.modal-hint {
  font-size: 11px;
  color: #065a20;
  margin: 4px 0 12px;
  text-align: center;
}

/* Door fail-shake animation hook used by gate.js door click handler. */
.door-btn.door-shake { animation: gate-shake 0.3s; }

/* The sigil shards row is decorative — gate.js exposes data-weight on each
   <span class="shard"> and sums them to derive the answer. */
.sigil-shards {
  font-size: 32px;
  letter-spacing: 0.2em;
  color: #00ff41;
  text-shadow: 0 0 18px rgba(0,255,65,0.5);
  margin-bottom: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}
.sigil-shards .shard {
  display: inline-block;
  animation: sigil-pulse 1.6s ease-in-out infinite;
}
.sigil-shards .shard:nth-child(2n) { animation-delay: 0.2s; }
.sigil-shards .shard:nth-child(3n) { animation-delay: 0.4s; }

.vault-line, .vault-hint {
  font-size: 12px;
  color: #065a20;
  text-align: center;
  margin: 6px 0;
}
.vault-line code, .vault-hint code {
  color: #00ff41;
  font-family: inherit;
}
