/* ---------------------------------------------------------------- tokens */

:root {
  --primary: #3369e8;
  --positive: #009925;
  --negative: #d50f25;
  --warning: #eeb211;

  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #ececec;
  --text: #111318;
  --muted: #5f6470;
  --line: #dcdee5;
  --shadow: 0 3px 6px 2px rgb(0 0 0 / .12);
  --toolbar-h: 50px;
}

:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1d1d1d;
  --surface-2: #272727;
  --text: #ffffff;
  --muted: #a8adba;
  --line: #343434;
  --shadow: 0 3px 6px 2px rgb(0 0 0 / .4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 Quicksand, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

body.no-scroll { overflow: hidden; }

/* --------------------------------------------------------------- toolbar */

.toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  min-height: var(--toolbar-h);
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 0 4px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.brand:hover { background: var(--surface-2); }
.brand-mark { width: 30px; height: 30px; border-radius: 50%; }
.brand-name { font-size: 17px; font-weight: 500; margin: 0; }

.toolbar-spacer { flex: 1 1 auto; }

.toolbar-actions { display: flex; align-items: stretch; }

.tbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 14px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.tbtn:hover { background: var(--surface-2); }
.tbtn:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.tbtn .ico { font-size: 15px; line-height: 1; }
.caret { font-size: 11px; opacity: .8; }

body:not(.muted) .ico-off { display: none; }
body.muted .ico-on { display: none; }

.hamburger { display: none; font-size: 19px; }

.menu-anchor { position: relative; display: flex; }

.menu {
  position: absolute;
  top: 100%;
  inset-inline-end: 0;
  min-width: 210px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 40;
}

.menu[hidden] { display: none; }

.menu button {
  font: inherit;
  text-align: start;
  padding: 9px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.menu button:hover { background: var(--surface-2); }
.menu button[aria-current="true"] { color: var(--primary); font-weight: 600; }

/* ------------------------------------------------------------ page shell */

.page {
  position: fixed;
  inset: var(--toolbar-h) 0 0 0;
  display: grid;
  grid-template-columns: minmax(0, 200px) minmax(0, 1fr) 380px;
  gap: 8px;
  padding: 8px;
  background:
    radial-gradient(at 0% 0%, rgb(51 105 232 / .30) 0, rgb(0 0 0 / 0) 50%),
    radial-gradient(at 98% 1%, rgb(213 15 37 / .30) 0, rgb(0 0 0 / 0) 50%),
    var(--page-tint, transparent);
}

.col-left {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px;
  min-width: 0;
}

.title-block { display: flex; align-items: center; gap: 10px; }

.wheel-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}

.side-note { margin: 0; font-size: 12px; color: var(--muted); }

.round-btn {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.round-btn:hover { filter: brightness(1.12); }
.round-btn svg { width: 14px; height: 14px; fill: currentColor; display: block; }
.brand-mark { object-fit: contain; }

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

.col-center {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  align-content: center;
  justify-items: center;
  gap: 12px;
  overflow: auto;
}

.wheel-container { width: 100%; display: grid; place-items: center; min-width: 0; }

.wheel-box {
  position: relative;
  width: min(100%, 78vh);
  aspect-ratio: 1;
}

.wheel-canvas { filter: drop-shadow(0 6px 18px rgb(0 0 0 / .45)); }

.wheel-canvas, .spin-hint {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.spin-hint { pointer-events: none; }

.spin-hint {
  z-index: 4;
  fill: #fff;
  font-family: system-ui, sans-serif;
  font-weight: 800;
  filter: drop-shadow(0 0 10px #000);
  transition: opacity .4s;
}

.spin-hint.gone { opacity: 0; }
.hint-major { font-size: 12px; }
.hint-minor { font-size: 8px; opacity: .85; }

.wheel-hit {
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.wheel-hit:focus-visible { outline: 3px solid var(--primary); outline-offset: 4px; }

/* The pointer is physically at 3 o'clock, which the spin maths assumes —
   so it anchors to `right`, never to the writing direction. */
.wheel-pointer {
  position: absolute;
  right: -3.5%;
  top: 50%;
  z-index: 5;
  width: 8.5%;
  height: auto;
  transform: translateY(-50%);
  transform-origin: 100% 50%;
  filter: drop-shadow(0 3px 5px rgb(0 0 0 / .55));
  pointer-events: none;
}

.wheel-pointer.knock { animation: knock .09s ease-out; }

@keyframes knock {
  50% { transform: translateY(-50%) rotate(-11deg); }
}

.wheel-container.active .wheel-box::after {
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 2px dashed rgb(51 105 232 / .5);
  pointer-events: none;
}

.wheel-container.solo.active .wheel-box::after { display: none; }

/* -------------------------------------------------------- right / editor */

.col-right { position: relative; min-width: 0; display: flex; }

.card {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs { display: flex; border-bottom: 1px solid var(--line); }

.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  padding: 11px 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.active { color: var(--text); border-bottom-color: var(--primary); }

.badge {
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #616161;
  color: #fff;
  font-size: 12px;
}

.panel {
  display: none;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow: auto;
}

.panel.active { display: flex; }

.row-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-tools.bottom { margin-top: auto; }

.pbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 13px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: inherit;
  cursor: pointer;
}

.pbtn:hover { filter: brightness(1.08); }
.pbtn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.pbtn.primary { background: var(--primary); border-color: transparent; color: #fff; }
.pbtn.danger { color: var(--negative); }

.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }

.editor {
  flex: 1 1 auto;
  min-height: 200px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.7 system-ui, sans-serif;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.editor:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
.editor div { min-height: 1.7em; }

.hint { margin: 0; font-size: 12.5px; color: var(--muted); }

.results { margin: 0; padding-inline-start: 24px; display: flex; flex-direction: column; gap: 4px; }
.results li { overflow-wrap: anywhere; }
.results .when { color: var(--muted); font-size: 12px; margin-inline-start: 6px; }

.card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.dot { opacity: .5; }

.editor-toggle {
  position: absolute;
  top: 14px;
  inset-inline-start: -16px;
  z-index: 10;
  width: 30px;
  height: 30px;
  font-size: 12px;
}

body.editor-hidden .col-right .card { display: none; }
body.editor-hidden .page { grid-template-columns: minmax(0, 200px) minmax(0, 1fr) 0; }

/* --------------------------------------------------------------- dialogs */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgb(8 10 20 / .6);
  backdrop-filter: blur(2px);
}

.overlay[hidden] { display: none; }

.dialog {
  width: min(520px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: pop .2s cubic-bezier(.2, 1.35, .5, 1);
}

.dialog.wide { width: min(680px, 96vw); }

@keyframes pop { from { transform: scale(.9); opacity: 0; } }

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h3 { margin: 0; font-size: 17px; }
.dialog-head .round-btn { background: transparent; color: var(--text); }
.dialog-head .round-btn:hover { background: var(--surface-2); }

.dialog-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.winner-dialog { width: min(860px, 96vw); overflow: hidden; }

.winner-bar {
  padding: 18px 24px;
  transition: background .2s, color .2s;
  background: var(--negative);
  color: #fff;
  font-size: 21px;
  font-weight: 700;
}

.winner-body {
  padding: 28px 24px 34px;
  background: var(--surface);
  text-align: center;
  overflow: auto;
}

.winner-name {
  margin: 0;
  font-size: clamp(34px, 7vw, 68px);
  font-weight: 400;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.winner-img { max-width: 160px; border-radius: 12px; margin: 0 auto 16px; display: block; }
.winner-dialog .dialog-actions { border: 0; padding: 0 24px 20px; background: var(--surface); }
.pbtn.flat { background: transparent; border-color: transparent; padding: 8px 16px; }
.pbtn.flat:hover { background: var(--surface-2); }
.winner-dialog .pbtn { font-size: 15px; padding: 10px 20px; }

fieldset {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

legend { padding: 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.field.row { flex-direction: row; align-items: center; justify-content: space-between; }
.field b { color: var(--text); }
.inline-tools { display: flex; gap: 6px; }

.field input[type="text"], .field select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.field input[type="range"] { accent-color: var(--primary); }
.field input[type="color"] { width: 56px; height: 32px; padding: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }

.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }

.saved-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.saved-list .name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }

.share-box {
  width: 100%;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

/* Above the dialog backdrop (z 50) so the throw stays bright while it is up. */
.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 55;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: 24px;
  z-index: 60;
  margin: 0 auto;
  width: fit-content;
  max-width: 90vw;
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow);
}

.toast[hidden] { display: none; }

/* ----------------------------------------------------------- fullscreen  */

body.presenting .toolbar,
body.presenting .col-left,
body.presenting .col-right { display: none; }

body.presenting .page { inset: 0; grid-template-columns: 1fr; padding: 0; }

/* ------------------------------------------------------------ responsive */

@media (max-width: 1100px) {
  .page { grid-template-columns: minmax(0, 1fr) 340px; }
  .col-left { display: none; }
  body.editor-hidden .page { grid-template-columns: minmax(0, 1fr) 0; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .toolbar-actions { display: none; }
  .toolbar-actions.open {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    top: var(--toolbar-h);
    inset-inline-end: 4px;
    width: 240px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }
  .toolbar-actions.open .tbtn { padding: 10px 12px; border-radius: 7px; }
  .toolbar-actions.open .menu-anchor { display: block; }
  .toolbar-actions.open .menu { position: static; border: 0; box-shadow: none; padding-inline-start: 14px; }
  .hamburger { display: inline-flex; }

  .page {
    position: static;
    height: auto;
    min-height: calc(100dvh - var(--toolbar-h));
    margin-top: var(--toolbar-h);
    grid-template-columns: minmax(0, 1fr);
  }
  .col-left { display: flex; }
  .wheel-box { width: min(92vw, 520px); }
  .col-right { min-height: 60vh; }
  .editor-toggle { display: none; }
  body.editor-hidden .col-right .card { display: flex; }
}
