:root {
  --tier-s: #ff7f7f;
  --tier-a: #ffbf7f;
  --tier-b: #ffdf7f;
  --tier-c: #ffff7f;
  --tier-d: #bfff7f;
  --tier-f: #7fbfff;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-item: #2a2a4a;
  --text-light: #ffffff;
  --text-muted: #888;
  --border-color: #0f3460;
}

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

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

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
}

header h1 {
  font-size: 1.5rem;
}

nav {
  display: flex;
  gap: 12px;
}

/* Buttons */
button {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background-color 0.2s, transform 0.1s;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button.primary, nav button, .actions button:first-child {
  background-color: #4CAF50;
  color: white;
}

button.primary:hover, nav button:hover {
  background-color: #45a049;
}

button.secondary {
  background-color: #2196F3;
  color: white;
}

button.secondary:hover {
  background-color: #1e88e5;
}

button.danger {
  background-color: #f44336;
  color: white;
}

/* Main Content */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.loading {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
  font-size: 1.2rem;
}

/* Tier List Header */
.tier-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.tier-list-header h2 {
  font-size: 1.5rem;
}

.actions {
  display: flex;
  gap: 12px;
}

/* Tier List */
.tier-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-color: var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

/* Tier Row */
.tier-row {
  display: flex;
  min-height: 100px;
  background-color: var(--bg-card);
}

.tier-label {
  width: 80px;
  min-width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: bold;
  color: #000;
}

.tier-label.tier-s { background-color: var(--tier-s); }
.tier-label.tier-a { background-color: var(--tier-a); }
.tier-label.tier-b { background-color: var(--tier-b); }
.tier-label.tier-c { background-color: var(--tier-c); }
.tier-label.tier-d { background-color: var(--tier-d); }
.tier-label.tier-f { background-color: var(--tier-f); }

.tier-content {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  padding: 8px;
  min-height: 100px;
  transition: background-color 0.2s;
}

.tier-content.drag-over {
  background-color: rgba(255, 255, 255, 0.1);
}

/* Chain Item */
.chain-item {
  width: 80px;
  height: 80px;
  background-color: var(--bg-item);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: transform 0.2s, box-shadow 0.2s;
  padding: 8px;
  text-align: center;
  user-select: none;
}

.chain-item:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

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

.chain-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 4px;
}

.chain-item .name {
  font-size: 0.65rem;
  font-weight: 500;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-top: 4px;
}

.chain-item .name.fallback {
  font-size: 0.7rem;
}

/* Custom Tooltip */
.chain-item {
  position: relative;
}

.chain-item::after {
  content: attr(data-name);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 100;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.chain-item::before {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: rgba(0, 0, 0, 0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  pointer-events: none;
  z-index: 100;
  margin-bottom: -4px;
}

.chain-item:hover::after,
.chain-item:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Unranked Pool */
.unranked-pool {
  margin-top: 24px;
  background-color: var(--bg-card);
  border: 2px dashed var(--border-color);
  border-radius: 8px;
  padding: 16px;
}

.unranked-pool h3 {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 1rem;
  font-weight: 500;
}

.unranked-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 100px;
}

/* Global Rankings */
.global-rankings {
  margin-top: 20px;
}

.global-header {
  margin-bottom: 24px;
}

.global-header h2 {
  margin-bottom: 8px;
}

.global-stats {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.global-item {
  position: relative;
}

.global-item .score {
  position: absolute;
  top: 4px;
  right: 4px;
  background-color: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: bold;
  color: #4CAF50;
}

.global-item .votes {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.no-rankings {
  text-align: center;
  padding: 60px;
  color: var(--text-muted);
}

.no-rankings p {
  margin-bottom: 8px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background-color: var(--bg-card);
  padding: 32px;
  border-radius: 12px;
  max-width: 500px;
  width: 90%;
  text-align: center;
}

.modal-content h2 {
  margin-bottom: 16px;
}

.modal-content p {
  color: var(--text-muted);
  margin-bottom: 16px;
}

.share-url-container {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.share-url-container input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--bg-dark);
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Error Message */
.error-message {
  text-align: center;
  padding: 60px;
}

.error-message h2 {
  margin-bottom: 16px;
  color: #f44336;
}

.error-message p {
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* Responsive */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    gap: 16px;
    text-align: center;
  }

  .tier-label {
    width: 50px;
    min-width: 50px;
    font-size: 1.5rem;
  }

  .chain-item {
    width: 70px;
    height: 70px;
  }

  .chain-item .name {
    font-size: 0.65rem;
  }

  .tier-list-header {
    flex-direction: column;
    text-align: center;
  }
}
