:root {
  --bg: #f7f4ee;
  --panel: #ffffff;
  --ink: #1d2428;
  --muted: #657076;
  --line: #dcd4c9;
  --accent: #0e8f7d;
  --accent-dark: #086d60;
  --rose: #d94d62;
  --gold: #f6b73c;
  --blue: #315caa;
  --shadow: 0 24px 70px rgba(29, 36, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(14, 143, 125, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(217, 77, 98, 0.1), transparent 30%),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(310px, 420px) minmax(0, 1fr);
  gap: 20px;
  min-height: calc(100vh - 48px);
}

.panel,
.setup-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(220, 212, 201, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.setup-panel {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--blue));
}

.brand p,
.brand span,
.eyebrow,
.winner-details p,
.winner-details span,
.muted {
  margin: 0;
}

.brand p {
  font-weight: 800;
}

.brand span,
.muted,
.winner-details span {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 8px;
}

label,
.rule-group h2,
.section-heading h2 {
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

textarea {
  min-height: 170px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 143, 125, 0.14);
}

.import-row,
.grid-2,
.section-heading,
.stats {
  display: flex;
  gap: 10px;
}

.grid-2 > * {
  flex: 1;
}

#fileInput {
  display: none;
}

.file-button,
.ghost-button,
.download-button,
.primary-button,
.draw-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  min-height: 44px;
  padding: 0 16px;
}

.file-button,
.ghost-button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: #eee7de;
  text-decoration: none;
}

.ghost-button.compact,
.download-button.compact {
  min-height: 34px;
  padding: 0 12px;
}

.primary-button,
.draw-button {
  color: #fff;
  background: var(--accent);
}

.primary-button:hover,
.draw-button:hover {
  background: var(--accent-dark);
}

.draw-button:disabled {
  cursor: not-allowed;
  background: #a8b9b5;
}

.import-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee7de;
}

.mode-button {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 800;
  background: transparent;
}

.mode-button.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 4px 18px rgba(29, 36, 40, 0.08);
}

.source-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fffaf3;
}

.source-card.hidden {
  display: none;
}

.extension-card {
  background: #f7fbfa;
}

.connection-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.connection-line span,
.helper-text {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.helper-text {
  margin: 0;
}

.helper-text.success {
  color: var(--accent-dark);
  font-weight: 700;
}

.helper-text.warning {
  color: #9a5b00;
  font-weight: 700;
}

.rule-group {
  display: grid;
  gap: 10px;
}

.rule-group h2,
.section-heading h2 {
  margin: 0;
}

.radio-card,
.toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  text-transform: none;
}

.radio-card span,
.toggle span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.radio-card strong {
  display: block;
  color: var(--ink);
  font-size: 0.95rem;
}

.draw-area {
  display: grid;
  grid-template-rows: auto minmax(340px, 1fr) auto;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 92px;
}

.eyebrow {
  color: var(--rose);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 6px 0 0;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 0.95;
}

.stats > div {
  min-width: 112px;
  border-left: 1px solid var(--line);
  padding-left: 14px;
}

.stats strong {
  display: block;
  font-size: 1.7rem;
}

.stats span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.stage {
  display: grid;
  place-items: center;
  min-height: 420px;
  border: 1px solid rgba(220, 212, 201, 0.85);
  border-radius: 8px;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(49, 92, 170, 0.16) 0 1px, transparent 1px 64px),
    linear-gradient(rgba(49, 92, 170, 0.12) 0 1px, transparent 1px 64px),
    #fffaf3;
}

.winner-card {
  width: min(680px, calc(100% - 32px));
  padding: 28px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 30px 90px rgba(29, 36, 40, 0.16);
  text-align: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--blue);
}

.slot-window {
  height: 86px;
  margin: 24px 0 18px;
  overflow: hidden;
  border-block: 1px solid var(--line);
  background: linear-gradient(#fff, #faf4eb);
}

.slot-track {
  transform: translateY(0);
}

.slot-track.spinning {
  transition: transform 3s cubic-bezier(0.12, 0.68, 0.16, 1);
}

.slot-item {
  display: grid;
  place-items: center;
  height: 86px;
  color: var(--ink);
  font-size: clamp(1.6rem, 4vw, 3rem);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 18px;
}

.slot-item.empty {
  color: var(--muted);
  font-size: 1.1rem;
}

.winner-details p {
  font-size: clamp(1.8rem, 5vw, 4rem);
  font-weight: 800;
  line-height: 1;
}

.winner-details span {
  display: block;
  min-height: 42px;
  margin: 12px auto 22px;
  max-width: 58ch;
  line-height: 1.4;
}

.draw-button {
  min-width: 180px;
  min-height: 54px;
  font-size: 1.05rem;
}

.winner-card.celebrate {
  animation: pop 560ms ease both;
}

@keyframes pop {
  0% {
    transform: scale(0.98);
  }
  55% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.results-grid .panel {
  min-height: 230px;
  padding: 18px;
}

.section-heading {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.entry-list,
.history-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.entry,
.history-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.entry strong,
.history-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry span,
.history-item span {
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .workspace,
  .results-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

  .stats > div {
    flex: 1;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 12px;
  }

  .setup-panel,
  .winner-card,
  .results-grid .panel {
    padding: 16px;
  }

  .grid-2,
  .import-row,
  .stats {
    flex-direction: column;
  }

  .stats > div {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding: 10px 0 0;
  }

  .stage {
    min-height: 360px;
  }
}
