:root {
  color-scheme: dark;
  --bg: #06070f;
  --surface: rgba(18, 20, 40, 0.68);
  --surface-strong: rgba(26, 29, 58, 0.92);
  --border: rgba(142, 152, 255, 0.16);
  --border-strong: rgba(142, 152, 255, 0.32);
  --text: #eef0ff;
  --muted: #9aa2c9;
  --primary: #7c5cff;
  --primary-2: #21d4fd;
  --accent: #b388ff;
  --danger: #ff5c7a;
  --success: #3ddc97;
  --radius: 20px;
  --shadow: 0 28px 70px -26px rgba(0, 0, 0, 0.85);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.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;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  padding: clamp(1rem, 2.5vw, 2.5rem);
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -12%, rgba(124, 92, 255, 0.22), transparent 60%),
    radial-gradient(900px 620px at 105% 8%, rgba(33, 212, 253, 0.16), transparent 55%),
    radial-gradient(800px 800px at 50% 120%, rgba(179, 136, 255, 0.14), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  overflow-x: hidden;
}

.aurora {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.42;
  animation: float 18s ease-in-out infinite;
}

.blob-1 {
  width: 38vw;
  height: 38vw;
  top: -10%;
  left: -8%;
  background: #6d4dff;
}

.blob-2 {
  width: 32vw;
  height: 32vw;
  top: 30%;
  right: -10%;
  background: #0aa7cf;
  animation-delay: -6s;
}

.blob-3 {
  width: 30vw;
  height: 30vw;
  bottom: -14%;
  left: 30%;
  background: #9d5cff;
  animation-delay: -12s;
}

@keyframes float {
  0%,
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  50% {
    transform: translate3d(2vw, -3vh, 0) scale(1.08);
  }
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: clamp(1.25rem, 2.5vw, 2rem);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4.6vw, 3.6rem);
  line-height: 1.04;
  letter-spacing: -0.03em;
  background: linear-gradient(115deg, #ffffff 10%, #c9c3ff 45%, #6fe6ff 90%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  margin: 0.7rem 0 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: clamp(0.92rem, 1.2vw, 1.05rem);
}

.header-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.sound-btn {
  min-width: 132px;
}

.sound-btn[aria-pressed="true"] {
  border-color: rgba(61, 220, 151, 0.4);
  background: rgba(61, 220, 151, 0.12);
  color: #b6ffe1;
}

.pool-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  min-width: 140px;
  padding: 1rem 1.4rem;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.pool-number {
  font-size: clamp(2rem, 3.4vw, 2.9rem);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  transition: transform 0.25s ease;
}

.pool-number.pulse {
  animation: pop 0.45s ease;
}

.pool-label {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

@keyframes pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.28);
  }
  100% {
    transform: scale(1);
  }
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(320px, 0.78fr);
  gap: clamp(1rem, 2vw, 1.5rem);
  align-items: start;
}

.panel {
  position: relative;
  padding: clamp(1rem, 2vw, 1.5rem);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
}

.draw-panel {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.draw-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.draw-form label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.input-row {
  display: flex;
  gap: 0.65rem;
}

input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 0.95rem 1.1rem;
  font: inherit;
  font-size: 1.02rem;
  color: var(--text);
  background: rgba(8, 10, 22, 0.72);
  border: 1px solid var(--border);
  border-radius: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

input[type="text"]::placeholder {
  color: rgba(154, 162, 201, 0.62);
}

input[type="text"]:focus {
  border-color: var(--primary);
  background: rgba(10, 12, 26, 0.92);
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.18);
}

input[type="text"].shake {
  animation: shake 0.35s ease;
  border-color: var(--danger);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-3px);
  }
}

.form-message {
  min-height: 1.15rem;
  margin: 0;
  font-size: 0.86rem;
  color: var(--danger);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.form-message.visible {
  opacity: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 0.9rem 1.25rem;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.11);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(124, 92, 255, 0.28);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  border: none;
  background: linear-gradient(135deg, var(--primary) 0%, #5f7bff 48%, var(--primary-2) 100%);
  background-size: 180% 180%;
  box-shadow: 0 16px 34px -16px rgba(124, 92, 255, 0.9);
}

.btn-primary:hover:not(:disabled) {
  background-position: 100% 50%;
  background-color: transparent;
}

.btn-ghost {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.03);
}

.btn-small {
  padding: 0.55rem 0.95rem;
  border-radius: 11px;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-danger {
  border-color: rgba(255, 92, 122, 0.35);
  background: rgba(255, 92, 122, 0.1);
  color: #ffafbd;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(255, 92, 122, 0.2);
}

.stage {
  perspective: 1200px;
}

.stage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 265px;
  padding: 2rem 1.4rem;
  text-align: center;
  border-radius: 18px;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at 50% 0%, rgba(124, 92, 255, 0.2), transparent 62%),
    linear-gradient(160deg, rgba(24, 27, 55, 0.85), rgba(10, 12, 26, 0.72));
  overflow: hidden;
  transform-style: preserve-3d;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.stage-card::after {
  content: "";
  position: absolute;
  inset: -40% -10%;
  background: conic-gradient(from 0deg, transparent, rgba(124, 92, 255, 0.16), transparent 30%);
  opacity: 0;
  transition: opacity 0.4s ease;
  animation: spin 6s linear infinite;
  pointer-events: none;
}

.stage-card.is-drawing {
  border-color: rgba(124, 92, 255, 0.5);
  box-shadow: 0 0 0 1px rgba(124, 92, 255, 0.2), 0 0 60px -18px rgba(124, 92, 255, 0.8);
}

.stage-card.is-drawing::after {
  opacity: 1;
}

