:root {
  /* ColorHunt Palette: e65747 - f5c46b - faeb95 - 90dcca */
  --coral: #e65747;
  --coral-hover: #d34636;
  --coral-soft: rgba(230, 87, 71, 0.12);
  --amber: #f5c46b;
  --amber-soft: rgba(245, 196, 107, 0.25);
  --cream: #faeb95;
  --cream-bg: #fcf5d4;
  --mint: #90dcca;
  --mint-deep: #248a73;
  --mint-soft: rgba(144, 220, 202, 0.28);

  /* Neutrals */
  --ink: #241916;
  --ink-muted: #66554e;
  --surface: #ffffff;
  --surface-alt: #fffdf5;
  --border: rgba(36, 25, 22, 0.1);
  --border-strong: rgba(36, 25, 22, 0.18);

  /* Radii & Shadows */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-card: 0 2px 8px rgba(36, 25, 22, 0.05), 0 12px 28px rgba(36, 25, 22, 0.07);
  --shadow-btn: 0 4px 14px rgba(230, 87, 71, 0.28);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Vazirmatn", Tahoma, system-ui, -apple-system, sans-serif;
  background: linear-gradient(165deg, var(--cream) 0%, var(--cream-bg) 52%, #f7f0d2 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 50;
}

.app-shell {
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  padding: 14px 14px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 1;
}

.hidden {
  display: none !important;
}

/* Top Bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--coral);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 3px 10px rgba(230, 87, 71, 0.25);
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 16px;
  box-shadow: var(--shadow-card);
}

/* Welcome Card */
.welcome-card {
  background: linear-gradient(180deg, #ffffff 0%, var(--surface-alt) 100%);
  border-top: 4px solid var(--coral);
}

.welcome-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  color: var(--coral);
  background: var(--coral-soft);
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}

.welcome-title {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.35;
}

.welcome-text {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--ink-muted);
}

.note-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--amber-soft);
  border: 1px solid rgba(245, 196, 107, 0.7);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
}

.note-box svg {
  flex-shrink: 0;
  color: #a86f09;
}

/* Setup Card */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.field-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.text-btn {
  background: none;
  border: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--coral);
  cursor: pointer;
  transition: background 0.15s ease;
}

.text-btn:hover {
  background: var(--coral-soft);
}

.entries-textarea {
  width: 100%;
  min-height: 144px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Vazirmatn", monospace;
  font-size: 14px;
  line-height: 1.65;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.entries-textarea:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-soft);
  background: #fff;
}

.entries-textarea::placeholder {
  color: #9e8f88;
}

/* Stats Row */
.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-top: 10px;
}

.stat-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.stat-label {
  font-size: 12px;
  color: var(--ink-muted);
}

.stat-value {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat-pill-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--mint-deep);
  background: var(--mint-soft);
  border-color: rgba(144, 220, 202, 0.7);
  cursor: pointer;
}

.stat-pill-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Pool Preview */
.pool-preview {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px dashed var(--border-strong);
}

.pool-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.pool-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 120px;
  overflow-y: auto;
}

.pool-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--cream);
  border: 1px solid rgba(245, 196, 107, 0.8);
  color: var(--ink);
}

/* Controls */
.controls-group {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.control-title {
  font-size: 14px;
  font-weight: 600;
}

.stepper {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.stepper-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: var(--surface-alt);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.stepper-btn:active {
  background: var(--amber-soft);
}

.stepper-input {
  width: 48px;
  height: 38px;
  border: none;
  border-inline: 1px solid var(--border);
  text-align: center;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.stepper-input::-webkit-inner-spin-button,
.stepper-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(36, 25, 22, 0.18);
  position: relative;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}

.toggle-row input:checked + .toggle-track {
  background: var(--mint-deep);
}

.toggle-row input:checked + .toggle-track::after {
  transform: translateX(-20px);
}

/* Error Message */
.error-msg {
  margin: 12px 0 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--coral-soft);
  color: #b42d1e;
  font-size: 13px;
  font-weight: 600;
}

/* Buttons */
.primary-btn {
  margin-top: 16px;
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--coral);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
}

.primary-btn:hover:not(:disabled) {
  background: var(--coral-hover);
}

.primary-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.primary-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-btn {
  width: 100%;
  min-height: 46px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
}

.secondary-btn:active {
  background: var(--cream);
}

/* Draw Stage (3 Sequential Input Slots) */
.draw-card {
  border-top: 4px solid var(--mint-deep);
}

.draw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.round-badge {
  background: var(--amber);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 11px;
  border-radius: 999px;
}

.draw-status {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}

.slots-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slot-wrapper {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slot-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-inline: 2px;
}

.slot-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
}

.slot-state {
  font-size: 11px;
  font-weight: 700;
  color: var(--coral);
}

.slot-wrapper.locked .slot-state {
  color: var(--ink-muted);
}

.slot-wrapper.winner .slot-state {
  color: var(--mint-deep);
}

.slot-input {
  height: 64px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-strong);
  background: var(--surface-alt);
  overflow: hidden;
  position: relative;
  transition: border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
}

.slot-wrapper.rolling .slot-input {
  border-color: var(--amber);
  background: #fff;
  box-shadow: 0 0 0 4px var(--amber-soft);
}

.slot-wrapper.locked .slot-input {
  border-color: var(--border-strong);
  background: var(--surface);
}

.slot-wrapper.winner .slot-input {
  border-color: var(--mint-deep);
  background: var(--mint-soft);
  box-shadow: 0 0 0 5px rgba(144, 220, 202, 0.4);
  transform: scale(1.02);
}

.slot-reel {
  display: flex;
  flex-direction: column;
  will-change: transform;
}

.slot-item {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Vazirmatn", monospace;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Winner Banner */
.winner-banner {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--cream) 0%, var(--amber-soft) 100%);
  border: 1.5px solid var(--amber);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: popIn 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.winner-crown {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--coral);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.winner-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.winner-subtitle {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-muted);
}

.winner-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Vazirmatn", monospace;
  font-size: 17px;
  font-weight: 900;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-btn {
  border: none;
  border-radius: var(--radius-sm);
  background: var(--mint-deep);
  color: #fff;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* Final Results */
.results-card {
  border-top: 4px solid var(--amber);
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.results-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
}

.results-badge {
  background: var(--mint-soft);
  color: var(--mint-deep);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 999px;
}

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

.winner-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.winner-row:first-child {
  background: linear-gradient(135deg, rgba(250, 235, 149, 0.5) 0%, rgba(245, 196, 107, 0.25) 100%);
  border-color: var(--amber);
}

.winner-rank {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--coral);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.winner-row-id {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Vazirmatn", monospace;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
}

.winner-row-chances {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.results-actions {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.results-actions .primary-btn {
  margin-top: 0;
}

.full-width-btn {
  margin-top: 10px;
  width: 100%;
  padding: 8px;
}
