/* Decision Spinner — chassis styles.
   Brand tokens are rewritten by `appfactory new`; everything else is structure. */

/* >>> tokens */
:root {
  --bg: #1C1633;
  --surface: #1b1b24;
  --text: #f2f2f7;
  --dim: #9a9aa8;
  --accent: #FF7A3C;
  --radius: 14px;
  --pad: 16px;
}
/* <<< tokens */

:root {
  --surface: #2A2250;
  --raised: #3A2F68;
  --line: rgba(247, 241, 255, .16);
  --text: #F7F1FF;
  --dim: #D0C2EC;
  --on-accent: #2A1206;
  --danger: #F08A84;
  --danger-bg: rgba(228, 115, 107, .14);
  --toast-bg: #3A2F68;
  --tap: 44px;
  --space: 8px;
  --radius-xl: 16px;
  --text-scale: 1;
  --dur: 180ms;
  --dur-layout: 320ms;
  --ease: cubic-bezier(.2, .7, .3, 1);
  --shadow: 0 8px 24px rgba(12, 8, 28, .35);
  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent);
  --app-max: 480px;
}

* { box-sizing: border-box; }

/* The UA rule for [hidden] is display:none at UA priority, so ANY author rule
   that sets display beats it — .btn-block{display:block} or a flex row keeps
   rendering while `el.hidden = true` quietly reports success. It fails silently
   and only in the browser, which makes it expensive to find. Declared once here
   so app code can toggle .hidden on anything without also remembering to write
   a matching [hidden] variant for every component it styles. */
[hidden] { display: none !important; }

html {
  font-size: calc(16px * var(--text-scale, 1));
}

html, body {
  margin: 0;
  /* --app-height is set ONLY while a field is focused (see index.html).
     Unset, this falls through to 100dvh, which is what we want the rest of
     the time because it survives rotation without stale pixel values. */
  height: var(--app-height, 100dvh);
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

::selection {
  background: color-mix(in srgb, var(--accent) 42%, transparent);
  color: var(--text);
}

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: var(--app-max);
  margin-inline: auto;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

#stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--dim) 40%, transparent) transparent;
}

#app[data-screen="spin"] #stage,
#app[data-screen="result"] #stage {
  overflow: hidden;
}

#app[data-screen="spin"] #appBar { display: none; }

/* --- primitives ----------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: calc(var(--space) * 2);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: .8rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.dim { color: var(--dim); }
code { background: rgba(255,255,255,.07); padding: .1em .4em; border-radius: 6px; font-size: .9em; }

.btn,
.icon-btn,
.seg-btn,
.option-main,
.switch,
.text-btn {
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

.btn {
  appearance: none;
  border: 0;
  background: var(--raised);
  color: var(--text);
  font: inherit;
  font-weight: 650;
  border-radius: 12px;
  padding: 12px 16px;
  min-height: var(--tap);
  min-width: var(--tap);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
    background var(--dur) var(--ease), filter var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: var(--shadow);
}
.btn:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: none;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn:disabled {
  cursor: default;
  filter: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
}
.btn-primary:disabled {
  background: var(--raised);
  color: var(--dim);
  border: 1px solid var(--line);
  opacity: 1;
}

.btn-ghost,
.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  border-radius: 12px;
  padding: 8px 10px;
  min-height: var(--tap);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn-ghost:hover:not(:disabled),
.text-btn:hover:not(:disabled) {
  background: rgba(255, 122, 60, .1);
}
.btn-ghost:active:not(:disabled),
.text-btn:active:not(:disabled) { transform: scale(0.97); }
.btn-ghost:disabled,
.text-btn:disabled {
  color: var(--dim);
  opacity: .55;
  cursor: default;
}

.btn-quiet {
  background: transparent;
  color: var(--dim);
  box-shadow: none;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
  display: inline-flex;
  line-height: 0;
  min-width: var(--tap);
  min-height: var(--tap);
  align-items: center;
  justify-content: center;
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover:not(:disabled) { background: rgba(247, 241, 255, .08); }
.icon-btn:active:not(:disabled) { transform: scale(0.96); background: rgba(247, 241, 255, .12); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.icon-btn-raised {
  background: var(--raised);
  border: 1px solid var(--line);
}
.icon-btn-raised:hover:not(:disabled) { background: color-mix(in srgb, var(--raised) 80%, #fff); }

.icon-btn-danger { color: var(--danger); }
.icon-btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

.field { display: flex; flex-direction: column; gap: 8px; }
.field-label {
  font-size: .85rem;
  font-weight: 650;
  color: var(--text);
}
.field-hint {
  margin: 0;
  font-size: .8rem;
  color: var(--dim);
}
.field-error {
  margin: 0;
  font-size: .85rem;
  font-weight: 650;
  color: var(--danger);
}
.field-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.field input,
.add-form input {
  flex: 1;
  min-width: 0;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--raised);
  color: var(--text);
  font: inherit;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: var(--tap);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
.field input::placeholder { color: color-mix(in srgb, var(--dim) 82%, var(--text)); }
.field input:hover { border-color: color-mix(in srgb, var(--line) 60%, var(--text)); }
.field input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.field input.is-invalid {
  border-color: var(--danger);
  animation: shake 300ms var(--ease);
}

/* --- header --------------------------------------------------------------- */

