* {
  box-sizing: border-box;
}

/* Author `display` rules (e.g. .auth-gate) otherwise beat the UA stylesheet's
   `[hidden] { display: none }`, leaving "hidden" elements on screen. */
[hidden] {
  display: none !important;
}

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-gate-denied-msg {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #ffb4b4;
}

.auth-gate-user-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.auth-user-status {
  margin: 0;
  font-size: 0.95rem;
  opacity: 0.9;
}

.auth-copy-user-id {
  border: 1px solid #666;
  border-radius: 6px;
  background: #2a2a44;
  color: #eee;
  font: inherit;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
}

.auth-copy-user-id:hover {
  background: #3a3a58;
}

.auth-copy-user-id[hidden] {
  display: none;
}

.auth-gate-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: stretch;
}

.auth-gate-primary-btn,
.auth-gate-secondary-btn {
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
}

.auth-gate-primary-btn {
  border: 1px solid #2d6a4f;
  background: #2d6a4f;
  color: #f5f5f0;
}

.auth-gate-primary-btn:hover {
  background: #245a42;
}

.auth-gate-secondary-btn {
  border: 1px solid #666;
  background: transparent;
  color: #eee;
}

.auth-gate-secondary-btn:hover {
  background: #2a2a44;
}

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;
}

.dictionary-progress {
  width: 100%;
  max-width: 20rem;
  height: 5px;
  margin-top: 0.35rem;
  border-radius: 3px;
  background: #2a2a44;
  overflow: hidden;
}

.dictionary-progress-bar {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(
    45deg,
    #2d6a4f 0,
    #2d6a4f 0.5rem,
    #3f8a68 0.5rem,
    #3f8a68 1rem
  );
  background-size: 1.4rem 1.4rem;
  transition: width 0.25s ease;
  animation: dictionary-progress-stripes 0.9s linear infinite;
}

@keyframes dictionary-progress-stripes {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 1.4rem 0;
  }
}

.db-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
  margin: 0.5rem 0 0.6rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid #3a3a4a;
  border-radius: 6px;
  background: #23232e;
}

.db-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: #aab;
}

.db-field input,
.db-field select {
  font-size: 0.85rem;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #444;
  background: #eee;
  color: #222;
}

.db-id-input {
  width: 11rem;
}

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

.db-bar button {
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
}

.db-status {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.85rem;
  color: #aab;
  min-height: 1.2em;
}

.db-status-error {
  color: #ff9a8c;
}

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;
}

.length-histogram {
  display: flex;
  gap: 0.2rem;
  font-family: system-ui, -apple-system, sans-serif;
}

.length-histogram-col {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  flex-direction: column;
  align-items: center;
}

.length-histogram-count {
  font-size: 0.6rem;
  line-height: 1.2;
  color: #333;
  margin-bottom: 0.1rem;
}

.length-histogram-bar-track {
  width: 100%;
  max-width: 1.1rem;
  height: 2rem;
  display: flex;
  align-items: flex-end;
}

.length-histogram-bar {
  width: 100%;
  min-height: 2px;
  background: #2d6a4f;
  border-radius: 2px 2px 0 0;
}

.length-histogram-label {
  margin-top: 0.15rem;
  font-size: 0.6rem;
  color: #888;
}

.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;
}

/* —— Admin CMS (served at /) —— */
.cms-body {
  margin: 0;
  min-height: 100vh;
  background: #1a1a22;
  color: #e8e8ef;
}

.cms-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

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

.cms-header-title h1 {
  margin: 0;
  font-size: 1.5rem;
}

.cms-daily-through {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  color: #aab;
}

.cms-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.cms-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: #aab;
}

.cms-filters input,
.cms-filters select {
  font-size: 0.85rem;
  padding: 0.25rem 0.4rem;
  border-radius: 4px;
  border: 1px solid #444;
  background: #eee;
  color: #222;
}

.cms-table-wrap {
  overflow-x: auto;
  border: 1px solid #3a3a4a;
  border-radius: 6px;
  background: #23232e;
}

