:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #6b7280;
  --secondary-hover: #4b5563;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1, .logo {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.logo:hover {
  opacity: 0.9;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* Cards */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.card h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: var(--text);
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  margin-bottom: 0.75rem;
}

/* Checkbox */
.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: normal;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--primary);
}

/* Options Input */
.option-input {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.option-input input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
}

.option-input input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
  background: var(--danger);
  color: white;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--secondary);
  color: white;
}

/* Link Box */
.link-box {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.link-box input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}

/* Sortable List */
.sortable-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sortable-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.sortable-item:hover {
  border-color: var(--primary);
}

.sortable-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.sortable-item.unranked {
  opacity: 0.6;
  border-style: dashed;
}

.sortable-item .drag-handle {
  color: var(--text-muted);
  font-size: 1.25rem;
}

.sortable-item .rank {
  font-weight: 700;
  color: var(--primary);
  min-width: 2rem;
  text-align: center;
}

.sortable-item .option-text {
  flex: 1;
}

.sortable-item .unrank-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  background: var(--border);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
}

.sortable-item .unrank-btn:hover {
  background: var(--secondary);
  color: white;
}

/* Options Display (read-only list) */
.options-display {
  list-style: none;
  padding: 0;
  margin: 0;
}

.options-display li {
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Results */
.ranking-list {
  list-style: none;
  counter-reset: ranking;
  padding: 0;
}

.ranking-list li {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  margin-bottom: 0.5rem;
  background: var(--bg);
  border-radius: var(--radius);
  counter-increment: ranking;
}

.ranking-list li::before {
  content: counter(ranking);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
  min-width: 2rem;
  text-align: center;
}

.ranking-list li:first-child {
  background: linear-gradient(135deg, #fef3c7, #fde68a);
  border: 2px solid #f59e0b;
}

.ranking-list li:first-child::before {
  color: #b45309;
}

/* Matrix Table */
.table-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.matrix-table th,
.matrix-table td {
  padding: 0.5rem;
  text-align: center;
  border: 1px solid var(--border);
}

.matrix-table th {
  background: var(--bg);
  font-weight: 600;
}

.matrix-table td.win {
  background: #d1fae5;
  color: #065f46;
  font-weight: 600;
}

.matrix-table td.lose {
  background: #fee2e2;
  color: #991b1b;
}

.matrix-table td.tie {
  background: #fef3c7;
  color: #92400e;
}

.matrix-table td.self {
  background: var(--border);
}

/* Results Section */
.results-section {
  margin-bottom: 2rem;
}

.results-section h3 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
  color: var(--text);
}

/* Form Actions */
.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* Add Option Row */
.add-option-row {
  display: flex;
  gap: 0.5rem;
}

.add-option-row input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
}

/* Utility */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

/* Footer */
footer {
  text-align: center;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
}

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

/* Responsive */
@media (max-width: 600px) {
  .container {
    padding: 1rem;
  }

  .card {
    padding: 1.5rem;
  }

  .form-actions {
    flex-direction: column;
  }

  .form-actions .btn {
    width: 100%;
  }

  .link-box {
    flex-direction: column;
  }

  .matrix-table {
    font-size: 0.75rem;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 0.25rem;
  }
}
