:root {
  --primary-color: #3498db;
  --secondary-color: #2ecc71;
  --bg-color: #f5f5f5;
  --text-color: #333;
  --board-bg: #fff;
  --tile-bg: #fff;
  --tile-hover: #e6e6e6;
  --selected-bg: #a0d2ff;
  --related-bg: #e6f3ff;
  --button-bg: var(--primary-color);
  --button-hover: #2980b9;
  --digit-selected-bg: #ffd700;
  --digit-selected-color: #000;
}

.dark-mode {
  --bg-color: #222;
  --text-color: #f5f5f5;
  --board-bg: #333;
  --tile-bg: #444;
  --tile-hover: #555;
  --selected-bg: #1a5f7a;
  --related-bg: #2c3e50;
  --button-bg: var(--secondary-color);
  --button-hover: #27ae60;
  --digit-selected-bg: #ffeb3b;
  --digit-selected-color: #000;
}

body {
  font-family: "Roboto", sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  transition: background-color 0.3s, color 0.3s;
  position: relative;
}

.container {
  padding: 2rem;
  max-width: 500px;
  width: 100%;
}

h1 {
  text-align: center;
  margin-bottom: 2rem;
  font-weight: 300;
  font-size: 2.5rem;
}

#board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 1px;
  margin-bottom: 2rem;
  border: 2px solid var(--text-color);
  padding: 2px;
  background-color: var(--text-color);
}

/* 3x3 블록에 두꺼운 테두리 적용 */
.tile:nth-child(3n + 3) {
  border-right: 3px solid var(--text-color);
}

.tile:nth-child(n + 19):nth-child(-n + 27) {
  border-bottom: 3px solid var(--text-color);
}

.tile:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 3px solid var(--text-color);
}

.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background-color: var(--tile-bg);
  transition: background-color 0.3s;
  cursor: pointer;
  position: relative;
}

.tile:hover {
  background-color: var(--tile-hover);
}

.tile.selected {
  background-color: var(--selected-bg);
}

.tile.given {
  font-weight: bold;
}

.tile.error {
  /* background-color: #ffcccc; */
}

#digits {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 5px;
  justify-content: center;
  margin-bottom: 1rem;
}

.digit,
button {
  width: 100%;
  aspect-ratio: 1;
  background-color: var(--button-bg);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s;
}

.digit {
  font-size: 1rem;
}

.digit:hover,
button:hover {
  background-color: var(--button-hover);
  transform: translateY(-2px);
}

.digit.selected {
  background-color: var(--digit-selected-bg);
  color: var(--digit-selected-color);
  transform: none;
}

#controls {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  gap: 5px;
}

button {
  padding: 8px 12px;
  font-size: 0.9rem;
  margin: 5px 0;
  flex: 1;
}

#theme-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1.5rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color);
  width: 30px;
  height: 30px;
  z-index: 10;
}

#difficultyPopup {
  display: none;
  position: fixed;
  width: 300px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--board-bg);
  padding: 20px;
  border-radius: 5px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  z-index: 100;
  text-align: center;
}

#difficultyPopup h3 {
  margin-bottom: 15px;
}

#difficultyPopup button {
  display: block;
  width: 100%;
  height: 40px;
  margin: 10px auto;
  padding: 10px 20px;
  background-color: var(--button-bg);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
}

#difficultyPopup button:hover {
  background-color: var(--button-hover);
}

.pencil-marks-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}

.pencil-mark {
  font-size: 0.7rem;
  color: grey;
  display: flex;
  align-items: center;
  justify-content: center;
}

.creator-info {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-color);
}

.creator-info a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

@media (max-width: 500px) {
  .container {
    padding: 1rem;
  }

  .tile {
    font-size: 1.3rem;
  }

  button {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  #digits {
    grid-template-columns: repeat(9, 1fr);
    gap: 2px;
  }

  .digit {
    font-size: 0.8rem;
  }
}

@media print {
  #print-board {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
  }
  @page {
    size: auto;
    margin: 0;
  }
}
