:root {
  --primary: #14b8a6;
  --background: #111827;
  --pointer: #f43f5e;
  --hub: #111827;
  --spin-button: #14b8a6;
  --result: #059669;
  --background-image: none;
  --background-overlay: 0.18;
  --wheel-size: min(86vw, 410px);
  --spin-duration: 5.4s;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --text: #111827;
  --muted: #667085;
  --border: #d8dee8;
  --success: #059669;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.18);
  font-family: Tahoma, Arial, system-ui, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  background: var(--background);
}

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--surface-2);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface);
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.topbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) 18px 14px;
  color: #ffffff;
  background: var(--background);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 390px;
  margin-bottom: 0;
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.3;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.icon-button {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  color: #ffffff;
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.balance-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.balance-band > div {
  min-width: 0;
  padding: 14px 8px;
  text-align: center;
}

.balance-band > div + div {
  border-right: 1px solid var(--border);
}

.balance-band span,
.balance-band small,
.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.balance-band strong {
  display: block;
  max-width: 100%;
  margin: 3px 0 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 18px;
}

.wheel-stage {
  padding: 18px 16px 20px;
  text-align: center;
  background-color: var(--surface-2);
  background-image:
    linear-gradient(
      rgba(0, 0, 0, var(--background-overlay)),
      rgba(0, 0, 0, var(--background-overlay))
    ),
    var(--background-image);
  background-position: center;
  background-size: cover;
  border-bottom: 1px solid var(--border);
}

.subtitle {
  min-height: 22px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.wheel-wrap {
  position: relative;
  width: var(--wheel-size);
  aspect-ratio: 1;
  margin: 0 auto 18px;
  filter: drop-shadow(0 12px 18px rgba(15, 23, 42, 0.2));
}

#wheel-canvas {
  width: 100%;
  height: 100%;
  display: block;
  transform: rotate(0deg);
  transition: transform var(--spin-duration) cubic-bezier(0.12, 0.72, 0.16, 1);
  will-change: transform;
}

.pointer {
  position: absolute;
  z-index: 3;
  top: -3px;
  left: 50%;
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-right: 17px solid transparent;
  border-left: 17px solid transparent;
  border-top: 38px solid var(--pointer);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.28));
}

.wheel-hub {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%);
  border: 5px solid #ffffff;
  border-radius: 50%;
  color: #ffffff;
  background: var(--hub);
  box-shadow: 0 5px 15px rgba(15, 23, 42, 0.32);
  font-size: 24px;
  font-weight: 800;
}

.source-control,
.period-tabs {
  display: grid;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.source-control {
  grid-template-columns: repeat(3, 1fr);
  max-width: 410px;
  margin: 0 auto 10px;
}

.source-control button,
.period-tabs button {
  min-height: 38px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  font-weight: 700;
}

.source-control button.active,
.period-tabs button[aria-selected="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.13);
}

.spin-button,
.confirm-button {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  color: #ffffff;
  background: var(--spin-button);
  font-weight: 800;
}

.spin-button {
  max-width: 410px;
}

.spin-button span,
.spin-button small {
  display: block;
}

.spin-button small {
  min-height: 16px;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.9;
}

.status-line {
  min-height: 20px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.result-band {
  padding: 17px 18px;
  border-bottom: 1px solid var(--border);
  border-right: 5px solid var(--result);
  background: var(--surface-2);
}

.result-band span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.result-band strong {
  display: block;
  margin: 4px 0;
  color: var(--result);
  font-size: 21px;
  overflow-wrap: anywhere;
}

.result-band p {
  margin-bottom: 0;
  color: var(--text);
  font-size: 13px;
}

.stats-section,
.history-section {
  padding: 19px 18px;
  border-bottom: 1px solid var(--border);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.section-heading > span {
  color: var(--muted);
  font-size: 12px;
}

.period-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.stats-grid > div {
  min-width: 0;
  padding: 13px;
  border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border);
}

.stats-grid strong {
  display: block;
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 17px;
}

.history-list {
  display: grid;
  gap: 0;
}

.history-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 62px;
  border-top: 1px solid var(--border);
}

.history-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: var(--primary);
  font-size: 18px;
}

.history-copy {
  min-width: 0;
}

.history-copy strong,
.history-copy span,
.history-amount strong,
.history-amount span {
  display: block;
}

.history-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.history-copy span,
.history-amount span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.history-amount {
  min-width: 72px;
  text-align: left;
}

.history-amount strong.positive {
  color: var(--success);
}

.history-amount strong.negative {
  color: var(--danger);
}

.empty-state {
  margin: 10px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

footer {
  display: flex;
  justify-content: center;
  gap: 22px;
  padding: 18px;
  font-size: 12px;
}

footer a {
  color: var(--muted);
}

.legal-page {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(28px, env(safe-area-inset-top)) 20px 40px;
  color: var(--text);
  background: var(--surface);
  line-height: 1.9;
}

.legal-page h1 {
  margin-bottom: 24px;
}

.legal-page h2 {
  margin: 24px 0 5px;
}

.legal-page p {
  color: var(--muted);
}

.legal-page a {
  color: var(--primary);
}

.loading-screen {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 14px;
  color: #ffffff;
  background: var(--background);
  text-align: center;
}

.loading-screen[hidden] {
  display: none;
}

.loading-mark {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  margin: auto;
  border: 3px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--primary);
  border-radius: 50%;
  font-size: 24px;
  font-weight: 800;
  animation: loading-spin 1s linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

.consent-dialog {
  width: min(calc(100% - 28px), 500px);
  max-height: min(82vh, 680px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.consent-dialog::backdrop {
  background: rgba(2, 6, 23, 0.72);
}

.consent-dialog form {
  padding: 18px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 13px;
}

.dialog-heading .icon-button {
  color: var(--text);
  border-color: var(--border);
}

.rules-copy {
  max-height: 260px;
  padding: 13px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-2);
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.8;
}

.check-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: start;
  gap: 9px;
  margin-top: 13px;
  font-size: 13px;
}

.check-row input {
  width: 19px;
  height: 19px;
  accent-color: var(--primary);
}

.confirm-button {
  margin-top: 16px;
}

.dialog-error {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 12px;
  text-align: center;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 14px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 14px;
  max-width: 520px;
  margin: auto;
  padding: 13px 15px;
  border-radius: 8px;
  color: #ffffff;
  background: #991b1b;
  box-shadow: var(--shadow);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 350px) {
  h1 { font-size: 19px; }
  .balance-band strong { font-size: 15px; }
  .source-control button,
  .period-tabs button { font-size: 11px; }
}

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