:root {
  --color-bg: #f0efee;
  --color-text: #4f5141;
  --color-accent: #726352;
  --color-border: #b7b7b6;
  --color-muted: #9b907f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Guarantees the `hidden` attribute always hides an element, even when a
   class on it also sets `display` (e.g. .form sets display:flex, which
   would otherwise win over the browser's default [hidden] rule). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

a { color: var(--color-accent); }

.site-header {
  border-bottom: 1px solid var(--color-border);
  background: white;
}

.nav {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  color: var(--color-text);
  display: flex;
  align-items: center;
}

.brand-logo {
  height: 40px;
  width: auto;
  display: block;
}

.nav-links {
  display: flex;
  gap: 1.25rem;
  align-items: center;
}

.nav-links form.logout-form {
  display: inline;
}

.nav-links button {
  background: none;
  border: none;
  color: var(--color-accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.container.narrow {
  max-width: 760px;
}

.hero {
  padding: 2rem 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2rem;
}

.post-list, .card-list, .admin-links, .admin-lesson-list {
  list-style: none;
  padding: 0;
}

.post-list li {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
}

.card-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}

.card {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  background: white;
}

.meta {
  color: var(--color-muted);
  font-size: 0.875rem;
}

.price {
  font-weight: 600;
}

.prose {
  line-height: 1.75;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;
}

/* Forms containing something wider than a couple of fields (e.g. the
   Trix editor, whose toolbar needs room or it scrolls horizontally). */
.form-wide {
  max-width: 760px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
}

.form label.checkbox {
  flex-direction: row;
  align-items: center;
  font-weight: normal;
}

input, textarea, select {
  font: inherit;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

button, .button {
  display: inline-block;
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.6rem 1.2rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  width: fit-content;
}

.error {
  color: #a3312a;
}

.success {
  color: #2a7a3f;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

.admin-table form {
  display: inline;
}

.site-footer {
  text-align: center;
  color: var(--color-muted);
  padding: 2rem 0;
}

/* Progress bar (course landing page + course player) */

.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--color-border);
  overflow: hidden;
  margin: 0.75rem 0 0.25rem;
}

.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 4px;
}

/* Curriculum preview on the course landing page */

.curriculum-preview {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.curriculum-preview > li {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: white;
}

.curriculum-module-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.curriculum-preview ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--color-muted);
}

/* Course player (sidebar + lesson pane) */

.player {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
}

.player-sidebar {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  background: white;
  position: sticky;
  top: 1.5rem;
}

.player-course-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.player-module {
  margin-top: 1.25rem;
}

.player-module-title {
  font-weight: 600;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-muted);
  margin: 0 0 0.4rem;
}

.player-lesson-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.player-lesson-list li a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 4px;
  text-decoration: none;
  color: var(--color-text);
}

.player-lesson-list li.active a {
  background: var(--color-bg);
  font-weight: 600;
}

.player-lesson-list .check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  color: var(--color-accent);
  font-size: 0.8rem;
}

.player-content {
  min-width: 0;
}

.player-complete-form {
  margin: 1.5rem 0;
}

.button-secondary {
  background: transparent;
  color: var(--color-accent);
  border: 1px solid var(--color-accent);
}

.player-nav {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--color-border);
  padding-top: 1rem;
}

@media (max-width: 720px) {
  .player {
    grid-template-columns: 1fr;
  }
  .player-sidebar {
    position: static;
  }
}

/* Admin curriculum editor */

.admin-module {
  margin-bottom: 1.25rem;
}

.admin-module-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.admin-module-header form {
  margin: 0;
}

.admin-lesson-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
}

.admin-module details {
  margin-top: 0.75rem;
}

.admin-module summary {
  cursor: pointer;
  color: var(--color-accent);
  font-weight: 600;
}

/* Lesson content blocks (student view + admin editor) */

.lesson-block {
  margin-bottom: 1.75rem;
}

/* Per-block design controls set in the admin lesson editor */

.block-align-left { text-align: left; }
.block-align-center { text-align: center; }
.block-align-right { text-align: right; }

.block-align-center .video-embed,
.block-align-right .video-embed {
  margin-left: auto;
}
.block-align-center .video-embed { margin-right: auto; }

.block-align-center .lesson-image img,
.block-align-right .lesson-image img {
  margin-left: auto;
}
.block-align-center .lesson-image img { margin-right: auto; }

.block-width-narrow {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
}

/* An image/video normally fills 100% of its block, so alignment has no
   free space to shift it within — visible only once the block itself is
   narrower than the space around it ("Narrower, centered" width), which
   caps the image/video below that 640px column so left/center/right can
   actually move it. min() keeps it from overflowing a smaller container
   (e.g. a side-by-side paired block) than 480px. */
.block-width-narrow .lesson-image img {
  max-width: min(480px, 100%);
}

.block-width-narrow .video-embed {
  max-width: min(480px, 100%);
}

