/* ========================================
   Reset & Base Styles
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Arial', sans-serif;
}

body {
  background-color: #e8ecef;
  color: #222;
}

/* ========================================
   Centering Container
   ======================================== */
.container {
  background: #ffffff;
  padding: 24px;
  max-width: 600px;
  width: 100%;
  margin: 40px auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  text-align: center;
}

/* ========================================
   Headings
   ======================================== */
h1 {
  font-size: 2rem;
  margin-bottom: 24px;
  color: #111;
}
h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
  color: #333;
}

/* ========================================
   Grid Layout for Clues and Solved Groups
   ======================================== */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
  padding: 12px;
  background: #f9f9f9;
  border-radius: 6px;
}

/* ========================================
   Tile Buttons
   ======================================== */
.tile {
  background: #ffffff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 18px;
  font-size: 1.2rem;
  color: #111;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  white-space: normal;         /* wrap long text */
  word-break: break-word;
  min-height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tile:hover {
  background: #f5f5f5;        /* soft neutral hover */
}
.tile.selected {
  background: #fff8e1;
  border-color: #f5c542;
}
.tile.solved {
  background: #e8f5e9;
  border-color: #81c784;
  color: #155724;
  cursor: default;
}

/* ========================================
   Description Text for Solved Group
   ======================================== */
.description {
  grid-column: span 4;
  font-weight: bold;
  font-size: 1rem;
  color: #222;
  margin-top: 12px;
}

/* ========================================
   Red X Indicator
   ======================================== */
.red-x {
  position: absolute;
  font-size: 2rem;
  color: rgba(192, 57, 43, 0.9);
  pointer-events: none;
}

/* ========================================
   Buttons & Inputs
   ======================================== */
.btn,
button {
  background-color: #006bb3;   /* slightly softer blue */
  color: #fff;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: background-color 0.3s ease;
  margin-top: 16px;
}
.btn:hover,
button:hover {
  background-color: #005080;
}

/* ========================================
   Input Form Styles
   ======================================== */
.input-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.input-form input[type="text"] {
  padding: 12px;
  border: 1px solid #888;
  border-radius: 5px;
  font-size: 1rem;
  width: 100%;
  background: #fdfdfd;
  color: #222;
}
.input-form input[type="text"]:focus {
  border-color: #006bb3;
  background: #ffffff;
  outline: none;
}

/* ========================================
   Encrypted Message Section
   ======================================== */
.output-section {
  margin-top: 20px;
}

.encrypted-message {
  font-weight: 600;
  font-size: 1.2rem;
  background-color: #eef5fb;
  padding: 12px;
  border-radius: 5px;
  margin-bottom: 16px;
  color: #004080;
}

/* ========================================
   Letter Buttons (Cryptogram)
   ======================================== */
.letter-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}

.letter-btn {
  width: 44px;
  height: 44px;
  font-size: 18px;
  background-color: #fbc02d;
  color: #111;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s;
}
.letter-btn:hover {
  background-color: #f9a825;
}
.letter-btn.selected {
  background-color: #ef6c00;
  color: #fff;
  border: 2px solid #d84315;
}
.letter-btn.correct {
  background-color: #388e3c;
  color: #fff;
  border: 2px solid #2e7d32;
  cursor: default;
}

/* ========================================
   Hidden Swap Button
   ======================================== */
#swap-button {
  visibility: hidden;
  position: absolute;
}
#swap-button:disabled {
  background-color: #ccc;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .container {
    width: 95%;
    margin: 12px auto;
    padding: 12px;
  }

  .section {
    margin-bottom: 8px;    /* extra section spacing */
  }

  .grid {
    grid-template-columns: repeat(4, 1fr);
    row-gap: 8px;          /* vertical gap */
    column-gap: 6px;       /* horizontal gap */
    margin-bottom: 6px;
  }

  #solved {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .tile {
    padding: 12px;
    font-size: clamp(0.9rem, 4vw, 1.1rem);
    min-width: 80px;
    min-height: 20px;
  }

  h1 {
    font-size: clamp(1.2rem, 8vw, 2rem);
  }
  h2 {
    font-size: clamp(1rem, 6vw, 1.5rem);
  }
}

/* Single‐column on very small screens */
@media (max-width: 400px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
    row-gap: 4px;   /* a bit more breathing room */
    column-gap: 2px;
    margin-bottom: 4px;
  }

  /* Solved stays two columns */
  #solved {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    row-gap: 4px;   /* a bit more breathing room */
    gap: 8px;
    column-gap: 2px;
    margin-bottom: 4px;
  }

  .tile {
    padding: 14px;
    font-size: clamp(1rem, 5vw, 1.1rem);
    min-width: 70px;
    min-height: 40px;
  }
}