/*
 * Bliss translator: communication board builder.
 *
 * Uses the tokens from styles.css (paper, ink, one accent, hairlines).
 * Cell symbols follow the Symbol size setting through --symbol.
 *
 * Author: Luke Steuber
 * License: MIT
 */

:root {
  --cell-symbol: calc(var(--symbol) * 0.6);
  --cell-min: calc(var(--cell-symbol) + 2.75rem);
}

/* Controls */

.board-controls,
.board-grid-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: end;
  margin-top: 16px;
}

.board-open select {
  width: auto;
  min-width: 12rem;
  max-width: 100%;
}

.board-title-field {
  margin-top: 12px;
  max-width: 28rem;
}

.board-title-input {
  font-size: 1.125rem;
  font-weight: 600;
}

.board-grid-controls {
  align-items: center;
}

.board-grid-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 0.9375rem;
  color: var(--ink);
}

.board-grid-controls input[type="number"] {
  width: 5rem;
  text-align: center;
}

.board-mode-toggle {
  display: inline-flex;
  border: 1px solid var(--edge);
  border-radius: 6px;
  overflow: hidden;
}

.board-mode-toggle button {
  border: 0;
  border-radius: 0;
  color: var(--muted);
}

.board-mode-toggle button + button {
  border-left: 1px solid var(--edge);
}

/* The pressed mode: filled, bold and underlined, not color alone. */
.board-mode-toggle button[aria-pressed="true"] {
  background: var(--select);
  color: var(--ink);
  font-weight: 650;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}

/* Grid: rows of cells (ARIA grid > row > gridcell) */

.board-grid-container {
  margin-top: 12px;
  overflow-x: auto;
  padding: 4px; /* room for the focus ring */
}

.board-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 100%;
  width: max-content;
}

.board-row {
  display: flex;
  gap: 6px;
}

/* gridcell (.board-slot) > button (.board-cell) + pointer-only clear */
.board-slot {
  position: relative;
  flex: 1 1 0;
  display: flex;
  min-width: var(--cell-min);
  min-height: var(--cell-min);
}

button.board-cell {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  min-height: 0;
  padding: 8px;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--edge);
  border-radius: 4px;
}

button.board-cell:hover:enabled {
  border-color: var(--accent);
}

.board-cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  z-index: 1;
}

button.board-cell--empty {
  background: transparent;
  border-style: dashed;
}

.board-cell__icon {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
}

.board-cell__image {
  width: var(--cell-symbol);
  height: var(--cell-symbol);
  object-fit: contain;
  padding: 2px;
  background: var(--plate);
  border-radius: 4px;
}

.board-cell__label {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: max(0.8125rem, calc(var(--caption) * 0.9));
  font-weight: 600;
  line-height: 1.25;
}

/* Pointer shortcut for clearing a cell. Keyboard and screen-reader users
   clear from the cell's dialog or with Delete. */
.board-cell__clear {
  position: absolute;
  top: 2px;
  right: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  width: 32px;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  border: 1px solid var(--edge);
  border-radius: 4px;
  background: var(--paper);
}

.board-cell__clear:hover:enabled {
  color: var(--danger);
  background: var(--paper);
}

.board-grid--preview .board-cell:hover {
  background: var(--tint);
}

.board-cell--speaking {
  outline: 4px solid var(--accent) !important;
  outline-offset: 2px;
  background: var(--tint) !important;
}

@media (forced-colors: active) {
  .board-cell--speaking {
    outline-color: Highlight !important;
  }
}

/* Symbol picker for a cell (inside <dialog id="cell-dialog">) */

.cell-results {
  list-style: none;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr));
  margin: 0;
  padding: 2px;
}

.cell-results:empty {
  display: none;
}

.cell-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  padding: 8px 6px;
  border-radius: 4px;
  text-align: center;
}

.cell-result img {
  width: 4rem;
  height: 4rem;
  object-fit: contain;
  padding: 2px;
  background: var(--plate);
  border-radius: 4px;
}

.cell-result span {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.875rem;
  line-height: 1.25;
}

.cell-result small {
  font-size: 0.75rem;
  color: var(--muted);
}

.board-feedback {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-top: 8px;
}

.board-feedback .status {
  margin-top: 0;
}

.board-empty-state {
  padding: 24px 0;
  color: var(--muted);
}

.board-empty-state p + p {
  margin-top: 4px;
}

@media (max-width: 640px) {
  .board-open,
  .board-open select,
  .board-title-field {
    width: 100%;
    max-width: none;
  }
}