.block-spacing-compact { margin-bottom: 0.75rem; }
.block-spacing-normal { margin-bottom: 1.75rem; }
.block-spacing-spacious { margin-bottom: 3.5rem; }

.block-has-bg {
  padding: 1.25rem 1.5rem;
  border-radius: 8px;
}

.block-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: start;
}

.block-row > .lesson-block {
  margin-bottom: 0;
}

@media (max-width: 720px) {
  .block-row {
    grid-template-columns: 1fr;
  }
}

.lesson-image {
  margin: 0;
}

.lesson-image img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
}

.lesson-image figcaption {
  margin-top: 0.4rem;
}

.video-embed {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: black;
}

.video-embed iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Banner: a wide, short hero strip that always spans the full content
   column (never narrow) -- forcing the aspect ratio here means it reads
   as a banner even if the admin skipped the crop tool's "Banner" preset. */
.lesson-banner {
  position: relative;
  margin: 0;
  aspect-ratio: 3 / 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--color-border);
}

.lesson-banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.lesson-banner-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 2rem 1.5rem 1.25rem;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), rgba(0, 0, 0, 0));
  color: white;
  font-weight: 700;
  font-size: 1.15rem;
}

@media (max-width: 480px) {
  .lesson-banner {
    aspect-ratio: 16 / 9;
  }
}

.lesson-divider {
  margin: 0;
  border: none;
  border-top: 2px solid var(--color-border);
}

.lesson-continue {
  text-align: center;
}

.lesson-continue-btn {
  font-size: 1rem;
  padding: 0.75rem 2rem;
}

.lesson-gate {
  animation: lesson-gate-reveal 0.3s ease;
}

@keyframes lesson-gate-reveal {
  from { opacity: 0; }
  to { opacity: 1; }
}

.block-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  column-gap: 1rem;
  margin-bottom: 1.5rem;
}

.block-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex: 1 1 100%;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  background: white;
  /* Default gap between cards -- overridden per-block by whichever
     block-item-spacing-* class its own Spacing setting adds, so
     Compact/Normal/Spacious are actually visible in the editor. */
  margin-bottom: 1.75rem;
}

.block-item-spacing-compact { margin-bottom: 0.75rem; }
.block-item-spacing-normal { margin-bottom: 1.75rem; }
.block-item-spacing-spacious { margin-bottom: 3.5rem; }

/* A block with a background color reads as a small floating chip if the
   card keeps its full padding around it -- tighten the card so the color
   visibly IS the block, not an inset shape sitting inside white space. */
.block-item:has(.block-has-bg) {
  padding: 0.5rem;
}

/* Blocks marked "side-by-side with the next block" (see Design panel) sit
   two to a row here too, so the editor matches what learners will see. */
.block-item-half {
  flex: 1 1 calc(50% - 0.5rem);
}

@media (max-width: 720px) {
  .block-item-half {
    flex-basis: 100%;
  }
}

.block-item-body {
  min-width: 0;
  flex: 1;
}

/* The block content preview reuses the learner-facing partial and its
   spacing classes, but in the editor spacing is shown by the card's own
   block-item-spacing-* margin (above) instead, so cancel the inner
   duplicate to avoid double-spacing inside the card. */
.block-item-body .lesson-block {
  margin-bottom: 0;
}

.drag-handle {
  flex-shrink: 0;
  cursor: grab;
  color: var(--color-muted);
  font-size: 1.25rem;
  line-height: 1;
  padding: 0.25rem 0.1rem;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.sortable-ghost {
  opacity: 0.4;
}

.sortable-chosen {
  box-shadow: 0 0 0 2px var(--color-accent);
}

.block-item-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  flex-shrink: 0;
}

.block-select-btn {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
  white-space: nowrap;
}

.block-select-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.block-item.selected {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.block-item.selected .block-select-btn {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* Clicking the image itself is a shortcut for the "Edit image" button. */
.block-image-clickable {
  cursor: pointer;
}

.edit-image-preview {
  display: block;
  max-width: 100%;
  border-radius: 8px;
  margin-bottom: 1rem;
  background: var(--color-bg);
}

/* Two-pane lesson editor: live block canvas on the left, a sticky Design
   panel on the right (Google Sites-style) instead of per-block controls
   inline in the list. */

.editor-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.editor-canvas {
  flex: 1;
  min-width: 0;
}

.editor-panel {
  width: 320px;
  flex-shrink: 0;
  position: sticky;
  top: 1.5rem;
}

.editor-panel-section {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  background: white;
}

.editor-panel-section h3 {
  margin-top: 0;
}

@media (max-width: 960px) {
  .editor-layout {
    flex-direction: column;
  }
  .editor-panel {
    width: 100%;
    position: static;
  }
}

/* Layout picker: visual thumbnail tiles for adding content, instead of a
   stack of plain-text accordions. */

.layout-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  max-width: 760px;
}

.layout-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 0.5rem;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}