#appBar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: saturate(1.2) blur(16px);
  -webkit-backdrop-filter: saturate(1.2) blur(16px);
  border-bottom: 1px solid var(--line);
}

#appTitle {
  font-size: 1rem;
  margin: 0;
  font-weight: 700;
  text-align: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#newBtn {
  flex: 0 1 auto;
  max-width: 46%;
  padding-inline: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen {
  flex: 1 1 auto;
  padding: 16px 16px 16px;
}

#decision.screen {
  display: flex;
  flex-direction: column;
}

/* --- sheets --------------------------------------------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 10, 32, .62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.sheet-backdrop[hidden] { display: none; }

.sheet {
  background: var(--surface);
  width: 100%;
  max-width: var(--app-max);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 85%;
  overflow-y: auto;
  box-shadow: 0 -12px 40px rgba(8, 4, 20, .4);
  animation: sheetUp var(--dur-layout) var(--ease);
}
.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: rgba(247, 241, 255, .22);
  margin: 4px auto 12px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.sheet-foot { margin-top: 16px; display: flex; gap: 8px; align-items: center; font-size: .85rem; }
.sheet-foot a {
  color: var(--dim);
  text-decoration-color: transparent;
  transition: color var(--dur) var(--ease), text-decoration-color var(--dur) var(--ease);
}
.sheet-foot a:hover { color: var(--text); text-decoration-color: currentColor; }
#appVersion { margin-left: auto; font-variant-numeric: tabular-nums; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  min-height: var(--tap);
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.row:last-of-type { border-bottom: 0; }
.row-stack { flex-direction: column; align-items: stretch; gap: 10px; cursor: default; }
.row-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-title { font-weight: 650; }
.row-hint { font-size: .8rem; color: var(--dim); }

.confirm-body { color: var(--dim); margin: 8px 0 16px; }
.sheet-actions { display: flex; gap: 8px; }
.sheet-actions .btn { flex: 1; }

.privacy-note { margin: 16px 0 0; font-size: .9rem; }

.switch {
  appearance: none;
  width: 52px;
  height: 32px;
  min-width: 52px;
  min-height: 32px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--raised);
  border: 1px solid var(--line);
  position: relative;
  cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.switch:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch:checked::after {
  transform: translateX(20px);
  background: var(--on-accent);
}
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.seg {
  display: flex;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: .85rem;
  font-weight: 650;
  flex: 1;
  min-height: var(--tap);
  border-radius: 10px;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.seg-btn:hover:not([aria-checked="true"]) { color: var(--text); }
.seg-btn:active { transform: scale(0.98); }
.seg-btn[aria-checked="true"] {
  background: var(--accent);
  color: var(--on-accent);
}
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- floating pills ------------------------------------------------------- */

.pill {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  border: 0;
  border-radius: 999px;
  padding: 12px 20px;
  min-height: var(--tap);
  font: inherit;
  font-size: .9rem;
  font-weight: 650;
  cursor: pointer;
  z-index: 60;
  box-shadow: var(--shadow);
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.pill:hover { filter: brightness(1.06); }
.pill:active { transform: translateX(-50%) scale(0.97); }
.pill[hidden] { display: none; }

.update-toast { bottom: calc(18px + env(safe-area-inset-bottom)); background: var(--accent); color: var(--on-accent); }
.install-hint { bottom: calc(74px + env(safe-area-inset-bottom)); background: var(--surface); color: var(--text); border: 1px solid var(--line); }

#toast, #syncStatus {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(12px + env(safe-area-inset-top));
  max-width: min(420px, calc(100vw - 32px));
  background: var(--toast-bg);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 650;
  z-index: 70;
  pointer-events: none;
  box-shadow: var(--shadow);
  animation: toastIn 220ms var(--ease);
}
#toast[hidden], #syncStatus[hidden] { display: none; }

