/* =========================================================
   Coin Flip — tool-specific styles.
   Layered on /tools/_shared/tool.css. Only widget-body styles
   live here; all colors reference shared tokens so the
   dark/light theme switch keeps working.
   ========================================================= */

/* ---------- Local coin tokens ---------- */
.cf-card {
  --coin-face:   #E9B949;   /* warm gold coin */
  --coin-edge:   #B8860B;
  --coin-ink:    #6B4E09;
  --coin-shine:  #F7DE9A;
  --coin-size:   clamp(150px, 44vw, 220px);
  --cf-spin:     5.4s;   /* flip duration; overridden inline by the slider */
}
:root[data-theme="dark"] .cf-card {
  --coin-face:  #D9A93C;
  --coin-edge:  #8A6408;
  --coin-ink:   #3C2C05;
  --coin-shine: #EFC96E;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .cf-card {
    --coin-face:  #D9A93C;
    --coin-edge:  #8A6408;
    --coin-ink:   #3C2C05;
    --coin-shine: #EFC96E;
  }
}

/* ---------- Stage ---------- */
.cf-stage {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(var(--coin-size) + var(--space-6));
  margin-bottom: var(--space-4);
  perspective: 1000px;
}

/* ---------- Coin ---------- */
.cf-coin {
  width: var(--coin-size);
  height: var(--coin-size);
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  transform-style: preserve-3d;
  -webkit-tap-highlight-color: transparent;
}
.cf-coin:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 6px;
}
.cf-coin-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.05s linear;
}

/* The two faces sit back-to-back. Heads faces front, tails is
   pre-rotated 180deg so it shows when the coin is flipped over. */
.cf-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background:
    radial-gradient(circle at 34% 30%, var(--coin-shine), var(--coin-face) 52%, var(--coin-edge) 100%);
  border: 6px solid var(--coin-edge);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28), inset 0 0 0 4px rgba(255, 255, 255, 0.18);
  color: var(--coin-ink);
}
.cf-face-tails { transform: rotateY(180deg); }
.cf-face-mark {
  font-size: clamp(56px, 18vw, 92px);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}
.cf-face-label {
  font-size: clamp(11px, 3vw, 15px);
  font-weight: 700;
  letter-spacing: 0.22em;
  opacity: 0.75;
}

/* Resting orientation is driven by data-face; JS adds spin turns. */
.cf-coin[data-face="tails"] .cf-coin-inner { transform: rotateY(180deg); }

/* Spinning state: fast rotation while landing is computed in JS via
   inline transform. This class just lengthens/eases the settle. */
.cf-coin.is-flipping .cf-coin-inner {
  /* easeOutQuad — decelerates smoothly and keeps visibly moving until it
     stops, rather than reaching the end value early and creeping (which
     read as a frozen coin with a delayed result). The result is revealed
     on transitionend, so it lands exactly when the coin comes to rest. */
  transition: transform var(--cf-spin, 5.4s) cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ---------- Result line ---------- */
.cf-result {
  text-align: center;
  font-size: clamp(20px, 5vw, 28px);
  font-weight: 700;
  color: var(--text);
  min-height: 1.4em;
  margin: 0 0 var(--space-5);
}
.cf-result.is-heads { color: var(--accent); }
.cf-result.is-tails { color: var(--accent); }

/* ---------- Actions ---------- */
.cf-actions {
  margin-bottom: var(--space-4);
}

/* ---------- Meta row (fullscreen + sound) ---------- */
.cf-meta {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}
.cf-meta-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition-colors);
}
.cf-meta-btn:hover { color: var(--text); border-color: var(--accent); }
.cf-meta-icon { width: 16px; height: 16px; flex-shrink: 0; }

/* Sound icon toggles with the muted state. */
.cf-sound-off { display: none; }
.cf-meta-btn.is-muted { color: var(--text-subtle); }
.cf-meta-btn.is-muted .cf-sound-on { display: none; }
.cf-meta-btn.is-muted .cf-sound-off { display: inline; }

/* ---------- Spin-length control ---------- */
.cf-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: var(--space-6);
}
.cf-settings-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.cf-spin-val {
  color: var(--accent);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.cf-settings input[type="range"] { width: 100%; }

/* ---------- Stats ---------- */
.cf-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.cf-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.cf-stat-num {
  font-size: clamp(20px, 5vw, 26px);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.cf-stat-lab {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* ---------- History + reset ---------- */
.cf-history-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.cf-history {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-height: 26px;
}
.cf-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.cf-chip[data-face="heads"] {
  background: var(--accent-soft-bg);
  color: var(--accent-soft-fg);
  border-color: transparent;
}
.cf-reset {
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  transition: var(--transition-colors);
}
.cf-reset:hover { color: var(--text); border-color: var(--accent); }

/* The flip spin is user-initiated and central to the tool, so it plays at
   full length regardless of prefers-reduced-motion (owner decision). */

/* ---------- Full-screen mode ---------- */
.cf-card:fullscreen {
  --coin-size: min(58vh, 58vw);
  padding: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5vh, 56px);
  border: none;
  border-radius: 0;
  background: var(--surface);
}
.cf-card:fullscreen .widget-header,
.cf-card:fullscreen .cf-settings,
.cf-card:fullscreen .cf-stats,
.cf-card:fullscreen .cf-history-row {
  display: none;
}
.cf-card:fullscreen .cf-stage {
  min-height: auto;
  margin: 0;
}
.cf-card:fullscreen .cf-result {
  font-size: clamp(44px, 10vw, 132px);
  margin: 0;
}
/* Scale the H/T mark and label to the much larger full-screen coin. */
.cf-card:fullscreen .cf-face-mark {
  font-size: clamp(120px, 30vh, 320px);
}
.cf-card:fullscreen .cf-face-label {
  font-size: clamp(18px, 4.5vh, 44px);
}
.cf-card:fullscreen .cf-actions {
  width: min(360px, 60vw);
  margin: 0;
}
.cf-card:fullscreen .cf-meta {
  margin: 0;
}
