/* --- Global Styles & Mobile First --- */
:root {
  /* These are now dynamic, set by JS */
  --grid-cols: 15;
  --grid-rows: 15;
  --primary-color: #007bff;
  --dark-color: #333;
  --light-gray: #f0f2f5;
  --white-color: #fff;
}

* {
  box-sizing: border-box;
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", Roboto,
    Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--light-gray);
  color: var(--dark-color);
  margin: 0;
  padding: 10px;
  font-size: 16px;
}

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  background-color: var(--white-color);
  padding: 15px;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  text-align: center;
}

h1 {
  color: var(--primary-color);
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 1.5em;
}

.instructions {
  margin-bottom: 20px;
  color: #666;
  font-size: 0.9em;
}

/* --- Game Layout --- */
.game-area {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

#crossword-container {
  width: 100%;
  max-width: 500px;
}

#crossword-grid {
  display: grid;
  border: 2px solid var(--dark-color);
  grid-template-columns: repeat(var(--grid-cols), 1fr);
  grid-template-rows: repeat(var(--grid-rows), 1fr);
  width: 100%;
}

.cell {
  position: relative;
}

.cell input {
  width: 100%;
  height: 100%;
  border: 1px solid #ccc;
  text-align: center;
  font-size: calc(90vw / var(--grid-cols) / 1.8);
  font-weight: bold;
  padding: 0;
  margin: 0;
  outline: none;
  background-color: var(--white-color);
  color: var(--dark-color);
  transition: background-color 0.3s;
}

.cell input:focus {
  background-color: #e8f0fe;
}

.cell input:read-only {
  color: #0056b3;
  background-color: #f0f0f0;
}

/* --- NEW: Style for hint-revealed cells --- */
.cell input.hint-revealed {
  color: #d9534f;
  /* Hinted letters in red */
  background-color: #fff3cd;
  /* Light yellow background */
}

.cell.black {
  background-color: var(--dark-color);
  border: 1px solid var(--dark-color);
}

.cell .clue-number {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: calc(90vw / var(--grid-cols) / 3.5);
  font-weight: bold;
  color: #555;
  pointer-events: none;
}

/* --- Controls --- */
.controls {
  margin: 20px 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.controls button {
  padding: 12px 15px;
  font-size: 1em;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  background-color: var(--primary-color);
  color: white;
  transition: background-color 0.3s;
  flex-grow: 1;
  max-width: 150px;
}

/* --- NEW: Style for the hint button --- */
#hint-btn {
  background-color: #f0ad4e;
}

/* Orange color for hint */
#hint-btn:hover {
  background-color: #ec971f;
}

#reveal-btn {
  background-color: #28a745;
}

#reset-btn {
  background-color: #dc3545;
}

/* --- Word Bank --- */
.word-bank {
  margin-top: 20px;
  padding: 15px;
  background-color: #f8f9fa;
  border-radius: 5px;
}

#word-bank-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

#word-bank-list span {
  background-color: #e9ecef;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 0.9em;
}

/* --- Modal Styles --- */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease-in-out;
}

.modal-content {
  background-color: var(--white-color);
  margin: 15% auto;
  padding: 0;
  border-radius: 10px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  animation: slideIn 0.3s ease-out;
  position: relative;
}

.modal-body {
  padding: 30px 20px 20px;
  text-align: center;
}

.modal-body h2 {
  color: var(--primary-color);
  margin: 0 0 15px 0;
  font-size: 1.8em;
}

.modal-body p {
  color: var(--dark-color);
  margin: 0 0 25px 0;
  font-size: 1.1em;
  line-height: 1.4;
}

.close {
  position: absolute;
  right: 15px;
  top: 10px;
  color: #999;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.3s;
}

.close:hover,
.close:focus {
  color: var(--dark-color);
}

.modal-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 12px 30px;
  font-size: 1em;
  border-radius: 5px;
  cursor: pointer;
  transition: background-color 0.3s;
}

.modal-btn:hover {
  background-color: #0056b3;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* --- Media Query for Larger Screens (Tablets and Desktops) --- */
@media (min-width: 800px) {
  body {
    padding: 40px;
    font-size: 18px;
  }

  #crossword-container {
    width: 100%;
    max-width: 600px;
  }

  .cell input {
    font-size: calc(600px / var(--grid-cols) / 1.8);
  }

  .cell .clue-number {
    font-size: calc(600px / var(--grid-cols) / 3.5);
  }

  .modal-content {
    margin: 10% auto;
  }
}

/* 修改原有的 focus 樣式，使其更通用 */
.cell input:focus {
  background-color: #e8f0fe;
}

/* 新增：高亮當前作用中詞彙的樣式 */
.cell input.highlight {
  background-color: #cce5ff; /* 淡藍色背景 */
}

/* 新增：當前作用中詞彙裡，被焦點選中的格子樣式 */
.cell input.highlight:focus {
  background-color: #aaccff; /* 較深的藍色背景 */
}

.cell input.highlight-focus {
  background-color: #aaccff;
}