/* --- Decision Spinner ----------------------------------------------------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.helper {
  margin: 0 0 16px;
  color: var(--dim);
  font-size: .95rem;
}

.add-card { margin-bottom: 16px; }
.add-card .btn-primary { flex: 0 0 auto; white-space: nowrap; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 200px;
  padding: 32px 16px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--surface) 55%, transparent);
}
.empty-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 8px;
  color: var(--dim);
}
.empty-icon svg { display: block; }
.empty-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 750;
}
.empty-copy {
  margin: 0;
  max-width: 28ch;
  color: var(--dim);
  font-size: .95rem;
}

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

.option-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--tap) var(--tap);
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border-radius: var(--radius-xl);
  min-height: 56px;
  padding: 6px 6px 6px 8px;
  border: 1px solid var(--line);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.option-row:hover {
  border-color: color-mix(in srgb, var(--line) 50%, var(--text));
  box-shadow: 0 4px 16px rgba(12, 8, 28, .22);
}
.option-row.flash {
  border-color: var(--accent);
  animation: flash .6s var(--ease);
}
.option-row.is-enter { animation: rowIn 220ms var(--ease); }

.option-main {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  min-height: var(--tap);
  min-width: 0;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 12px;
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.option-main:hover { background: rgba(247, 241, 255, .05); }
.option-main:active { transform: scale(0.98); background: rgba(247, 241, 255, .08); }
.option-main:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.option-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}
.option-name {
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.option-plus {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  opacity: .9;
}
.option-plus svg { width: 20px; height: 20px; }

.spin-dock {
  flex: 0 0 auto;
  padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 72%, color-mix(in srgb, var(--bg) 55%, transparent));
  border-top: 1px solid var(--line);
}
.btn-spin {
  width: 100%;
  font-size: 1.1rem;
  border-radius: 14px;
}

#spin.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  min-height: 0;
  padding-top: calc(16px + env(safe-area-inset-top));
}
#spin[hidden] { display: none !important; }

.spin-status {
  margin: 0 0 16px;
  color: var(--dim);
  font-weight: 700;
  letter-spacing: .02em;
}

.wheel-wrap {
  position: relative;
  width: min(86vw, 360px);
  aspect-ratio: 1;
}
.pointer {
  position: absolute;
  left: 50%;
  top: -10px;
  z-index: 2;
  width: 30px;
  height: 36px;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 5px rgba(0,0,0,.45));
  pointer-events: none;
}
.pointer-flap {
  display: block;
  width: 0;
  height: 0;
  margin: 0 auto;
  border-left: 14px solid transparent;
  border-right: 14px solid transparent;
  border-top: 28px solid var(--accent);
  transform-origin: 50% 3px;
}
.pointer.is-tick .pointer-flap {
  animation: pointerTick 90ms cubic-bezier(0.15, 0.85, 0.3, 1);
}
.wheel-stage {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(8, 4, 20, .5), inset 0 0 0 5px #2A2250;
  border: 2px solid rgba(247, 241, 255, .18);
}
#wheel {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: 50% 50%;
  will-change: transform;
}

.slice-label {
  font-size: 5px;
  font-weight: 700;
  fill: #1C1633;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

#result.screen {
  display: flex;
  flex-direction: column;
  text-align: center;
  min-height: 0;
  overflow: hidden;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
#result[hidden] { display: none !important; }

.result-hero { flex: 0 0 auto; }
.result-kicker {
  margin: 8px 0 0;
  color: var(--dim);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: .8rem;
}
.result-name {
  margin: 8px 0 8px;
  font-size: clamp(2rem, 8vw, 2.6rem);
  line-height: 1.1;
  font-weight: 800;
  word-break: break-word;
  animation: resultPop 420ms var(--ease) both;
}
.result-sentence {
  margin: 0 0 16px;
  color: var(--dim);
  font-weight: 650;
}

.odds-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}
.odds-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: var(--tap);
  border: 1px solid var(--line);
  animation: rowIn 280ms var(--ease) both;
  animation-delay: calc(var(--i, 0) * 50ms);
}
.odds-row.winner {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.odds-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.odds-meta { color: var(--dim); font-variant-numeric: tabular-nums; flex: 0 0 auto; }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
  margin-top: auto;
}

@keyframes flash {
  from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent); }
  to { box-shadow: 0 0 0 0 transparent; }
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}
@keyframes resultPop {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes sheetUp {
  from { transform: translateY(16px); opacity: .7; }
  to { transform: none; opacity: 1; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
@keyframes pointerTick {
  0% { transform: rotate(0deg); }
  38% { transform: rotate(26deg); }
  100% { transform: rotate(0deg); }
}

@media (max-width: 360px) {
  .field-row { flex-direction: column; }
  .field-row .btn { width: 100%; }
}

@media (hover: none) {
  .btn:hover:not(:disabled),
  .option-row:hover,
  .icon-btn:hover:not(:disabled) {
    filter: none;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

html[data-reduce-motion="1"] *,
html[data-reduce-motion="1"] *::before,
html[data-reduce-motion="1"] *::after {
  animation-duration: .01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .01ms !important;
}

/* >>> addon-styles */
/* <<< addon-styles */
