.game {
  display: grid;
  gap: 20px;
}

/* ---------- level list ---------- */

.levels {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin: 20px 0 0;
  padding: 0;
  list-style: none;
}

.level {
  appearance: none;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: rgb(25 25 28 / 0.34);
  color: var(--paper);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background-color 0.15s, box-shadow 0.15s;
}

.level:hover:not([disabled]) {
  background: rgb(25 25 28 / 0.5);
}

.level[disabled] {
  cursor: default;
  color: rgb(255 255 255 / 0.4);
  background: rgb(25 25 28 / 0.18);
}

.level[data-status='solved'] {
  background: var(--done);
  color: var(--ink);
}

.level[aria-current='step'] {
  box-shadow: 0 0 0 2px var(--paper);
}

.level-name,
.level-meta {
  display: none;
}

/* ---------- panel ---------- */

.game-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.guard {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 20px 18px;
  border-bottom: 1px solid var(--line);
}

.guard-level {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--dim);
}

.guard-name {
  margin-top: 2px;
  font-size: var(--text-lg);
}

.guard-defense {
  max-width: 52ch;
  margin-top: 6px;
  color: var(--mist);
}

.guard-timer {
  flex: none;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--panel-sunken);
  font-size: 1.0625rem;
  font-weight: 600;
}

.guard-timer[data-done] {
  color: var(--done);
}

/* ---------- conversation ---------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 180px;
  max-height: 52vh;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 4px;
  max-width: min(88%, 560px);
}

.message-guard {
  align-self: flex-start;
}

.message-player {
  align-self: flex-end;
  justify-items: end;
}

.message-author,
.message-note {
  padding-inline: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--dim);
}

.message-text {
  padding: 10px 14px;
  border-radius: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-guard .message-text {
  border-top-left-radius: 4px;
  background: var(--panel-raised);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.message-player .message-text {
  border-top-right-radius: 4px;
  background: var(--paper);
  color: var(--ink);
}

.message-error {
  align-self: center;
  font-size: var(--text-sm);
  color: var(--alarm);
}

/* A reply a defense stopped: the filter speaks, not the guard. */
.message-blocked .message-author {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--alarm);
}

.message-blocked .message-author .icon {
  width: 14px;
  height: 14px;
}

.message-blocked .message-text {
  background: rgb(255 138 128 / 0.08);
  box-shadow: inset 0 0 0 1.5px rgb(255 138 128 / 0.5);
  font-size: 0.9375rem;
  line-height: 1.55;
}

.typing {
  display: inline-flex;
  gap: 5px;
  padding: 16px 16px;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mist);
  animation: typing 1.2s infinite;
}

.typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing {
  0%,
  70%,
  100% {
    opacity: 0.25;
  }
  35% {
    opacity: 1;
  }
}

.composer {
  display: flex;
  gap: 8px;
  padding: 0 20px 20px;
}

.composer .input {
  flex: 1;
  min-width: 0;
}

/* ---------- unlock ---------- */

.unlock {
  display: grid;
  gap: 8px;
  padding: 18px 20px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel-sunken);
}

.unlock-row {
  display: flex;
  gap: 8px;
}

.unlock-row .input {
  flex: 1;
  min-width: 0;
  background: var(--panel);
}

.input-code {
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.input-code::placeholder {
  font-family: var(--font-sans);
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.unlock-feedback {
  min-height: 1.4em;
  font-size: var(--text-sm);
  color: var(--mist);
}

.unlock-feedback[data-tone='error'] {
  color: var(--alarm);
}

.unlock[data-shake] .input-code {
  animation: shake 0.32s;
}

@keyframes shake {
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(4px);
  }
  75% {
    transform: translateX(-2px);
  }
}

.solved {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-top: 1px solid var(--line);
  background: var(--panel-sunken);
}

.solved-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--text-md);
  font-weight: 700;
}

.solved-title .icon {
  width: 28px;
  height: 28px;
  padding: 5px;
  border-radius: 50%;
  background: var(--done);
  color: var(--ink);
  stroke-width: 3;
}

.solved-sub {
  display: block;
  margin-top: 2px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--mist);
}

.game-note {
  gap: 12px;
  padding: 24px;
}

.game-note p {
  color: var(--mist);
}

.game-note .button {
  justify-self: start;
  align-self: flex-start;
  margin-top: 8px;
}

/* ---------- wide screens: levels become a list beside the conversation ---------- */

@media (min-width: 960px) {
  .game {
    grid-template-columns: 300px minmax(0, 1fr);
    align-items: start;
    gap: 48px;
    padding-top: 16px;
  }

  .levels {
    grid-template-columns: 1fr;
    gap: 2px;
    margin-top: 28px;
    padding: 8px;
    border-radius: 20px;
    background: rgb(25 25 28 / 0.34);
  }

  .level,
  .level[disabled],
  .level[data-status='solved'] {
    grid-template-columns: 32px minmax(0, 1fr) auto;
    justify-items: start;
    gap: 12px;
    aspect-ratio: auto;
    padding: 10px 12px;
    border-radius: 12px;
    background: transparent;
    color: var(--paper);
    text-align: left;
  }

  .level[disabled] {
    color: rgb(255 255 255 / 0.5);
  }

  .level:hover:not([disabled]),
  .level[aria-current='step'] {
    background: rgb(255 255 255 / 0.1);
    box-shadow: none;
  }

  .level-number {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / 0.4);
    font-size: 0.875rem;
  }

  .level[data-status='solved'] .level-number {
    background: var(--done);
    color: var(--ink);
    box-shadow: none;
  }

  .level-name {
    display: block;
    font-weight: 600;
  }

  .level-meta {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: rgb(255 255 255 / 0.72);
  }

  .game-panel[data-game] {
    position: sticky;
    top: 16px;
    height: calc(100vh - 96px);
    height: calc(100dvh - 96px);
    min-height: 520px;
  }

  .chat {
    flex: 1;
    max-height: none;
  }

  .guard,
  .chat,
  .unlock,
  .solved {
    padding-inline: 28px;
  }

  .composer {
    padding-inline: 28px;
  }
}
