:root {
  --bg: #faf8ef;
  --panel: #bbada0;
  --cell: rgba(238, 228, 218, 0.35);
  --text-dark: #5f574f;
  --text-light: #f9f6f2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #fff9eb, var(--bg));
  color: var(--text-dark);
  display: flex;
  justify-content: center;
  padding: 20px;
}

.game-shell {
  width: min(94vw, 520px);
  display: grid;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 42px);
}

.topbar p {
  margin: 4px 0 0;
  font-size: 14px;
}

#restart {
  border: none;
  background: #8f7a66;
  color: var(--text-light);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: #bbada0;
  color: var(--text-light);
  border-radius: 10px;
  padding: 8px 12px;
  display: grid;
  gap: 4px;
  text-align: center;
}

.metric span {
  font-size: 12px;
  opacity: 0.9;
}

.metric strong,
.metric-value-button {
  font-size: 24px;
  font-weight: 700;
}

.metric-value-button {
  border: none;
  background: transparent;
  color: inherit;
  font-family: inherit;
  padding: 0;
  cursor: pointer;
}

.metric-value-button:focus-visible {
  outline: 2px solid rgba(249, 246, 242, 0.9);
  outline-offset: 2px;
}

.completion-panel {
  background: #efe5d8;
  border-radius: 10px;
  padding: 10px 12px;
}

.completion-panel h2 {
  margin: 8px 0px 0px 0px;
  font-size: 14px;
}

.completed-counts {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.completed-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 8px;
  background: #f7f1e8;
  padding: 6px 8px;
  font-size: 13px;
}

.completed-item strong {
  min-width: 28px;
  text-align: right;
}

.game-panel {
  position: relative;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
}

.game-message {
  position: absolute;
  inset: 12px;
  border-radius: 8px;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 14px;
  text-align: center;
  background: rgba(238, 228, 218, 0.73);
  z-index: 3;
}

.game-message.visible {
  display: flex;
  animation: fade-in 180ms ease-out;
}

.game-message-text {
  margin: 0;
  color: #776e65;
  font-size: clamp(30px, 8vw, 52px);
  font-weight: 700;
}

.retry-button {
  border: none;
  height: 42px;
  padding: 0 20px;
  border-radius: 4px;
  background: #8f7a66;
  color: var(--text-light);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.retry-button:hover {
  background: #9f8b77;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-cols, 4), minmax(0, 1fr));
  gap: 10px;
  touch-action: none;
}

.cell {
  aspect-ratio: 1;
  background: var(--cell);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.complete-quote {
  color: #f9f6f2;
  background-color: #3c3a32;
  padding: 2px 2px;
  border-radius: 4px;
}

.text-span-button {
  margin-left: 6px;
  color: #8f7a66;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  cursor: pointer;
  user-select: none;
}

.text-span-button:hover {
  color: #6f5d4d;
}

.text-span-button:focus-visible {
  outline: 2px solid #8f7a66;
  outline-offset: 2px;
  border-radius: 4px;
}

.tile {
  --tile-bg: #eee4da;
  --tile-color: #776e65;
  --tile-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--tile-font-size, clamp(14px, 3vw, 24px));
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.08;
  padding: 4px;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  animation: pop 120ms ease-out;
  cursor: pointer;
  user-select: none;
  background: var(--tile-bg);
  color: var(--tile-color);
  box-shadow: var(--tile-shadow);
  transition: background 150ms ease-out, box-shadow 150ms ease-out;
}

.controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.controls button {
  border: none;
  border-radius: 8px;
  padding: 10px 0;
  background: #8f7a66;
  color: var(--text-light);
  font-size: 18px;
  cursor: pointer;
}

.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 14px;
}

.events {
  margin: 0;
  min-height: 96px;
  background: #f5f0e8;
  border-radius: 8px;
  padding: 10px;
  font-size: 12px;
  white-space: pre-wrap;
}

@keyframes pop {
  from {
    transform: scale(0.92);
  }

  to {
    transform: scale(1);
  }
}

@media (max-width: 480px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  #restart {
    width: 100%;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}