.layout-tile:hover {
  border-color: var(--color-accent);
}

.layout-tile.active {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent);
}

.layout-thumb {
  width: 100%;
  height: 56px;
  background: var(--color-bg);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px;
}

.layout-thumb-split {
  justify-content: space-between;
}

.thumb-img {
  flex: 1;
  align-self: stretch;
  background: var(--color-border);
  border-radius: 3px;
}

.thumb-lines {
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.thumb-lines span {
  display: block;
  height: 3px;
  background: var(--color-border);
  border-radius: 2px;
}

.thumb-lines span:last-child {
  width: 65%;
}

.thumb-play,
.thumb-icon {
  font-size: 1.25rem;
  color: var(--color-muted);
}

/* "Image, centered" thumbnail: a small inset square rather than a
   full-bleed rectangle, hinting that the image won't stretch to fill. */
.thumb-img-small {
  flex: 0 0 auto;
  width: 28px;
  align-self: center;
}

.thumb-banner {
  flex: 1;
  align-self: center;
  height: 18px;
  background: var(--color-border);
  border-radius: 3px;
}

.thumb-divider {
  flex: 1;
  align-self: center;
  height: 2px;
  background: var(--color-muted);
}

.thumb-continue-btn {
  align-self: center;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  background: var(--color-accent);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
}

.layout-form-panel {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  background: white;
  margin-bottom: 1.25rem;
}

/* Crop-before-upload modal */

.crop-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}

.crop-modal-inner {
  background: white;
  border-radius: 8px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.crop-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.crop-ratio-buttons {
  display: flex;
  gap: 0.4rem;
}

.crop-ratio-buttons button {
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.3rem 0.6rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}

.crop-ratio-buttons button.active {
  border-color: var(--color-accent);
  color: white;
  background: var(--color-accent);
}

.crop-modal-image-wrap {
  flex: 1;
  min-height: 320px;
  max-height: 60vh;
  background: #111;
}

.crop-modal-image-wrap img {
  display: block;
  max-width: 100%;
}

.crop-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
}

.block-type-label {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
  margin-bottom: 0.4rem;
}

/* Trix rich text editor (text blocks in the lesson editor) */

trix-editor {
  min-height: 8rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.75rem;
  font: inherit;
  background: white;
}

trix-toolbar .trix-button-group {
  border-color: var(--color-border);
}

trix-toolbar .trix-button {
  color: var(--color-text);
  border-color: var(--color-border);
}

trix-toolbar .trix-button.trix-active {
  background: var(--color-bg);
}

/* Image/Attachment blocks already handle uploads; hide Trix's own file
   button. !important because trix.css loads after this file and would
   otherwise win the cascade at equal specificity. */
trix-toolbar .trix-button-group--file-tools {
  display: none !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1e1f19;
    --color-text: #f0efee;
    --color-accent: #b7b7b6;
    --color-border: #3f4136;
    --color-muted: #9b907f;
  }
  .site-header, .card, .player-sidebar, .curriculum-preview > li, .block-item { background: #262820; }
  trix-editor { background: #262820; }
}

/* Admin is a working tool, not public-facing — always light, regardless of
   the visitor's system dark mode, so it stays easy to read while editing. */
body.admin {
  --color-bg: #f0efee;
  --color-text: #4f5141;
  --color-accent: #726352;
  --color-border: #b7b7b6;
  --color-muted: #9b907f;
}

body.admin .site-header,
body.admin .card,
body.admin .player-sidebar,
body.admin .curriculum-preview > li,
body.admin .block-item {
  background: white;
}

body.admin trix-editor {
  background: white;
}

.theme-swatch-row {
  display: inline-flex;
  gap: 0.25rem;
}

.theme-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  display: inline-block;
}

.theme-form-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: flex-start;
}

.theme-form-layout .form {
  flex: 1 1 320px;
}

.theme-form-layout input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 0.2rem;
  cursor: pointer;
}

.theme-preview {
  flex: 1 1 280px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
  --preview-bg: #f0efee;
  --preview-text: #4f5141;
  --preview-accent: #726352;
  --preview-border: #b7b7b6;
  --preview-muted: #9b907f;
}

.theme-preview-header {
  background: white;
  border-bottom: 1px solid var(--preview-border);
  padding: 0.75rem 1rem;
  font-weight: 700;
}

.theme-preview-body {
  background: var(--preview-bg);
  color: var(--preview-text);
  padding: 1.25rem;
}

.theme-preview-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.theme-preview-text {
  margin: 0 0 0.5rem;
}

.theme-preview-meta {
  color: var(--preview-muted);
  font-size: 0.875rem;
  margin: 0 0 1rem;
}

.theme-preview-button {
  display: inline-block;
  background: var(--preview-accent);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
}

.preview-banner {
  background: #fff6e0;
  border: 1px solid #e0c988;
  color: #6b5518;
  padding: 0.6rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}
