:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --soft: #e2e8f0;
  --soft-2: #f1f5f9;
  --accent: #1d4ed8;
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --error: #b91c1c;
  --error-bg: #fef2f2;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }

.page { max-width: 1260px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--soft); border-radius: 16px; padding: 16px; }
.top-card { margin-bottom: 16px; }
.title { margin: 0; font-size: 28px; }
.subtitle, .small, .section-note, .progress-text { color: var(--muted); font-size: 14px; }
.section-title { margin: 8px 0; }
.topbar, .section-head, .section-actions, .progress-header, .grid-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; }

.btn { border: 1px solid var(--line); background: #fff; padding: 8px 12px; border-radius: 10px; font-weight: 700; cursor: pointer; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-success { background: #059669; color: #fff; border-color: #059669; }

.pill { border-radius: 999px; background: var(--soft); padding: 6px 10px; font-size: 12px; font-weight: 700; }
.pill-current { background: #dbeafe; color: #1e3a8a; }
.progress-bar { margin-top: 10px; height: 10px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.progress-bar span { display: block; width: 0; height: 100%; background: var(--accent); }

.message { margin-top: 12px; border-radius: 12px; padding: 10px; border: 1px solid var(--line); }
.message.success { background: var(--ok-bg); color: var(--ok); border-color: #a7f3d0; }
.message.error { background: var(--error-bg); color: var(--error); border-color: #fecaca; }

.board-wrap { overflow: auto; margin-top: 12px; }
.board { display: inline-grid; gap: 2px; }
.cell, .clue-cell {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.cell { background: #fff; cursor: pointer; font-weight: 700; }
.cell.filled { background: #0f172a; border-color: #0f172a; }
.cell.crossed { color: #64748b; }
.clue-cell { background: var(--soft-2); font-size: 12px; }

.simple-board {
  display: grid;
  gap: 6px;
}

.simple-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.simple-grid-row {
  display: grid;
  gap: 2px;
}

.simple-clues-cell {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 8px;
}

.simple-clue-line {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  align-items: center;
  line-height: 1.3;
}

.clue-chip {
  display: inline-flex;
  min-width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 12px;
  font-weight: 700;
  padding: 0 8px;
}

.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: none; align-items: center; justify-content: center; padding: 16px; }
.overlay.visible { display: flex; }
.modal { width: min(460px, 100%); background: #fff; border-radius: 14px; padding: 16px; }
.stacked-form { display: grid; gap: 10px; }
.stacked-form input, .stacked-form textarea, .stacked-form select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-top: 4px; }

.admin-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; }
.admin-page { max-width: 1400px; }
.bo-header { margin-bottom: 12px; }
.bo-tabs {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.bo-tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}
.bo-tab.active {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e3a8a;
}
.bo-panel { display: none; }
.bo-panel.active { display: block; }
.exercise-list { margin-top: 10px; display: grid; gap: 8px; max-height: 70vh; overflow: auto; }
.exercise-item { border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; background: #fff; text-align: left; }
.exercise-item.active { border-color: var(--accent); background: #eff6ff; }
.preview { margin-top: 10px; padding: 10px; border: 1px dashed var(--line); border-radius: 10px; background: #fff; overflow: auto; }
.preview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.preview-block { margin-top: 10px; }
.hidden { display: none; }
.mode-fieldset {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.mode-fieldset legend { padding: 0 6px; color: var(--muted); }
.mode-fieldset label { display: inline-flex; gap: 6px; align-items: center; }
.matrix-editor { border: 1px solid var(--line); background: var(--soft-2); border-radius: 10px; padding: 10px; display: inline-block; }
.grid-controls label { display: inline-flex; align-items: center; gap: 6px; }
.grid-controls input { width: 80px; }
.preset-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.matrix-preset-btn { padding: 6px 10px; font-size: 12px; }
.inline-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.inline-check input { width: auto; margin: 0; }
.exercise-item-head { margin-bottom: 6px; }
.exercise-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.exercise-item-inline-action {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  text-decoration: underline;
}
.exercise-item-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.list-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  background: #f8fafc;
}
.list-badge.on { background: #ecfdf5; border-color: #86efac; color: #166534; }
.list-badge.off { background: #f8fafc; border-color: #d1d5db; color: #4b5563; }
.list-badge.current { background: #dbeafe; border-color: #93c5fd; color: #1e3a8a; }
.lesson-browser { margin-bottom: 14px; }
.lesson-list { display: grid; gap: 8px; margin-bottom: 14px; }
.lesson-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  text-align: left;
  cursor: pointer;
}
.lesson-item.active {
  border-color: var(--accent);
  background: #eff6ff;
}
.app-footer {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}
.app-footer-admin {
  grid-column: 1 / -1;
}
.backup-browser {
  grid-column: 1 / -1;
}
.backup-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr 1.2fr;
}
.backup-list {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  min-height: 220px;
  max-height: 340px;
  overflow: auto;
  padding: 8px;
  display: grid;
  gap: 8px;
}
.backup-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 8px;
  text-align: left;
  cursor: pointer;
}
.backup-item.active {
  border-color: var(--accent);
  background: #eff6ff;
}
.backup-item-meta {
  color: var(--muted);
  font-size: 12px;
}
.backup-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.backup-delete {
  font-size: 12px;
  font-weight: 700;
  color: #b91c1c;
  text-decoration: underline;
}
.backup-delete:hover {
  color: #991b1b;
}
.json-block {
  font-family: Consolas, Monaco, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.backup-detail-block {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--soft);
}
.backup-detail-block:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}
.action-bar-sticky {
  position: sticky;
  top: 8px;
  z-index: 20;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .preview-grid { grid-template-columns: 1fr; }
  .backup-grid { grid-template-columns: 1fr; }
  .bo-tab { flex: 1; text-align: center; }
}
