:root {
  color-scheme: dark;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  --page: #050816;
  --surface: #0b1220;
  --surface-raised: #0f172a;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.2);
  --cyan: #38bdf8;
  --indigo: #6366f1;
}

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

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgba(99, 102, 241, 0.14), transparent 34rem),
    var(--page);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button,
a,
input,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(56, 189, 248, 0.7);
  outline-offset: 3px;
}

.app-shell {
  width: min(96vw, 1680px);
  margin: 0 auto;
  padding: 32px 16px 64px;
}

.app-header {
  position: relative;
  overflow: hidden;
  padding: 22px 24px 26px;
  border-radius: 20px;
  background: radial-gradient(circle at top left, rgba(99, 102, 241, 0.9), rgba(37, 99, 235, 0.75));
  box-shadow: 0 35px 80px rgba(5, 8, 22, 0.55);
  color: #fff;
}

.app-header::after {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 80% 30%, rgba(56, 189, 248, 0.45), transparent 60%);
  content: "";
  pointer-events: none;
}

.back-link,
.title-block {
  position: relative;
  z-index: 1;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
}

.back-link:hover {
  color: #fff;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.35);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 8px 0 6px;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  line-height: 1.15;
}

.title-block p {
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.95rem;
}

main {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 32px;
}

.panel,
.results-panel,
.history-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(2, 6, 23, 0.55);
}

.panel {
  padding: 20px;
  border-radius: 18px;
  background: var(--surface-raised);
}

#assignment-form,
.field {
  display: flex;
  flex-direction: column;
}

#assignment-form {
  gap: 16px;
}

.field {
  gap: 8px;
}

.field label {
  font-weight: 600;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.count-pill,
.alpha-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--text);
  font-weight: 700;
}

textarea,
input {
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

textarea:focus,
input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
  outline: none;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

.group-count-field input,
.numbered-list-field input {
  max-width: 140px;
}

.numbered-list-control {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
}

.field-hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.inline-error {
  margin: 0;
  color: #fbbf24;
  font-size: 0.9rem;
}

.primary-button,
.secondary-button,
.ghost-button,
.view-toggle button {
  border: 0;
  cursor: pointer;
  font-weight: 700;
}

.primary-button {
  min-height: 48px;
  padding: 12px 18px;
  border-radius: 12px;
  background: linear-gradient(120deg, var(--cyan), var(--indigo));
  color: #08111f;
  transition: transform 120ms ease, opacity 160ms ease;
}

.secondary-button {
  min-height: 44px;
  padding: 9px 18px;
  border-radius: 12px;
  background: rgba(56, 189, 248, 0.16);
  color: #e0f2fe;
  border: 1px solid rgba(56, 189, 248, 0.45);
  transition: background 160ms ease, border-color 160ms ease;
}

.secondary-button:hover {
  background: rgba(56, 189, 248, 0.24);
  border-color: rgba(56, 189, 248, 0.7);
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.results-panel,
.history-panel {
  padding: 28px;
  border-radius: 22px;
}

.results-panel {
  min-height: 280px;
  border-color: rgba(99, 102, 241, 0.22);
}

.empty-state {
  margin: 0;
  padding: 30px 0;
  color: #71809e;
  text-align: center;
}

.meta-row {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.meta-list {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  margin: 0;
}

.meta-list dt {
  color: #8b9bbb;
  font-size: 0.82rem;
}

.meta-list dd {
  margin: 3px 0 0;
  font-weight: 700;
}

.view-toggle {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.75);
}

.view-toggle button {
  padding: 7px 14px;
  border-radius: 999px;
  background: transparent;
  color: #cbd5e1;
}

.view-toggle button.active {
  background: linear-gradient(120deg, var(--cyan), var(--indigo));
  box-shadow: 0 8px 18px rgba(56, 189, 248, 0.28);
  color: #08111f;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 24px;
  align-items: stretch;
}

.group-card {
  grid-column: span 2;
  overflow: hidden;
  border: 1px solid var(--group-color);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.95);
  box-shadow: 0 18px 45px rgba(2, 6, 23, 0.55);
}

.group-grid[data-count="1"] .group-card {
  grid-column: 1 / -1;
}

.group-grid[data-count="2"] .group-card,
.group-grid[data-count="4"] .group-card,
.group-card:nth-last-child(2):nth-child(3n + 1),
.group-card:nth-last-child(2):nth-child(3n + 1) ~ .group-card {
  grid-column: span 3;
}

.group-grid:not([data-count="4"]) .group-card:last-child:nth-child(3n + 1) {
  grid-column: 1 / -1;
}

.group-grid.dense {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.group-grid.dense .group-card {
  grid-column: auto;
}

.group-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--group-color);
  color: #fff;
  font-weight: 700;
}

