/* ══════════════════════════════════════════════
   SHARED INSTRUCTION OVERLAY
   ══════════════════════════════════════════════
   Configurable CSS custom properties (set on :root or #instruction-overlay):
     --instr-overlay-bg     (default: rgba(140, 145, 175, 0.06))
     --instr-stage-bg       (default: rgba(10, 12, 28, 0.95))
     --instr-accent         (default: #fbbf24)
     --instr-accent-glow    (default: rgba(251, 191, 36, 0.5))
   ══════════════════════════════════════════════ */

/* ── Overlay ── */
#instruction-overlay {
  position: fixed;
  inset: 0;
  background: var(--instr-overlay-bg, rgba(140, 145, 175, 0.06));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

#instruction-overlay.show {
  opacity: 1;
  pointer-events: auto;
}

/* ── Stage (card) ── */
#instr-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: 92%;
  max-width: 700px;
  font-family: 'Inter', sans-serif;
  background: var(--instr-stage-bg, rgba(10, 12, 28, 0.95));
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.4),
              inset 0 0 0 0.5px rgba(255, 255, 255, 0.06);
  padding: 24px 48px;
}

/* ── Board ── */
#instr-board {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  overflow: visible;
}

/* ── Progress Dots ── */
#instr-dots {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 6px;
}

.instr-dot {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
}

.instr-dot:hover {
  border-color: rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.15);
  transform: scale(1.25);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.25);
}

.instr-dot.active {
  border-color: var(--instr-accent, #fbbf24);
  background: var(--instr-accent, #fbbf24);
  box-shadow: 0 0 8px var(--instr-accent-glow, rgba(251, 191, 36, 0.5));
}

/* ── Label ── */
#instr-label {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: clamp(1.5rem, 4.8vw, 2.1rem);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.88);
  text-align: center;
  width: 100%;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1.4em;
  letter-spacing: 0.01em;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.4);
  transition: opacity 0.35s ease, color 0.3s ease;
}

#instr-label.pos-left {
  text-align: left;
  padding-left: 8%;
}

#instr-label.pos-right {
  text-align: right;
  padding-right: 8%;
}

/* Goal / objective text */
#instr-label.gold {
  color: var(--instr-accent, #fbbf24);
  font-weight: 600;
  text-shadow: 0 0 18px var(--instr-accent-glow, rgba(251, 191, 36, 0.3));
}

/* Dual labels (e.g. Start / Goal) */
#instr-label.dual {
  display: flex;
  justify-content: space-between;
  padding: 0 8%;
  text-align: left;
}

.goal-span {
  color: var(--instr-accent, #fbbf24);
  font-weight: 600;
  text-shadow: 0 0 18px var(--instr-accent-glow, rgba(251, 191, 36, 0.3));
}

/* Warning / forbidden text */
#instr-label.warning {
  color: #ff6b6b;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Close (X) Button ── */
#instr-close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: clamp(32px, 4.5vw, 40px);
  height: clamp(32px, 4.5vw, 40px);
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 40;
  transition: background 0.2s, border-color 0.2s, color 0.2s,
              transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

#instr-close-btn svg {
  width: 48%;
  height: 48%;
}

#instr-close-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.08);
}

#instr-close-btn:active {
  transform: scale(0.88);
}

/* ── Nav Buttons (Back / Forward) ── */
.instr-nav-btn {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: clamp(34px, 5vw, 44px);
  height: clamp(34px, 5vw, 44px);
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, background 0.2s ease,
              border-color 0.2s ease, color 0.2s ease,
              transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  z-index: 35;
}

.instr-nav-btn svg {
  width: 50%;
  height: 50%;
}

.instr-nav-btn.show {
  opacity: 1;
  pointer-events: auto;
}

.instr-nav-btn:hover {
  background: rgba(255, 255, 255, 0.10);
  border-color: rgba(255, 255, 255, 0.20);
  color: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 20px rgba(255, 255, 255, 0.06);
}

.instr-nav-btn:active {
  transform: translateY(-50%) scale(0.88);
}

#instr-back-btn {
  left: 8px;
}

