/* =========================================================
   Magic 8 Ball — tool-specific styles.
   Layered on /tools/_shared/tool.css. Tokens, fonts, base
   resets live in the shared sheet; only the widget body
   styles unique to this tool live here.
   ========================================================= */

/* ---------- Stage ---------- */
.m8-stage {
  display: flex;
  justify-content: center;
  padding: var(--space-2) 0 var(--space-6);
}

/* The ball itself is a button — kill default styling. */
.m8-ball {
  background: none;
  border: none;
  padding: 0;
  cursor: grab;
  display: inline-block;
  -webkit-tap-highlight-color: transparent;
  line-height: 0;
  touch-action: none;   /* let us drag on touch without scrolling the page */
  user-select: none;
  -webkit-user-select: none;
}
.m8-ball:focus { outline: none; }

/* ---------- Outer sphere ---------- */
.m8-ball-outer {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 28%,
      #5a5d63 0%,
      #2a2c32 30%,
      #0e1014 70%,
      #050608 100%);
  box-shadow:
    inset 0 -28px 60px rgba(0, 0, 0, 0.55),
    inset 0 22px 38px rgba(255, 255, 255, 0.04),
    0 24px 50px rgba(0, 0, 0, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, box-shadow 0.18s ease;
}
@media (min-width: 560px) {
  .m8-ball-outer { width: 300px; height: 300px; }
}

.m8-ball:hover .m8-ball-outer {
  transform: scale(1.02);
}
.m8-ball:active .m8-ball-outer {
  transform: scale(0.985);
}
.m8-ball:focus-visible .m8-ball-outer {
  box-shadow:
    inset 0 -28px 60px rgba(0, 0, 0, 0.55),
    inset 0 22px 38px rgba(255, 255, 255, 0.04),
    0 24px 50px rgba(0, 0, 0, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.25),
    0 0 0 4px var(--accent-ring);
}

/* Glossy highlight on the upper-left of the sphere. */
.m8-ball-shine {
  position: absolute;
  top: 8%;
  left: 16%;
  width: 38%;
  height: 28%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center,
    rgba(255, 255, 255, 0.5) 0%,
    rgba(255, 255, 255, 0.06) 65%,
    rgba(255, 255, 255, 0) 100%);
  filter: blur(2px);
  pointer-events: none;
}

