:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #d1d5db;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --tree: #2a8e49;
  --tent: #e37e3a;
  --grass: #dff5dd;
  --empty: #ffffff;
  --error: #dc2626;
  --success: #15803d;
  --cell-size: clamp(28px, 7vw, 52px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}

.hero h1 {
  margin: 0 0 10px;
  font-size: 2.2rem;
}

.intro {
  max-width: 700px;
  margin: 0 auto;
  color: var(--muted);
  line-height: 1.5;
}

.game-panel,
.how-to-play,
.leaderboard {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 20px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.status-group {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.status-box {
  min-width: 100px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.status-box .label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.select-wrap {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--muted);
  gap: 6px;
}

.select-wrap select {
  min-width: 130px;
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px 10px;
  font-size: 0.95rem;
}

button {
  border: 0;
  background: var(--accent);
  color: white;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent-hover);
}

.board-wrap {
  overflow-x: auto;
  margin: 0 -6px;
}

#boardContainer {
  display: inline-block;
  min-width: max-content;
  padding: 0;
}

.board-grid {
  display: grid;
  gap: 2px;
  background: var(--line);
  padding: 2px;
  border-radius: 8px;
}

.cell,
.clue-cell,
.corner-cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--empty);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  font-weight: 700;
}

.clue-cell,
.corner-cell {
  background: #eef2f7;
  color: #334155;
}

.cell {
  cursor: pointer;
  font-size: 1.2rem;
  position: relative;
  overflow: hidden;
}

.cell.tree {
  background: #e7f7ef;
  color: transparent;
  cursor: default;
}

.cell.tent {
  background: #fff3e7;
  color: transparent;
}

.cell.grass {
  background: var(--grass);
  color: transparent;
}

.cell::after {
  content: "";
  position: absolute;
  inset: 2px;
  background-size: 100%;
  background-repeat: no-repeat;
  background-position: center;
}

.cell.tree::after {
  background-image: url("assets/tree.png");
}

.cell.tent::after {
  background-image: url("assets/tent.png");
}

.cell.grass::after {
  background-image: url("assets/grass.png");
  opacity: 0.9;
}

.cell.invalid {
  outline: 2px solid var(--error);
  outline-offset: -2px;
}

.how-to-play ol {
  margin: 0;
  padding-left: 20px;
  line-height: 1.7;
}

.score-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.score-form input {
  flex: 1 1 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 1rem;
}


.leaderboard {
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.06);
}

.leaderboard h2 {
  margin: 0 0 12px;
}

.leaderboard-list {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #f8fafc;
}

.leaderboard.compact .leaderboard-list {
  margin-bottom: 10px;
}

.leaderboard.compact .ghost {
  align-self: flex-start;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 10px;
  margin-bottom: 4px;
}

.leaderboard.compact .ghost:hover {
  background: #eef2f7;
}

.score-row {
  display: grid;
  grid-template-columns: 60px 1fr 90px 90px;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: white;
}

.score-row:first-child {
  border-top: 0;
}

.score-row.header {
  background: #f8fafc;
  font-weight: 700;
}

.score-row.empty span {
  grid-column: 1 / -1;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.modal-content input {
  width: 100%;
  margin: 12px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

@media (max-width: 700px) {
  :root {
    --cell-size: clamp(24px, 8vw, 42px);
  }

  .cell,
  .clue-cell,
  .corner-cell {
    font-size: 1rem;
  }

  /* Prevent overlap on small screens after rotation by slightly shrinking icons */
  .cell::after {
    inset: 4px;
    background-size: 90%;
  }

  .board-grid {
    gap: 1px;
    padding: 1px;
    border-radius: 6px;
  }

  .score-row {
    grid-template-columns: 44px 1fr 70px 70px;
    font-size: 0.9rem;
  }
}