.stage-card.is-suspense {
  animation: suspensePulse 0.42s ease;
  border-color: rgba(33, 212, 253, 0.55);
  box-shadow: 0 0 0 1px rgba(33, 212, 253, 0.25), 0 0 70px -16px rgba(33, 212, 253, 0.85);
}

@keyframes suspensePulse {
  0% {
    transform: scale(1);
  }
  55% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

.stage-card.reveal {
  animation: revealCard 0.65s cubic-bezier(0.22, 1.4, 0.36, 1);
  border-color: rgba(61, 220, 151, 0.45);
}

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

@keyframes revealCard {
  0% {
    transform: rotateX(12deg) scale(0.92);
    opacity: 0.4;
  }
  60% {
    transform: rotateX(0) scale(1.035);
  }
  100% {
    transform: rotateX(0) scale(1);
    opacity: 1;
  }
}

.stage-label {
  margin: 0;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.stage-theme {
  margin: 0.15rem 0;
  font-size: clamp(1.7rem, 3.2vw, 2.8rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  color: #ffffff;
  text-shadow: 0 10px 40px rgba(124, 92, 255, 0.45);
}

.stage-team {
  margin: 0;
  min-height: 1.2rem;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--accent);
}

.pattern-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: #dfe3ff;
  background: rgba(124, 92, 255, 0.16);
  border: 1px solid rgba(142, 152, 255, 0.28);
  border-radius: 999px;
}

.stage-extra {
  margin: 0.35rem 0 0;
  max-width: 40ch;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.controls .btn {
  flex: 1;
}

.history-panel {
  display: flex;
  flex-direction: column;
  max-height: min(72vh, 760px);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0 0.6rem;
  font-size: 0.82rem;
  font-weight: 800;
  color: #cfd3ff;
  background: rgba(124, 92, 255, 0.16);
  border: 1px solid rgba(142, 152, 255, 0.26);
  border-radius: 999px;
}

.history {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(124, 92, 255, 0.5) transparent;
}

.history::-webkit-scrollbar {
  width: 8px;
}

.history::-webkit-scrollbar-thumb {
  background: rgba(124, 92, 255, 0.45);
  border-radius: 999px;
}

.history-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border);
  animation: slideIn 0.35s ease both;
}

.history-index {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.9rem;
  height: 1.9rem;
  font-size: 0.78rem;
  font-weight: 800;
  color: #cfd3ff;
  background: rgba(124, 92, 255, 0.18);
  border-radius: 10px;
}

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

.history-team {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-theme {
  margin: 0.15rem 0 0.35rem;
  font-size: 0.84rem;
  color: var(--muted);
}

.history-patterns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.history-patterns .chip {
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
}

.repeat-tag {
  margin-left: 0.35rem;
  padding: 0.08rem 0.4rem;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ffd7a1;
  background: rgba(255, 170, 60, 0.16);
  border: 1px solid rgba(255, 170, 60, 0.35);
  border-radius: 999px;
  vertical-align: middle;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.empty-state {
  margin: 1rem 0 0;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: clamp(1.25rem, 2.5vw, 2rem);
  padding: 0.9rem 1.1rem;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.footer-groups {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.export-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.export-label {
  margin-right: 0.2rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.modal-backdrop,
.results-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 5, 12, 0.78);
  backdrop-filter: blur(12px);
}

.modal-backdrop {
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal {
  width: min(440px, 100%);
  padding: 1.5rem;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  animation: revealCard 0.3s ease;
}

.modal h2 {
  margin: 0 0 0.5rem;
  font-size: 1.3rem;
}

.modal p {
  margin: 0 0 1.2rem;
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.results-overlay {
  display: flex;
  flex-direction: column;
  padding: clamp(1rem, 3vw, 2.5rem);
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(124, 92, 255, 0.2), transparent 60%),
    rgba(4, 5, 12, 0.94);
}

.results-overlay:fullscreen {
  padding: clamp(1.5rem, 3.5vw, 3rem);
}

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: clamp(1rem, 2vw, 1.6rem);
}

.results-header h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2.4rem);
  letter-spacing: -0.02em;
}

.results-meta {
  margin: 0.45rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.results-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.results-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(12, 14, 30, 0.72);
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.95rem, 1.45vw, 1.5rem);
}

.results-table th,
.results-table td {
  padding: clamp(0.7rem, 1.4vw, 1.1rem) clamp(0.8rem, 1.8vw, 1.4rem);
  text-align: left;
  vertical-align: top;
}

.results-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.78em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(16, 18, 38, 0.98);
  border-bottom: 1px solid var(--border-strong);
}

.results-table tbody tr {
  border-bottom: 1px solid rgba(142, 152, 255, 0.08);
}

.results-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.025);
}

.results-table tbody tr:last-child {
  border-bottom: none;
}

.results-table td:first-child {
  width: 1%;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.results-table td:nth-child(2) {
  font-weight: 700;
}

.results-table td:nth-child(3) {
  color: #dfe3ff;
}

.results-table .pattern-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.results-table .chip {
  font-size: 0.85em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 80;
  padding: 0.75rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #e9ecff;
  background: rgba(28, 31, 60, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.confetti-piece {
  position: fixed;
  top: -16px;
  z-index: 70;
  width: 8px;
  height: 14px;
  border-radius: 2px;
  pointer-events: none;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  0% {
    transform: translate3d(0, -10vh, 0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translate3d(var(--drift, 0px), 110vh, 0) rotate(720deg);
    opacity: 0;
  }
}

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

  .history-panel {
    max-height: 420px;
  }
}

@media (max-width: 620px) {
  .input-row {
    flex-direction: column;
  }

  .app-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .export-group {
    justify-content: center;
  }
}

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