:root {
  color-scheme: dark;
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f1218;
  color: #f4f4f6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1f2a44, #0f1218 55%);
  display: flex;
  flex-direction: column;
}

header {
  padding: 18px 8vw;
  background: rgba(15, 18, 24, 0.9);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);

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

  a {
    color: #f5d742;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    transition: background 0.2s ease;

    &:hover,
    &:focus-visible {
      background: rgba(255, 255, 255, 0.18);
    }
  }
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 16px 8vw 30px;
}

.panel {
  background: rgba(18, 22, 32, 0.92);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
}

.panel-title {
  margin: 0 0 16px;
  font-size: 1.25rem;
}

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

.difficulty-card {
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.08);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    border 0.2s ease,
    background 0.2s ease;

  &:hover {
    transform: translateY(-3px);
    background: rgba(255, 255, 255, 0.14);
  }

  &.is-selected {
    border-color: #f5d742;
    background: rgba(245, 215, 66, 0.2);
  }
}

.menu-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.game-actions {
  margin-top: 16px;
}

button {
  &.primary {
    background: #f5d742;
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    font-weight: 700;
    cursor: pointer;
    color: #1a1e26;
  }

  &.secondary {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 12px 20px;
    border-radius: 999px;
    color: inherit;
    cursor: pointer;
  }
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;

  &.switch {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 0;
    cursor: pointer;
  }
}

.toggle-row {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.switch {
  input {
    position: absolute;
    opacity: 0;
    pointer-events: none;

    &:checked + .switch-track {
      background: rgba(245, 215, 66, 0.8);

      &::after {
        transform: translateX(24px);
      }
    }

    &:focus-visible + .switch-track {
      outline: 2px solid #f5d742;
      outline-offset: 3px;
    }
  }
}

.switch-track {
  width: 52px;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
  position: relative;
  transition: background 0.2s ease;

  &::after {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f4f4f6;
    top: 3px;
    left: 3px;
    transition: transform 0.2s ease;
  }
}

.switch-label {
  font-weight: 600;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 18, 24, 0.6);
  color: inherit;
}

.game-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  align-items: center;
}

.stat {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 12px 14px;
}

.card-stage {
  position: relative;
  overflow: visible;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.is-hidden {
  display: none !important;
}

.animal-card {
  width: min(520px, 90%);
  background: rgb(40, 46, 68);
  border-radius: 20px;
  padding: 24px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: absolute;
  transition:
    transform 2s ease,
    opacity 2s ease;

  &.enter {
    transform: translateX(120%);
    opacity: 0;

    &.enter-active {
      transform: translateX(0);
      opacity: 1;
    }
  }

  &.exit {
    transform: translateX(-140%);
    opacity: 0;
  }
}

.animal-placeholder {
  min-height: 160px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.08em;

  &.is-hidden {
    display: none;
  }
}

.animal-media {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.animal-image {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
  object-fit: contain;
}

.balance-stage {
  --platform-width: 90%;
  --platform-height: 18px;
  position: relative;
  width: 100%;
  min-height: 420px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.balance-stage::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(-50%);
}

.balance-side {
  position: relative;
  min-height: 420px;
}

.platform-stack {
  position: absolute;
  width: var(--platform-width);
  height: 360px;
  left: calc(50% - var(--platform-width) / 2);
}

.platform-stack.left {
  bottom: var(--left-offset, 0%);
}

.platform-stack.right {
  bottom: var(--right-offset, 50%);
}

.platform {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: var(--platform-height);
  background: linear-gradient(180deg, #f5d742, #caa32b);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.animal-on-scale {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--platform-height));
  width: min(360px, 90%);
  border-radius: 16px;
}

.drop-highlight {
  position: absolute;
  left: 0;
  bottom: calc(var(--platform-height) + 12px);
  width: 100%;
  height: min(300px, calc(100% - var(--platform-height) - 24px));
  border-radius: 14px;
  border: 2px dashed rgba(76, 207, 108, 0.75);
  background: rgba(76, 207, 108, 0.15);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.drop-highlight.is-active {
  opacity: 1;
}

.balance-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 120px;
  height: 120px;
  transform: translate(-50%, -100%) rotate(var(--arrow-rotation, -90deg));
  transform-origin: 50% 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.arrow-body {
  width: 12px;
  height: 100px;
  background: #f4f4f6;
}

.arrow-head {
  width: 0;
  height: 0;
  border-left: 18px solid transparent;
  border-right: 18px solid transparent;
  border-bottom: 26px solid #ff595e;
  margin-top: -6px;
}

.weights-area {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 16px;
}

.weights-rack {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  z-index: 2;
}

.mode-animals .weights-area {
  min-height: 250px;
}

.mode-animals .weights-rack {
  display: block;
  width: 100%;
  min-height: 250px;
}

.weight-column {
  position: relative;
  display: block;
}

.weight-block {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--weight-color, #4d6a90);
  color: #f4f4f6;
  font-weight: 700;
  width: var(--weight-width);
  height: var(--weight-height);
  border-radius: 10px;
  cursor: grab;
  user-select: none;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.35);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.weight-block::before {
  content: "";
  position: absolute;
  top: calc(-1 * var(--weight-head-height));
  left: 50%;
  transform: translateX(-50%);
  width: var(--weight-head-width);
  height: var(--weight-head-height);
  background: inherit;
  border-radius: 8px;
}

.weight-block.is-dragging {
  cursor: grabbing;
  transform: scale(1.05);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45);
  z-index: 5;
}

.animal-block {
  background-color: var(--animal-color, #4d6a90);
  background-image: var(--animal-image);
  background-size: cover;
  background-position: center;
  color: transparent;
  border: 2px solid rgba(255, 255, 255, 0.35);
  text-shadow: none;
}

.animal-block::before {
  display: none;
}

.mode-description {
  margin-top: 12px;
  color: rgba(255, 255, 255, 0.7);
}

.mode-weights #weight-input {
  display: none;
}

.mode-weights #weight-label {
  display: none;
}

.hint {
  min-height: 24px;
  color: #ffd166;
  margin-top: 10px;
  margin-bottom: 0px;
}

.attempts {
  display: flex;
  gap: 6px;
}

.attempt-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);

  &.is-remaining {
    background: #4cc9f0;
  }
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;

  &.hidden {
    display: none;
  }
}

.modal {
  background: #141a26;
  border-radius: 18px;
  padding: 24px;
  max-width: 560px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;

  th,
  td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.12);
}

.error {
  color: #ff7b7b;
  min-height: 20px;
}

@media (max-width: 720px) {
  header {
    flex-direction: column;
    gap: 12px;
  }
}
