* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #222;
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: #1a1a2e;
  color: #eee;
}

.auth-gate-panel {
  max-width: 28rem;
  text-align: center;
}

.auth-gate-panel button {
  cursor: pointer;
}

.auth-status {
  margin-top: 1rem;
  opacity: 0.85;
}

header {
  padding: 1rem 1.5rem;
  background: #1a1a2e;
  color: #eee;
}

.header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.25rem;
}

.header-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.header-title-row h1 {
  margin: 0;
  font-size: 1.4rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-actions button {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
}

.lang-select {
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

.lang-select-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: #aab;
}

.lang-select-control {
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #444;
  background: #eee;
  color: #222;
}

.status {
  margin: 0;
  font-size: 0.9rem;
  color: #aab;
}

main {
  padding: 1rem 1.5rem 2rem;
  max-width: 1200px;
}

.workspace {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.controls-left {
  flex: 1 1 16rem;
  min-width: 0;
}

.grid-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
  margin-left: auto;
}

.grid-size-row {
  margin-bottom: 0;
}

.grid-panel-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
  width: 100%;
}

.hint-display {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
}

.hint-display label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 0.75rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.starting-word-label {
  flex: 1;
  min-width: 12rem;
}

.starting-words-row {
  align-items: stretch;
}

.starting-words-panel {
  flex: 0 0 auto;
  width: max-content;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.starting-words-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.starting-words-label {
  font-size: 0.85rem;
  font-weight: 600;
}

.starting-word-suggestions.word-list {
  width: 14rem;
  height: calc(0.85rem * 1.5 * 12 + 0.2rem);
  min-height: 0;
  flex: none;
}

.starting-words-custom-label {
  width: 14rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
}

.starting-words-custom {
  width: 100%;
  min-height: 4.5rem;
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 0.35rem 0.45rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
}

.secondary-btn {
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
}

.control-row-actions {
  align-items: center;
}

.fill-remaining-option {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
}

.filler-letter-mix-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: -0.25rem 0 0.75rem;
  font-size: 0.85rem;
  color: #555;
}

.filler-letter-mix-label {
  font-weight: 600;
  color: #333;
  margin-right: 0.25rem;
}

.filler-letter-mix-end {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #666;
}

.filler-letter-mix-row input[type="range"] {
  flex: 1 1 8rem;
  min-width: 6rem;
  max-width: 14rem;
}

.filler-letter-spice-label,
.sparse-word-target-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.sparse-word-target-label input {
  width: 4rem;
}

.filler-letter-spice-label input[type="range"] {
  flex: 1 1 6rem;
  min-width: 5rem;
  max-width: 10rem;
}

.weave-session-stats {
  margin: -0.25rem 0 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: #1a3d2e;
  background: #e8f5ee;
  border: 1px solid #9fd4b5;
  border-radius: 4px;
}

.word-add-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.word-add-input {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  padding: 0.3rem 0.45rem;
}

.results {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.75rem;
  align-items: flex-start;
}

body.weave-busy {
  overflow: hidden;
}

.weave-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.weave-modal[hidden] {
  display: none;
}

.weave-modal-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.weave-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 24rem;
  padding: 1.25rem;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.weave-modal-title {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.weave-modal-message {
  margin: 0 0 1rem;
  font-size: 0.9rem;
  color: #555;
  line-height: 1.4;
}

.weave-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.hint-unlocks {
  align-items: end;
}

.score-model-label {
  display: inline-flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.85rem;
  color: #555;
  margin-right: 0.75rem;
}

.score-model-label select {
  min-width: 8rem;
}

.hint-unlocks-label {
  font-size: 0.85rem;
  color: #555;
  margin-right: 0.25rem;
}

.max-score-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: #333;
  margin-right: 0.5rem;
  white-space: nowrap;
}

.hint-unlocks label input {
  width: 4rem;
}

.hint-unlock-error {
  margin: -0.25rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  color: #664d03;
  background: #fff3cd;
  border: 1px solid #e0c36a;
  border-radius: 4px;
}

input[type="number"],
input[type="text"],
textarea:not(.starting-words-custom) {
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  padding: 0.45rem 0.9rem;
  font-size: 0.95rem;
  border: 1px solid #888;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #eee;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#grid-container {
  display: inline-block;
  padding: 0.5rem;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
}

.grid-table {
  border-collapse: collapse;
}

.grid-table td {
  padding: 0;
  position: relative;
}

.cell-input {
  width: 4.62rem;
  height: 4.62rem;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 2.31rem;
  text-transform: uppercase;
  border: 1px solid #bbb;
  padding: 0;
}

.hint {
  position: absolute;
  bottom: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
}

.hint-start {
  left: 4px;
  color: #2ecc71;
}

.hint-contains {
  right: 4px;
  color: #1a1a1a;
}

.cell-input.blank {
  background: #f0f0f0;
}

.cell-input.user-blank {
  background: #6b7280;
}

.cell-input.weave-cell {
  background: #dbeafe;
}

.cell-input.weave-cell:focus {
  outline: 2px solid #4a6fa5;
}

.cell-input.unused {
  background: #fff3cd;
  box-shadow: inset 0 0 0 2px #e0a800;
}

.cell-input.weave-cell.unused {
  background: #dbeafe;
  box-shadow: none;
}

.cell-input:focus {
  outline: 2px solid #4a6fa5;
  z-index: 1;
  position: relative;
}

.word-column {
  flex: 1 1 0;
  min-width: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.word-column h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.length-counts {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.4;
  color: #555;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #e0e0e0;
}

.word-transfer {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.transfer-btn {
  min-width: 2.75rem;
  font-family: ui-monospace, monospace;
  font-weight: 600;
  padding: 0.5rem 0.65rem;
}

.word-list {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  height: 16rem;
  overflow-y: auto;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fafafa;
  user-select: none;
}

.word-line {
  padding: 0.1rem 0.5rem;
  cursor: pointer;
}

.word-line:hover {
  background: #eef3fa;
}

.word-line.selected {
  background: #4a6fa5;
  color: #fff;
}

.word-line.selected:hover {
  background: #3d5d8a;
}

.word-line-ranked {
  font-variant-numeric: tabular-nums;
}

.word-sort-option {
  display: block;
  margin: 0.25rem 0 0.5rem;
  font-size: 0.9rem;
  font-weight: normal;
}

.starting-min-length-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.starting-min-length-label input {
  width: 3rem;
}

.warning {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #fff3cd;
  border: 1px solid #e0c36a;
  border-radius: 4px;
  color: #664d03;
}