#instr-fwd-btn {
  right: 8px;
}

#instr-fwd-btn:hover {
  color: var(--instr-accent, #fbbf24);
  border-color: rgba(251, 191, 36, 0.3);
  box-shadow: 0 0 18px rgba(251, 191, 36, 0.12);
}

/* ── End Button (accent play, replaces forward arrow on final phase) ── */
#instr-end-btns {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
  z-index: 35;
}

#instr-end-btns.show {
  opacity: 1;
  pointer-events: auto;
}

#instr-go-btn {
  width: clamp(40px, 6vw, 50px);
  height: clamp(40px, 6vw, 50px);
  border-radius: 50%;
  border: 2px solid var(--instr-accent, #fbbf24);
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--instr-accent, #fbbf24) 22%, transparent),
    color-mix(in srgb, var(--instr-accent, #fbbf24) 10%, transparent));
  color: var(--instr-accent, #fbbf24);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 0 0 2px;
  box-shadow: 0 0 18px var(--instr-accent-glow, rgba(251, 191, 36, 0.3));
  transition: background 0.2s, border-color 0.2s,
              transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}

#instr-go-btn svg {
  width: 44%;
  height: 44%;
}

#instr-go-btn:hover {
  background: linear-gradient(145deg,
    color-mix(in srgb, var(--instr-accent, #fbbf24) 35%, transparent),
    color-mix(in srgb, var(--instr-accent, #fbbf24) 18%, transparent));
  box-shadow: 0 0 28px var(--instr-accent-glow, rgba(251, 191, 36, 0.5));
}

#instr-go-btn:active {
  transform: scale(0.88);
}

/* ── Hand Cursor ── */
#instr-cursor {
  position: absolute;
  width: clamp(18px, 4vw, 28px);
  height: auto;
  color: #ffffff;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5));
  transform: translateX(-30%) rotate(15deg);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: left 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
}

#instr-cursor img {
  width: 100%;
  height: auto;
  display: block;
}

@keyframes cursorTap {
  0%   { transform: translateX(-30%) rotate(15deg) scale(1) translateY(0); }
  35%  { transform: translateX(-30%) rotate(15deg) scale(0.92) translateY(15%); }
  60%  { transform: translateX(-30%) rotate(15deg) scale(1.04) translateY(-4%); }
  100% { transform: translateX(-30%) rotate(15deg) scale(1) translateY(0); }
}

#instr-cursor.tap {
  animation: cursorTap 0.3s ease-out;
}

/* ── Forbidden / Error Icon ── */
#instr-forbidden {
  position: absolute;
  transform: translate(-50%, 10%) scale(0);
  font-size: clamp(4rem, 12vw, 7rem);
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#instr-forbidden.show {
  opacity: 1;
  transform: translate(-50%, 10%) scale(1);
}

/* ── Frosty Interstitial (e.g. "How?" before a phase) ── */
#instr-frost {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: rgba(10, 12, 28, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#instr-frost.show {
  opacity: 1;
  pointer-events: auto;
}

#instr-frost-text {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: clamp(1.8rem, 5.5vw, 2.8rem);
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.15);
  letter-spacing: 0.02em;
  text-align: center;
}

/* ── Spring Rattle (invalid move shake) ── */
@keyframes springRattle {
  0%   { transform: translateX(-50%) rotate(0deg); }
  12%  { transform: translateX(calc(-50% + 10px)) rotate(3deg); }
  24%  { transform: translateX(calc(-50% - 8px)) rotate(-2.5deg); }
  36%  { transform: translateX(calc(-50% + 6px)) rotate(2deg); }
  48%  { transform: translateX(calc(-50% - 4px)) rotate(-1.2deg); }
  60%  { transform: translateX(calc(-50% + 2px)) rotate(0.5deg); }
  75%  { transform: translateX(calc(-50% - 1px)) rotate(-0.2deg); }
  100% { transform: translateX(-50%) rotate(0deg); }
}

.spring-rattle {
  animation: springRattle 0.45s cubic-bezier(0.36, 0.07, 0.19, 0.97);
  z-index: 10;
}