.cms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.cms-table th,
.cms-table td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid #333;
  vertical-align: middle;
}

.cms-table th {
  color: #aab;
  font-weight: 600;
  white-space: nowrap;
}

.cms-table tr:last-child td {
  border-bottom: none;
}

.cms-row-draft {
  background: rgba(255, 180, 80, 0.06);
}

.cms-id {
  font-family: ui-monospace, monospace;
  white-space: nowrap;
}

.cms-status {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.8rem;
}

.cms-status-draft {
  background: #4a3a20;
  color: #f0c878;
}

.cms-status-published {
  background: #1e3a2a;
  color: #8fd9a8;
}

.cms-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.cms-actions a.secondary-btn,
.cms-actions button {
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  text-decoration: none;
  display: inline-block;
}

.cms-link-btn {
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 4px;
  border: 1px solid #6a6a78;
  background: #3a3a48;
  color: #f2f2f7 !important;
  text-decoration: none;
  display: inline-block;
}

.cms-link-btn:visited {
  color: #d8d8e0 !important;
}

.cms-link-btn:hover {
  background: #4a4a5a;
  color: #ffffff !important;
}

.cms-id {
  white-space: nowrap;
}

.cms-id-label {
  cursor: default;
  border-bottom: 1px dotted #889;
}

.cms-feedback-badge {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 0.35rem;
  color: #c8d0ff;
}

.cms-board-preview {
  position: fixed;
  z-index: 50;
  padding: 0.45rem;
  background: #1c1c24;
  border: 1px solid #666;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.cms-board-preview[hidden] {
  display: none !important;
}

.cms-preview-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cms-preview-row {
  display: flex;
  gap: 2px;
}

.cms-preview-cell {
  width: 1.35rem;
  height: 1.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2a36;
  color: #f5f5f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 2px;
}

.cms-danger-btn {
  background: #5a2a2a;
  color: #ffc8c0;
  border: 1px solid #8a4040;
  border-radius: 4px;
  cursor: pointer;
}

.cms-danger-btn:hover {
  background: #6e3434;
}

.cms-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cms-modal[hidden] {
  display: none !important;
}

.cms-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(0, 0, 0, 0.55);
  cursor: pointer;
}

.cms-modal-panel {
  position: relative;
  z-index: 1;
  width: min(24rem, calc(100vw - 2rem));
  padding: 1.25rem 1.35rem;
  border-radius: 8px;
  background: #2a2a36;
  border: 1px solid #4a4a5a;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  color: #e8e8ef;
}

#feedback-detail-modal .cms-modal-panel {
  width: min(32rem, calc(100vw - 2rem));
  background: #fff;
  border: 1px solid #ccc;
  color: #222;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

#feedback-detail-modal .cms-modal-panel h2 {
  color: #222;
}

#feedback-detail-modal .feedback-detail-body {
  color: #222;
}

#feedback-detail-modal .cms-modal-actions .secondary-btn {
  color: #222;
}

.cms-modal-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.cms-modal-hint {
  margin: 0 0 1rem;
  font-size: 0.85rem;
  color: #aab;
}

.cms-modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: #aab;
}

.cms-modal-field input {
  font-size: 0.9rem;
  padding: 0.35rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #555;
  background: #eee;
  color: #222;
}

.cms-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.editor-meta-panel {
  margin: 1.5rem 0 2rem;
  display: grid;
  gap: 1.25rem;
}

.editor-notes-label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-weight: 600;
}

.editor-notes {
  width: 100%;
  min-height: 8rem;
  font: inherit;
  font-weight: 400;
  line-height: 1.4;
  padding: 0.6rem 0.7rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  resize: vertical;
}

.editor-feedback-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}

.editor-feedback-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.editor-feedback-row {
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #f7f7f7;
  cursor: pointer;
  color: #222;
}

.editor-feedback-row:hover {
  background: #ececec;
}

.editor-feedback-empty {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}

.feedback-detail-body {
  max-height: min(60vh, 28rem);
  overflow: auto;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.feedback-detail-body p {
  margin: 0 0 0.65rem;
}

