:root{
  --bg:#050509;
  --panel:#0b0b12;
  --panel2:#10101a;
  --border:#24243a;
  --text:#f5f5f7;
  --muted:#b0b0c3;
  --orange:#ff6a00;
  --cyan:#38d6ff;
  --red:#ff3b6b;
  --radius:18px;
  --shadow: 0 22px 60px rgba(0,0,0,.55);
}

.crdf-wrap{
  background: linear-gradient(180deg, var(--bg), #070712);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow:hidden;
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.crdf-header{
  display:flex;
  gap:18px;
  align-items:stretch;
  justify-content:space-between;
  padding:18px 18px 12px;
  border-bottom:1px solid var(--border);
  background: radial-gradient(900px 220px at 20% 0%, rgba(255,106,0,.14), transparent 60%),
              radial-gradient(700px 220px at 85% 0%, rgba(56,214,255,.10), transparent 55%);
}

.crdf-badge{
  display:inline-flex;
  align-items:center;
  padding:6px 10px;
  border:1px solid rgba(255,106,0,.35);
  border-radius:999px;
  color:var(--orange);
  letter-spacing:.12em;
  font-size:12px;
}

.crdf-title h2{ margin:8px 0 4px; font-size:20px; }
.crdf-sub{ margin:0; color:var(--muted); font-size:13px; max-width:540px; }

.crdf-player{
  margin:8px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.crdf-player strong{
  color: var(--orange);
  letter-spacing: .04em;
}

.crdf-hud{
  display:flex;
  gap:12px;
  min-width:320px;
  align-items:flex-end;
}

.crdf-kpi{
  flex:1;
  background: rgba(16,16,26,.7);
  border:1px solid rgba(36,36,58,.9);
  border-radius: 14px;
  padding:10px;
}

.crdf-kpi-label{ font-size:12px; color:var(--muted); margin-bottom:8px; }
.crdf-kpi-bar{
  height:10px;
  background: rgba(255,255,255,.06);
  border-radius:999px;
  overflow:hidden;
  border:1px solid rgba(255,255,255,.06);
}
.crdf-kpi-bar span{
  display:block;
  height:100%;
  width:70%;
  background: linear-gradient(90deg, var(--cyan), var(--orange));
  box-shadow: 0 0 18px rgba(56,214,255,.22);
  transition: width .25s ease;
}

.crdf-stage{
  position:relative;
  background: linear-gradient(180deg, #070712, #050509);
  border-bottom:1px solid var(--border);
}

.crdf-canvas{
  display:block;
  width:100%;
  height:auto;
  outline:none;
  pointer-events:auto;
}

.crdf-hintbar{
  display:flex;
  gap:14px;
  flex-wrap:wrap;
  padding:10px 14px;
  border-top:1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.35);
  color: var(--muted);
  font-size:12px;
}
.crdf-hintbar strong{ color: var(--text); }

.crdf-overlay{
  position:absolute;
  inset:0;
  display:grid;
  place-items:center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(6px);
  z-index: 9999;
  pointer-events: auto;
}

.crdf-overlay-card{
  width:min(720px, 92%);
  background: rgba(11,11,18,.92);
  border:1px solid rgba(255,255,255,.10);
  border-radius: 18px;
  padding:18px;
  box-shadow: var(--shadow);
}

.crdf-overlay-title{
  font-size:18px;
  margin-bottom:8px;
  color: var(--orange);
  letter-spacing:.02em;
}

.crdf-overlay-text{
  color: var(--text);
  opacity:.92;
  line-height:1.5;
  margin-bottom:14px;
  white-space: pre-wrap;
}

.crdf-btn{
  cursor:pointer;
  border:none;
  padding:10px 14px;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(255,106,0,.95), rgba(56,214,255,.65));
  color:#0b0b12;
  font-weight:800;
}

.crdf-panel{
  display:grid;
  grid-template-columns: 1.2fr 1.2fr .8fr;
  gap:14px;
  padding:14px 18px 18px;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
}

.crdf-scene-title{ font-size:16px; margin-bottom:8px; }
.crdf-scene-desc{ color:var(--muted); font-size:13px; line-height:1.5; }

.crdf-choices{
  display:flex;
  flex-direction:column;
  gap:10px;
}

.crdf-choice{
  text-align:left;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.crdf-choice:hover{
  transform: translateY(-1px);
  border-color: rgba(255,106,0,.35);
  box-shadow: 0 0 0 1px rgba(56,214,255,.08) inset;
}
.crdf-choice.is-active{
  border-color: rgba(56,214,255,.45);
  box-shadow: 0 0 22px rgba(56,214,255,.10);
}

.crdf-choice small{
  display:block;
  color: var(--muted);
  margin-top:4px;
  font-size:12px;
}

.crdf-fluffy{
  border-radius: 14px;
  border:1px solid rgba(56,214,255,.18);
  background: radial-gradient(420px 180px at 20% 0%, rgba(56,214,255,.12), transparent 55%),
              rgba(255,255,255,.03);
  padding:12px;
}
.crdf-fluffy-name{
  color: var(--cyan);
  font-weight:900;
  letter-spacing:.04em;
  margin-bottom:6px;
}
.crdf-fluffy-line{
  color: var(--text);
  opacity:.92;
  line-height:1.45;
  font-size:13px;
}
.crdf-fluffy-mini{
  margin-top:8px;
  color: var(--muted);
  font-size:12px;
  line-height:1.4;
}


/* Ensure the HTML 'hidden' attribute actually hides the overlay (theme CSS can override it) */
.crdf-overlay[hidden]{
  display:none !important;
  pointer-events:none !important;
}

/* Failure UI (Quick Buttons) */
.crdf-overlay-sub{
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.crdf-overlay-chain{
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius: 14px;
  border:1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.04);
  margin: 10px 0 12px;
}
.crdf-chain-node{
  font-weight: 800;
  color: var(--text);
  font-size: 13px;
}
.crdf-chain-line{
  flex:1;
  height:2px;
  background: linear-gradient(90deg, rgba(56,214,255,.55), rgba(255,106,0,.55));
  opacity:.6;
  border-radius:999px;
}

.crdf-overlay-prompt{
  margin-top: 8px;
  margin-bottom: 10px;
  color: var(--text);
  font-weight: 800;
  letter-spacing: .01em;
}

.crdf-fail-choices{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-bottom: 14px;
}

.crdf-fail-choice{
  text-align:left;
  padding:12px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
.crdf-fail-choice:hover{
  transform: translateY(-1px);
  border-color: rgba(255,106,0,.35);
}
.crdf-fail-choice.is-selected{
  border-color: rgba(255,106,0,.65);
  box-shadow: 0 0 28px rgba(255,106,0,.12);
  background: rgba(255,106,0,.08);
}

.crdf-btn[disabled]{
  opacity:.45;
  cursor:not-allowed;
  filter: grayscale(.15);
}

.crdf-btn-ghost{
  background: rgba(255,255,255,.06);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.12);
}
.crdf-btn-ghost:hover{
  border-color: rgba(56,214,255,.35);
}

/* Failure overlay: allow scrolling on smaller screens */
.crdf-overlay{
  align-items: start;
  padding: 20px 0;
}
.crdf-overlay-card{
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/* Make quick choices more visible */
.crdf-fail-choice{
  font-weight: 800;
}

/* v1.4.6 overlay scroll hardening */
.crdf-overlay{ align-items:start !important; padding:18px 0 !important; }
.crdf-overlay-card{ max-height:85vh !important; overflow-y:auto !important; -webkit-overflow-scrolling:touch; }

/* v1.4.13: Make failure overlay truly viewport-fixed and scrollable on all desktops.
   This avoids theme/page containers swallowing wheel events or clipping the overlay. */
.crdf-overlay{
  position: fixed !important;
  inset: 0 !important;
  z-index: 99999 !important;
  display: flex !important;
  justify-content: center !important;
  align-items: flex-start !important;
  padding: 22px 0 !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  pointer-events: auto !important;
}
.crdf-overlay[hidden]{ display:none !important; }

.crdf-overlay-card{
  width: min(980px, calc(100vw - 28px)) !important;
  max-height: none !important; /* overlay scrolls, not the card */
  overflow: visible !important;
  margin: 0 auto !important;
}

/* Keep action buttons always reachable */
.crdf-overlay-actions{
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(5,5,9,.92) 40%, rgba(5,5,9,.98) 100%);
  padding-top: 10px;
  padding-bottom: 10px;
}

/* Visible scrollbar on Chromium/Edge (optional) */
.crdf-overlay::-webkit-scrollbar{ width: 12px; }
.crdf-overlay::-webkit-scrollbar-thumb{
  background: rgba(255,255,255,.18);
  border-radius: 999px;
  border: 3px solid rgba(0,0,0,0);
  background-clip: padding-box;
}
.crdf-overlay::-webkit-scrollbar-track{
  background: rgba(255,255,255,.05);
  border-radius: 999px;
}

/* v1.4.16 – overlay window sizing:
   Default smaller (better on 1920px laptops), larger only on very wide desktops */
.crdf-overlay-card{
  width: min(760px, calc(100vw - 32px)) !important;
}
@media (min-width: 2200px){
  .crdf-overlay-card{
    width: min(980px, calc(100vw - 32px)) !important;
  }
}