.group-card-header small {
  font-weight: 600;
  opacity: 0.9;
}

.group-card ul {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 10px;
  margin: 0;
  padding: 16px;
  list-style: none;
}

.group-card li {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 74px;
  padding: 8px 12px;
  overflow-wrap: anywhere;
  border-radius: 10px;
  background: rgba(55, 65, 81, 0.7);
  color: #f8fafc;
  font-size: clamp(1.5rem, 3vw, 2.75rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
}

.group-card .empty-group {
  color: var(--muted);
  font-size: 1rem;
  font-weight: 500;
}

.alpha-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.alpha-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.85rem;
}

.alpha-list {
  margin: 0;
  padding: 16px;
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.45);
  column-count: 4;
  column-gap: 12px;
  list-style: none;
}

.alpha-item {
  display: grid;
  grid-template-columns: minmax(2.1ch, max-content) max-content;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  margin-bottom: 10px;
  padding: 8px 10px;
  break-inside: avoid;
  column-gap: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.82);
}

.alpha-name {
  overflow-wrap: anywhere;
  color: #f8fafc;
  font-size: 2rem;
  font-weight: 750;
  line-height: 1;
  text-align: right;
}

.alpha-group {
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--group-color);
  color: #fff;
  font-size: 1rem;
  font-weight: 750;
  line-height: 1;
  white-space: nowrap;
}

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

.history-header h2 {
  margin: 0;
}

.ghost-button {
  padding: 9px 16px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.history-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.65);
}

.history-item-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-item-header strong,
.history-item-header time {
  display: block;
}

.history-item-header time {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.85rem;
}

.history-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: #a5b4fc;
  font-size: 0.88rem;
}

.history-groups {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.history-chip {
  display: flex;
  align-items: stretch;
  min-width: 140px;
  overflow: hidden;
  border: 1px solid var(--group-color);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
}

.history-chip-label {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  background: var(--group-color);
  color: #fff;
  font-weight: 700;
}

.history-chip-members {
  padding: 8px 10px;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
}

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

[hidden] {
  display: none !important;
}

@media (min-width: 960px) {
  .meta-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (min-width: 1400px) {
  .alpha-list {
    column-count: 5;
  }
}

@media (max-width: 960px) {
  .group-grid,
  .group-grid.dense {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .group-grid > .group-card {
    grid-column: span 1 !important;
  }

  .group-grid .group-card:last-child:nth-child(odd) {
    grid-column: 1 / -1 !important;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: 100%;
    padding: 16px 12px 40px;
  }

  .app-header {
    padding: 18px;
  }

  .title-block p {
    font-size: 0.88rem;
  }

  main {
    margin-top: 20px;
    gap: 18px;
  }

  .results-panel,
  .history-panel {
    padding: 18px;
  }

  .alpha-list {
    column-count: 1;
  }
}

@media (max-width: 640px) {
  .group-grid,
  .group-grid.dense {
    grid-template-columns: 1fr;
  }

  .group-grid > .group-card {
    grid-column: 1 / -1 !important;
  }

  .history-chip {
    width: 100%;
  }
}

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