/* ===========================================================================
   app.css — the WheelToss wheel application
   Loaded by the home page, the template pages, /embed/ and /streaming/.
   Mobile first: the stage comes first in the DOM and stays first until there is
   room for a two-column layout, so a phone never shows the editor above the
   wheel.
   =========================================================================== */

.wheel-app {
  display: grid;
  gap: 1.25rem;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 960px) {
  .wheel-app {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
    gap: 1.75rem;
  }
}

.wheel-app__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .9rem;
  min-width: 0;
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--wheel-stage, transparent);
  transition: background-color .2s ease;
}

.wheel-app__side {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.wheel-app__title {
  margin: 0;
  font-size: clamp(1.05rem, .9rem + .8vw, 1.4rem);
  text-align: center;
  overflow-wrap: anywhere;
}

/* --- the wheel itself ---------------------------------------------------- */

.wheel-app .wheel-frame {
  position: relative;
  width: 100%;
  max-width: min(560px, 82vw);
  aspect-ratio: 1 / 1;
  margin-inline: auto;
  touch-action: manipulation;
}

.wheel-app .wheel-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.wheel-app .wheel-pointer {
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 44px;
  z-index: 3;
  color: #111827;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .35));
  pointer-events: none;
}
.wheel-app .wheel-pointer svg { width: 100%; height: 100%; display: block; }

.wheel-app .wheel-hub {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 26%;
  max-width: 132px;
  aspect-ratio: 1;
  z-index: 2;
}

.wheel-hub__button {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 4px solid var(--surface);
  background: var(--wheel-hub, #ffffff);
  color: var(--wheel-hub-text, #1f2937);
  font: inherit;
  font-weight: 800;
  font-size: clamp(.7rem, .35rem + 1.5vw, 1.05rem);
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(17, 24, 39, .28);
  /* A quick settle when the pointer stops — the wheel's own bit of character. */
  transition: transform .18s cubic-bezier(.34, 1.56, .64, 1);
}
.wheel-hub__button:hover:not(:disabled) { transform: translateZ(0) scale(1.05); }
.wheel-hub__button:active:not(:disabled) { transform: scale(.96); }
.wheel-hub__button:disabled { opacity: .6; cursor: not-allowed; }

.wheel-hub__image { display: block; width: 100%; height: 100%; }
.wheel-hub__image[hidden] { display: none; }
.wheel-hub__image img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.wheel-hub__image + .wheel-hub__text { position: absolute; bottom: 8%; font-size: .6rem; }
.wheel-hub__text[hidden] { display: none; }

.wheel-empty {
  position: absolute;
  inset: 18%;
  display: grid;
  place-items: center;
  text-align: center;
  margin: 0;
  padding: 1rem;
  border-radius: 50%;
  color: var(--muted);
  font-size: .95rem;
  background: var(--surface);
  border: 2px dashed var(--border-strong);
}
.wheel-empty[hidden] { display: none; }

/* --- actions and result -------------------------------------------------- */

.wheel-app__actions {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
  width: 100%;
}
.wheel-app__spin { flex: 1 1 220px; max-width: 340px; }

.wheel-app__status {
  margin: 0;
  font-size: .88rem;
  color: var(--muted);
  text-align: center;
  min-height: 1.4em;
}

.result-badge {
  width: 100%;
  max-width: 560px;
  text-align: center;
  padding: .85rem 1rem;
  border: 2px solid var(--primary);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.result-badge.is-empty { border-style: dashed; border-color: var(--border-strong); }
.result-badge__label {
  display: block;
  font-size: .72rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--muted);
}
.result-badge__value {
  display: block;
  font-size: clamp(1.3rem, 1rem + 2.2vw, 2.1rem);
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.result-badge.is-empty .result-badge__value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}

/* --- result dialog ------------------------------------------------------- */

dialog.result-dialog {
  width: min(94vw, 460px);
  text-align: center;
  border: 0;
  border-top: 6px solid var(--primary);
}
.result-dialog__body { padding: 1.4rem 1.25rem 1.25rem; }
.result-dialog__message {
  margin: 0 0 .3rem;
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.result-dialog__value {
  margin: 0 0 .4rem;
  font-size: clamp(1.6rem, 1.1rem + 3vw, 2.6rem);
  font-weight: 800;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.result-dialog__meta { margin: 0 0 1rem; font-size: .85rem; color: var(--muted); }
.result-dialog__actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
  justify-content: center;
}

/* --- entries panel ------------------------------------------------------- */

.entries-panel__text { min-height: 200px; font-variant-numeric: tabular-nums; }
.entries-panel__example {
  margin: .35rem 0 0;
  font-size: .84rem;
  color: var(--muted);
}
.entries-panel__example[hidden] { display: none; }

.entries-panel__quick { display: flex; gap: .5rem; margin-top: .75rem; }
.entries-panel__quick input { flex: 1 1 auto; min-width: 0; }

.entries-panel__tools { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .75rem; }

.entries-panel__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .6rem;
  font-size: .84rem;
  color: var(--muted);
}
.entries-panel__summary { flex: 1 1 auto; }

.entries-panel__privacy {
  margin: .75rem 0 0;
  font-size: .82rem;
  color: var(--muted);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .45rem .6rem;
}

.entry-rows { list-style: none; padding: 0; margin: 0; max-height: 340px; overflow-y: auto; }
.entry-rows li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 4.5rem 3.2rem auto auto;
  align-items: center;
  gap: .4rem;
  margin: 0;
  padding: .3rem .1rem;
  border-bottom: 1px solid var(--border);
}
.entry-rows li:last-child { border-bottom: 0; }
.entry-rows input[type='checkbox'] { width: 20px; height: 20px; min-height: 20px; }
.entry-rows__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.entry-rows__label.is-off { opacity: .5; text-decoration: line-through; }
.entry-rows__weight { min-height: 34px; padding: .15rem .3rem; font-size: .85rem; }
.entry-rows__chance {
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.entry-rows input[type='color'] { width: 34px; height: 30px; min-height: 30px; }

/* --- settings panel ------------------------------------------------------ */

.settings-panel { display: flex; flex-direction: column; gap: 1rem; }
.settings-panel__label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.settings-panel__colors { display: flex; flex-wrap: wrap; gap: .9rem; margin: .5rem 0; }
.settings-panel__colors label {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  margin: 0;
  font-size: .85rem;
}
.settings-panel__thumb {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface-alt);
  display: inline-grid; place-items: center; overflow: hidden; flex: 0 0 auto;
}
.settings-panel__thumb img { width: 100%; height: 100%; object-fit: cover; }

/* --- saved wheels and share --------------------------------------------- */

.saved-wheels { list-style: none; padding: 0; margin: .75rem 0; }
.saved-wheels li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .4rem;
  margin: 0;
  padding: .45rem .1rem;
  border-bottom: 1px solid var(--border);
}
.saved-wheels li:last-child { border-bottom: 0; }
.saved-wheels__name { font-weight: 600; font-size: .9rem; flex: 1 1 8rem; min-width: 0; overflow-wrap: anywhere; }
.saved-wheels__count { font-size: .78rem; color: var(--muted); }
.saved-wheels__actions { display: flex; flex-wrap: wrap; gap: .25rem; }

.share-output { margin-top: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.share-output[hidden] { display: none; }
.share-output input { font-family: var(--font-mono); font-size: .8rem; }

/* --- multi-wheel grid ---------------------------------------------------- */

.wheel-grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.wheel-grid__toolbar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin-bottom: 1rem;
}
@media (min-width: 900px) {
  .wheel-grid[data-count='2'] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wheel-grid[data-count='3'] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .wheel-grid[data-count='4'] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.wheel-grid .wheel-app { grid-template-columns: minmax(0, 1fr); }
.wheel-grid .wheel-app__side { display: none; }
.wheel-grid .wheel-app.is-open .wheel-app__side { display: flex; }
.wheel-grid__cell {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: .85rem;
}
.wheel-grid__cell-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .5rem;
}

/* --- full screen, embed, streaming -------------------------------------- */

body.is-fullscreen .wheel-app { grid-template-columns: minmax(0, 1fr); }
body.is-fullscreen .wheel-app__side { display: none; }
body.is-fullscreen .wheel-app .wheel-frame { max-width: min(74vh, 92vw); }
body.is-fullscreen .wheel-legend { max-height: 84px; }

body.page-embed,
body.page-streaming { background: transparent; }
body.page-embed .wheel-app,
body.page-streaming .wheel-app { grid-template-columns: minmax(0, 1fr); }
body.page-streaming .wheel-app__status,
body.page-streaming .wheel-legend { display: none; }
body.page-streaming .result-badge {
  border-width: 0;
  background: transparent;
  box-shadow: none;
}
body.page-streaming .result-badge__value {
  font-size: clamp(2rem, 1.2rem + 5vw, 4.5rem);
  text-shadow: 0 2px 12px rgba(0, 0, 0, .55);
}
body.page-streaming .result-badge.is-empty { visibility: hidden; }

.embed-credit {
  display: block;
  text-align: center;
  font-size: .78rem;
  margin: .5rem 0 0;
}

/* --- shared bits used by the app pages ---------------------------------- */

.output-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  font-size: .85rem;
  min-height: 80px;
  overflow-wrap: anywhere;
}

.shortcut-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; }
.shortcut-list li { display: flex; gap: .6rem; align-items: baseline; margin: 0; font-size: .9rem; }
.shortcut-list kbd { flex: 0 0 4.5rem; text-align: center; }

/* --- randomness audit chart (no chart library) --------------------------- */

.audit-chart { display: grid; gap: .3rem; margin: 1rem 0; }
.audit-chart__row {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr) 9rem;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
}
.audit-chart__name { color: var(--muted); font-variant-numeric: tabular-nums; }
.audit-chart__track {
  position: relative;
  display: block;
  height: 1.1rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.audit-chart__bar { display: block; height: 100%; background: var(--primary); }
/* The expected count is marked as a line, so a bias shows as a gap rather than
   needing the reader to compare two numbers. */
.audit-chart__expected {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text);
  opacity: .75;
}
.audit-chart__value { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

@media (max-width: 520px) {
  .audit-chart__row { grid-template-columns: 4rem minmax(0, 1fr); }
  .audit-chart__value { grid-column: 1 / -1; text-align: left; }
}

progress { width: 100%; height: .6rem; }
progress[hidden] { display: none; }
