:root {
  --ui-bg: rgba(255, 255, 255, 0.9);
  --ui-border: rgba(255, 255, 255, 0.65);
  --ui-shadow: 0 1.2rem 2.5rem rgba(0, 0, 0, 0.12);
  --ui-text: #1e1e1e;
  --ui-muted: #666;
  --ui-backdrop: rgba(0, 0, 0, 0.35);
  --ui-button: rgba(255, 255, 255, 0.95);
  --ui-button-hover: rgba(255, 255, 255, 1);
  --ui-accent: #111;
  --brand-bg: #221e1d;
  --brand-cream: #ede3d0;
  --brand-text: #c8bcab;
  --brand-accent: #724b39;
  --radius-xl: 1.5rem;
  --radius-lg: 1.1rem;
  --radius-md: 0.9rem;
  --radius-sm: 0.75rem;
  --transition: 220ms ease;
  --font-stack: "Poppins", "Inter", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: transparent !important;
  overflow: hidden;
  font-family: var(--font-stack);
  color: var(--ui-text);
}

body {
  display: grid;
  place-items: center;
}

.widget-shell {
  width: 100%;
  height: 100%;
  background: var(--brand-bg);
  position: relative;
  overflow: hidden;
}

.scale-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1000px;
  height: 1000px;
  transform-origin: center center;
  will-change: transform;
  pointer-events: auto;
}

.stage {
  position: relative;
  width: 1000px;
  height: 1000px;
  background: transparent;
}

.wheel-area {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: transparent;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: transparent;
}

.pointer {
  position: absolute;
  top: 2.8%;
  left: 50%;
  transform: translateX(-50%);
  width: 5.2%;
  height: auto;
  z-index: 20;
  filter: drop-shadow(0 0.35rem 0.6rem rgba(0, 0, 0, 0.15));
  pointer-events: none;
}

.spinner-button {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 19%;
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  z-index: 15;
  display: grid;
  place-items: center;
}

.spinner-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.spinner-button:active {
  transform: translate(-50%, -50%) scale(0.985);
}

/* Floating settings control */
/* IMPORTANT: .top-controls should be outside .scale-wrap in the HTML */
.top-controls {
  position: fixed;
  right: 18px;
  bottom: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 500;
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.settings-nudge {
  display: flex;
  align-items: center;
  gap: 7px;
  color: rgba(237, 227, 208, 0.98);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.72);
  white-space: nowrap;
  opacity: 1;
  padding: 6px 8px 6px 10px;
  border-radius: 999px;
  background: rgba(34, 30, 29, 0.62);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.settings-arrow {
  width: 48px;
  height: auto;
  color: rgba(237, 227, 208, 0.96);
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.6));
  transform: translateY(1px);
  flex: 0 0 auto;
}

.settings-btn {
  border: 1px solid rgba(237, 227, 208, 0.24);
  background: rgba(255, 255, 255, 0.13);
  backdrop-filter: blur(0.8rem);
  -webkit-backdrop-filter: blur(0.8rem);
  color: #ffffff;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  border-radius: 999px;
  box-shadow: 0 0.8rem 1.8rem rgba(0, 0, 0, 0.34);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  line-height: 1;
  padding: 0;
  flex: 0 0 auto;
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.settings-btn img {
  width: 58%;
  height: 58%;
  object-fit: contain;
  pointer-events: none;
  filter: brightness(0) invert(1);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--ui-backdrop);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 200;
}

.modal-backdrop.show {
  display: flex;
}

.modal {
  width: min(92vw, 34rem);
  max-height: 88vh;
  overflow: auto;
  border-radius: var(--radius-xl);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(1rem);
  -webkit-backdrop-filter: blur(1rem);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 1.6rem 3.5rem rgba(0, 0, 0, 0.18);
  padding: 1.2rem;
}

.modal h2 {
  margin: 0 0 0.35rem;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal p {
  margin: 0;
  color: var(--ui-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.modal-section {
  margin-top: 1rem;
}

.label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ui-text);
}

textarea,
select,
input[type="text"] {
  width: 100%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-md);
  padding: 0.9rem 1rem;
  font: inherit;
  color: var(--ui-text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

textarea {
  min-height: 10.5rem;
  max-height: 18rem;
  resize: vertical;
  overflow: auto;
  line-height: 1.45;
}

textarea:focus,
select:focus,
input[type="text"]:focus {
  border-color: rgba(0, 0, 0, 0.18);
  box-shadow: 0 0 0 0.2rem rgba(0, 0, 0, 0.06);
}

.help {
  margin-top: 0.45rem;
  font-size: 0.82rem;
  color: var(--ui-muted);
  line-height: 1.45;
}

.palette-preview {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
}

.swatch {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex: 0 0 auto;
}

.modal-actions {
  display: flex;
  gap: 0.65rem;
  margin-top: 1.15rem;
  flex-wrap: wrap;
  align-items: center;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 0.82rem 1.15rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), opacity var(--transition), background var(--transition);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: #111;
  color: #fff;
}

.btn-secondary {
  background: rgba(0, 0, 0, 0.06);
  color: #111;
}

#shufflePaletteBtn {
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.06);
  color: #111;
}

