:root {
  --color-bg: #171320;
  --color-text: #F9F4DB;
  --color-border: #55305e;
  --color-border-active: #D9A68A;

  --color-absent: #2C1E49;
  --color-present: #caa662;
  --color-correct: #538D4E;

  --color-key-bg: #743e6e;


  --color-avatar-bg: #3a3a3c;
  --color-avatar-text: #D9A68A;
}

* { box-sizing: border-box; }

/* Loading screen */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: var(--color-bg);
  color: var(--color-text);
  z-index: 100;
}

.loading-screen[hidden] { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-border);
  border-top-color: var(--color-border-active);
  border-radius: 50%;
  animation: 0.8s spin linear infinite;
}

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

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

.game {
  display: flex;
  height: 100vh;
}

/* Sidebar: remove scrolling and use flex layout */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 0.5rem; /* Remove horizontal padding so scrollbar hits the edge */
  width: 160px;
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid var(--color-border);
}

.sidebar > *:not(#playersList) {
  padding-inline: 0.5rem; /* Restore horizontal padding for non-scrolling items */
}

#playersList {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
  flex: 1;
  padding-inline: 1rem; /* Push content away from the edge */
}

#playersList::-webkit-scrollbar {
  width: 6px;
}

#playersList::-webkit-scrollbar-track {
  background: transparent;
}

#playersList::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

#playersList::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-active);
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.player-info {
  display: flex;
  flex-direction: row;
  gap: 0.7rem;
  justify-content: center;
  align-items: center;
}

.player.is-active { border-color: var(--color-border-active); }

.player-streak {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-border-active);
}

.divider {
  height: 1px;
  background: var(--color-border);
  margin: 0 0.5rem;
}

.player-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-avatar-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  color: var(--color-avatar-text);
}

.player-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.player-board {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 80%;
}

.mini-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
}

.mini-tile {
  aspect-ratio: 1;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}

.mini-tile.is-absent { background: var(--color-absent); }
.mini-tile.is-present { background: var(--color-present); }
.mini-tile.is-correct { background: var(--color-correct); }
.mini-tile.is-typed { border-color: var(--color-border-active); }

.mini-tile.is-absent,
.mini-tile.is-present,
.mini-tile.is-correct {
  border: none;
}

.streak-section {
  margin-top: auto;
  padding: 0.5rem 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--color-border);
}

.streak-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.streak-item p {
  margin: 0;
  font-size: 0.8rem;
}

.streak-value {
  font-weight: 700;
  color: var(--color-border-active);
}

/* Board */
.board-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  min-width: 0;

  gap: 1rem;
}

.message {
  min-height: 1.2rem;
  margin: 0;
  font-weight: 600;
  position: absolute;

  padding: 0.2rem 0.4rem;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
}

.board {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: auto 0;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.tile {
  width: 62px;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  color: var(--color-text);
}

.tile.is-filled { border-color: var(--color-border-active); }
.tile.is-absent { background: var(--color-absent); border-color: var(--color-absent); }
.tile.is-present { background: var(--color-present); border-color: var(--color-present); }
.tile.is-correct { background: var(--color-correct); border-color: var(--color-correct); }

.board-row.is-shake { animation: 0.4s shake; }

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.tile.is-flip { animation: 0.5s flip ease; }

@keyframes flip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0deg); }
}

/* Keyboard */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 480px;
}

.keyboard-row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.key {
  flex: 1;
  min-width: 0;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 4px;
  background: var(--color-key-bg);
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}

.key.is-absent { background: var(--color-absent); }
.key.is-present { background: var(--color-present); }
.key.is-correct { background: var(--color-correct); }

.key-wide { flex: 1.5; font-size: 0.75rem; }

.key-spacer { flex: 0.5; }

/* Bot avatar */
.bot-avatar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--color-border);
  border-radius: 50%;
  background: var(--color-absent);
  overflow: hidden;
  cursor: pointer;
}

.bot-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Right sidebar */
.sidebar-right {
  border-right: 0;
  border-left: 1px solid var(--color-border);
}

.sidebar-right[hidden] { display: none; }

.sidebar-item {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.sidebar-item p {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 400;
}

.sidebar-right code {
  width: fit-content;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--color-absent);
  color: var(--color-border-active);
  font-family: monospace;
  font-size: 0.8rem;
}

.version-info {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  font-size: 1rem;
  color: var(--color-border);
}

html, body {
  overflow: hidden;
  height: 100vh;
}

@media (max-width: 700px) {
  aside.sidebar {
    display: none;
  }
}

@media (max-height: 400px) {
  .keyboard,
  .sidebar,
  .board,
  .message {
    display: none;
  }

  .board-area {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    gap: 1rem;

    &::after {
      content: "Wordle";
      font-size: 1.5rem;
      font-weight: bold;
      color: var(--color-text);
    }
  }

  .bot-avatar {
    height: 100px;
    width: 100px;
    position: static;
  }
}

/* Bump this string on every CSS edit, if it doesn't match on screen the stylesheet is stale */
.version-css::after { content: "CSS v1.0"; }