/* ---------- The round answer window cut into the sphere ---------- */
.m8-window {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54%;
  height: 54%;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 65%,
      #14213f 0%,
      #0a1530 60%,
      #050a1c 100%);
  box-shadow:
    inset 0 0 22px rgba(0, 0, 0, 0.7),
    inset 0 6px 14px rgba(255, 255, 255, 0.06),
    inset 0 -4px 12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

/* ---------- The triangular die face floating in the window ---------- */
.m8-triangle {
  position: relative;
  width: 92%;
  height: 92%;
  clip-path: polygon(50% 4%, 96% 96%, 4% 96%);
  background: linear-gradient(180deg, #1c3a76 0%, #102756 55%, #0a1c3f 100%);
  opacity: 0;
  /* Fast out (when hidden); the slow fade-in is on .is-revealed below. */
  transition: opacity 0.18s ease, background 0.4s ease;
  will-change: opacity;
}
/* Slow fade-in driven by a keyframe animation (more reliable than a
   class-toggle opacity transition, which the browser can skip when the
   text + background change in the same tick). Tune --m8-fade to taste. */
.m8-triangle.is-revealed {
  opacity: 1;
  animation: m8-fade-in var(--m8-fade, 2.6s) ease forwards;
}

/* Sentiment tints — subtle, so readable on both themes. */
.m8-triangle.s-affirmative {
  background: linear-gradient(180deg, #1f5a48 0%, #103a2e 55%, #082720 100%);
}
.m8-triangle.s-neutral {
  background: linear-gradient(180deg, #6a4f1a 0%, #44320d 55%, #2a1f06 100%);
}
.m8-triangle.s-negative {
  background: linear-gradient(180deg, #6a2a30 0%, #44181d 55%, #2a0e12 100%);
}
.m8-triangle.s-custom {
  background: linear-gradient(180deg, #1c3a76 0%, #102756 55%, #0a1c3f 100%);
}

/* The answer is an overlay centered in the round window — it sits ABOVE
   the clipped triangle so long answers use the full width and aren't cut
   off by the triangle's slanted edges, and it's truly vertically centered. */
.m8-answer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 14%;
  color: #FAFAFA;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.2;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.18s ease;   /* fast out; slow-in is on .is-revealed below */
  pointer-events: none;
}
@media (min-width: 560px) {
  .m8-answer { font-size: 12.5px; }
}
/* Fade the answer in together with the die face — same keyframe + duration. */
.m8-triangle.is-revealed ~ .m8-answer {
  opacity: 1;
  animation: m8-fade-in var(--m8-fade, 2.6s) ease forwards;
}

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

/* ---------- Shake animation ---------- */
@keyframes m8-shake {
  0%   { transform: translate(0, 0) rotate(0); }
  10%  { transform: translate(-5px, -2px) rotate(-2deg); }
  20%  { transform: translate(5px,  2px) rotate(2deg); }
  30%  { transform: translate(-6px, 3px) rotate(-3deg); }
  45%  { transform: translate(6px, -3px) rotate(3deg); }
  60%  { transform: translate(-4px, -2px) rotate(-2deg); }
  75%  { transform: translate(4px,  3px) rotate(2deg); }
  88%  { transform: translate(-2px, 1px) rotate(-1deg); }
  100% { transform: translate(0, 0) rotate(0); }
}
.m8-ball.is-shaking .m8-ball-outer {
  animation: m8-shake 0.7s ease-in-out;
}

/* ---------- Drag-to-shake ---------- */
.m8-ball.is-dragging { cursor: grabbing; }
/* While held, the ball tracks the cursor instantly (no easing). */
.m8-ball.is-dragging .m8-ball-outer { transition: none; }
/* On release it springs back to center. */
.m8-ball.is-settling .m8-ball-outer {
  transition: transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Reduced motion: no shake, just a fade. The .m8-triangle opacity
   transition handles the in/out fade on its own. */
@media (prefers-reduced-motion: reduce) {
  .m8-ball.is-shaking .m8-ball-outer { animation: none; }
  .m8-ball-outer { transition: none; }
  .m8-triangle { transition: opacity 0.2s ease; }
  .m8-ball.is-settling .m8-ball-outer { transition: none; }
  .m8-answer { transition: opacity 0.2s ease; }
  /* Skip the slow fade animation; reveal quickly. */
  .m8-triangle.is-revealed,
  .m8-triangle.is-revealed ~ .m8-answer { animation: none; opacity: 1; }
}

/* ---------- Ask row (question + button) ---------- */
.m8-ask {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
@media (max-width: 480px) {
  .m8-ask { grid-template-columns: 1fr; }
}

.m8-ask input[type="text"] {
  min-height: 48px;
  padding: 0 var(--space-4);
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: var(--transition-colors);
}
.m8-ask input[type="text"]::placeholder {
  color: var(--text-subtle);
}
.m8-ask input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.m8-ask .btn-primary {
  min-width: 100px;
}

.m8-tip {
  margin: 0 0 var(--space-6);
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}
.m8-tip kbd {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  margin: 0 1px;
}

/* ---------- Mode toggle (Classic / Custom) ---------- */
.m8-mode {
  border-top: 1px solid var(--border);
  padding-top: var(--space-6);
  margin-top: var(--space-2);
}

.m8-mode-fieldset {
  border: none;
  padding: 0;
  margin: 0;
}
.m8-mode-fieldset legend {
  display: block;
  padding: 0;
  margin-bottom: var(--space-3);
}

.m8-mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.m8-mode-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-colors);
}
.m8-mode-option:hover { border-color: var(--border-strong); color: var(--text); }
.m8-mode-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft-bg);
  color: var(--accent-soft-fg);
  font-weight: 600;
}
.m8-mode-option:has(input:focus-visible) {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
}
/* Hide the radio visually; keep it accessible. */
.m8-mode-option input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Custom-answer textarea ---------- */
.m8-custom {
  margin-top: var(--space-5);
}
.m8-custom-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}
#custom-list {
  width: 100%;
  min-height: 140px;
  padding: var(--space-3) var(--space-4);
  font: inherit;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: vertical;
  transition: var(--transition-colors);
}
#custom-list::placeholder { color: var(--text-subtle); }
#custom-list:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.m8-custom-hint {
  margin: var(--space-3) 0 0;
  font-size: 13px;
  padding: var(--space-2) var(--space-3);
  background: var(--accent-soft-bg);
  border: 1px solid var(--accent);
  color: var(--accent-soft-fg);
  border-radius: var(--radius-sm);
}
.m8-custom-note {
  margin: var(--space-2) 0 0;
  font-size: 12px;
  color: var(--text-muted);
}