#shufflePaletteBtn:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Result modal */
.result-modal {
  text-align: center;
  padding: 1.5rem 1.25rem 1.25rem;
}

.result-modal h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ui-muted);
}

.result-book {
  margin: 0.8rem 0 0;
  font-size: 1.45rem;
  line-height: 1.3;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--ui-text);
  overflow-wrap: anywhere;
}

/* Secret offer shown after first spin */
.secret-offer {
  margin: 1rem auto 0;
  padding: 1rem 1rem 1.05rem;
  border: 1px solid rgba(200, 188, 171, 0.18);
  border-radius: 1rem;
  background:
    linear-gradient(
      135deg,
      rgba(34, 30, 29, 0.09),
      rgba(114, 75, 57, 0.08)
    );
}

.secret-kicker {
  margin: 0;
  color: var(--brand-accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.secret-line {
  margin: 0.45rem 0 0;
  color: var(--ui-text);
  font-size: 0.98rem;
  line-height: 1.35;
  font-weight: 500;
}

.secret-code {
  margin: 0.35rem 0 0;
  color: var(--ui-muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.secret-code strong {
  color: var(--ui-text);
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* Empty wheel state */
.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
  pointer-events: none;
  padding: 18%;
  text-align: center;
  color: rgba(237, 227, 208, 0.72);
  font-size: 1.1rem;
  line-height: 1.45;
  font-weight: 500;
}

/* Mobile */
@media (max-width: 560px) {
  .top-controls {
    top: auto !important;
    right: 14px !important;
    bottom: 118px !important;
    gap: 6px !important;
    z-index: 999 !important;
  }

  .settings-nudge {
    font-size: 13px !important;
    font-weight: 500 !important;
    padding: 5px 7px 5px 9px !important;
    gap: 6px !important;
    border-radius: 999px !important;
    background: rgba(34, 30, 29, 0.68) !important;
    backdrop-filter: blur(7px) !important;
    -webkit-backdrop-filter: blur(7px) !important;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.78) !important;
    color: rgba(237, 227, 208, 1) !important;
  }

  .settings-arrow {
    width: 42px !important;
    min-width: 42px !important;
  }

  .settings-btn {
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    box-shadow: 0 0.75rem 1.6rem rgba(0, 0, 0, 0.34) !important;
  }

  .settings-btn img {
    width: 58% !important;
    height: 58% !important;
  }

  .modal-backdrop {
    padding: 0.75rem;
  }

  .modal {
    width: min(86vw, 24rem);
    max-height: 82vh;
    border-radius: 1.25rem;
    padding: 0.85rem;
  }

  .settings-modal {
    width: min(84vw, 23rem);
    max-height: 78vh;
    padding: 0.82rem;
  }

  .modal h2 {
    font-size: 1rem;
    line-height: 1.12;
    margin-bottom: 0.25rem;
  }

  .modal p {
    font-size: 0.76rem;
    line-height: 1.3;
  }

  .modal-section {
    margin-top: 0.7rem;
  }

  .label {
    font-size: 0.76rem;
    margin-bottom: 0.32rem;
  }

  select,
  input[type="text"] {
    border-radius: 0.72rem;
    padding: 0.58rem 0.72rem;
    font-size: 0.82rem;
  }

  .palette-preview {
    gap: 0.34rem;
    margin-top: 0.52rem;
  }

  .swatch {
    width: 0.92rem;
    height: 0.92rem;
  }

  .modal-actions {
    gap: 0.42rem;
    margin-top: 0.78rem;
  }

  .btn {
    padding: 0.56rem 0.78rem;
    font-size: 0.74rem;
  }

  .result-modal {
    padding: 1rem 0.85rem 0.85rem;
  }

  .result-modal h3 {
    font-size: 0.72rem;
  }

  .result-book {
    font-size: 1.1rem;
    margin-top: 0.52rem;
  }

  .secret-offer {
    margin-top: 0.72rem;
    padding: 0.72rem 0.7rem 0.76rem;
  }

  .secret-kicker {
    font-size: 0.66rem;
  }

  .secret-line {
    font-size: 0.78rem;
  }

  .secret-code {
    font-size: 0.74rem;
  }
}

/* Extra small phones */
@media (max-width: 390px) {
  .top-controls {
    top: auto !important;
    right: 12px !important;
    bottom: 108px !important;
    gap: 5px !important;
  }

  .settings-nudge {
    font-size: 12px !important;
    padding: 5px 6px 5px 8px !important;
    gap: 5px !important;
  }

  .settings-arrow {
    width: 36px !important;
    min-width: 36px !important;
  }

  .settings-btn {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
  }
}

.hidden {
  display: none !important;
}
