/* =============================================================================
   BASE
   ============================================================================= */

* {
  transition: all .2s ease-out;
}

footer {
  bottom: 2em;
  font-size: 0.8em;
}

strong {
  margin: 1em;
}

/* =============================================================================
   GRID TABLE
   ============================================================================= */

table {
  border-top: 1px solid black;
  border-left: 1px solid black;
}

tbody {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols, 15), min(50px, calc(100cqw / var(--grid-cols, 15))));
}

tr {
  display: contents;
}

td {
  border-right: 1px solid black;
  border-bottom: 1px solid black;
}

tbody td {
  aspect-ratio: 1;
  width: 100%;
  font-size: clamp(0.6rem, calc(min(50px, 100cqw / var(--grid-cols, 15)) * 0.7), 1.8em);
  background-color: white;
  text-align: center;
  vertical-align: middle;
  position: relative;
  line-height: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Cell number label */
td span.i_words {
  position: absolute;
  top: 1px;
  left: 2px;
  font-size: clamp(6px, calc(100cqw / var(--grid-cols, 15) * 0.28), 12px);
  line-height: 1;
  font-weight: 600;
  color: black;
}

/* Cell states */
tbody td:hover            { background-color: #ffe066; }
td.focus_across,
td.focus_down             { background-color: #b8d8e8; }
td.selected_cell          { background-color: #ffd700; }
td.black                  { background-color: black; }
td.black:hover            { background-color: black; }
td.empty-warn             { background-color: #fff9c4 !important; }

/* Correct / wrong letter colours */
.right  { color: #00c200; }
.wrong  { color: red; }
.answer { display: none; }

/* =============================================================================
   CLUES PANEL
   ============================================================================= */

.clues {
  text-align: left;
  flex-shrink: 3;
  flex-basis: 320px;
  width: 320px;
  min-width: 120px;
  max-width: 360px;
  height: min(80vh, 600px);
  display: flex;
  flex-direction: column;
  gap: 0.4em;
}

.clues_across, .clues_down {
  border-radius: 0.3em;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  background: #eef4f7;
  overflow: auto;
  font-size: 0.92rem;
}

.clues_across div, .clues_down div {
  padding: 0.2em;
  border-radius: 0.3em;
  cursor: pointer;
}

.clues_across div:hover,
.clues_down div:hover {
  background-color: #4a90a4;
  color: white;
}

.clue-num {
  font-weight: 700;
  margin-right: 0.15em;
}

.selected_clue {
  background-color: #4a90a4;
  color: white;
  font-size: 1.3em;
}

/* =============================================================================
   GAME LAYOUT
   ============================================================================= */

.game-topbar {
  display: flex;
  align-items: center;
  gap: 1em;
  margin-bottom: 0.8em;
}

.game-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 600;
  color: #343a40;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  padding: 0 1rem;
  box-sizing: border-box;
}

.puzzle {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 2em;
  padding: 1em 0;
  width: 100%;
}

.grid-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-grow: 1;
  flex-shrink: 0;
  min-width: calc(var(--grid-cols, 15) * 20px);
  max-width: calc(var(--grid-cols, 15) * 50px);
  container-type: inline-size;
  container-name: grid-block;
}

.grid {
  position: relative;
  cursor: default;
  width: fit-content;
  margin: 0 auto;
}

.active-clue-bar {
  min-height: 2.2em;
  margin-top: 0.5em;
  padding: 0.3em 0.5em;
  background: #eef4f7;
  border-left: 3px solid #4a90a4;
  border-radius: 0.3em;
  font-size: 1.2rem;
  font-weight: 500;
  color: black;
  width: 100%;
  box-sizing: border-box;
}

.history-bar {
  display: flex;
  gap: 0.4em;
  margin-top: 0.4em;
  padding: 0.4em 0.2em;
  border-top: 2px solid #dee2e6;
  width: 100%;
}

/* =============================================================================
   BUTTONS BAR
   ============================================================================= */

.buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.6em 1.2em;
  padding: 0.8em 0 1.2em;
}

.btn-section {
  display: flex;
  align-items: center;
  gap: 0.3em;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 0.3em 0.6em;
}

.btn-section-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-right: 0.4em;
  border-right: 1px solid #dee2e6;
  margin-right: 0.2em;
}

.buttons .btn {
  margin: 0;
  font-size: 0.85em;
  letter-spacing: 0.03em;
}

.btn-check-grid {
  font-size: 0.95em !important;
  padding: 0.45em 1.3em !important;
  border-left: 2px solid rgba(255,255,255,0.25);
  box-shadow: 0 2px 6px rgba(13, 110, 253, 0.35);
  letter-spacing: 0.04em !important;
}

/* =============================================================================
   NOTIFICATION BAR
   ============================================================================= */

.game-notification-bar {
  width: 100%;
  max-width: 520px;
  margin: 0.4em auto 0;
  padding: 0;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 6px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.22s ease, opacity 0.22s ease, padding 0.22s ease;
  position: sticky;
  top: 0.5rem;
  z-index: 100;
}

.game-notification-bar.show {
  max-height: 3em;
  opacity: 1;
  padding: 0.45em 1em;
}

.game-notification-bar.ntf-success { background: #d1e7dd; color: #0a3622; }
.game-notification-bar.ntf-error   { background: #f8d7da; color: #58151c; }
.game-notification-bar.ntf-warning { background: #fff3cd; color: #664d03; }
.game-notification-bar.ntf-info    { background: #e9ecef; color: #212529; }

/* =============================================================================
   UTILITIES
   ============================================================================= */

.unselectable {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* =============================================================================
   RESPONSIVE — narrow screens
   ============================================================================= */

@media (max-width: 640px) {
  .puzzle {
    display: flex;
    flex-direction: column;
  }
  .clues {
    width: 100%;
    max-width: 100%;
  }
  .clues_across, .clues_down {
    height: 200px;
    flex: none;
  }
  .grid-block {
    width: 100%;
    min-width: unset;
    max-width: calc(var(--grid-cols, 15) * 40px);
  }
}
