:root {
  --bg: #0a0414;
  --panel: #150a2c;
  --panel-2: #1f1240;
  --cream: #f6efe2;
  --muted: rgba(246, 239, 226, 0.62);
  --line: rgba(246, 239, 226, 0.14);
  --gold: #ffd77a;
  --violet: #b57bff;
  --danger: #ff7a8a;
  --ok: #7ee2a8;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Baloo 2", "Segoe UI", system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(128, 38, 92, 0.35), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(80, 60, 180, 0.28), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.4;
}

a {
  color: inherit;
}

.container {
  width: min(1180px, 100% - 32px);
  margin: 0 auto;
}

.site-header {
  padding: 32px 0 8px;
}

.site-header .container {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.site-title {
  margin: 0;
  font-size: clamp(1.8rem, 5vw, 2.6rem);
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.01em;
}

.site-title small {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

main.container {
  padding-bottom: 64px;
}

/* --- boutons --- */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--cream);
  text-decoration: none;
  background: rgba(246, 239, 226, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
}

.btn:hover {
  background: rgba(246, 239, 226, 0.16);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  color: #1a0f00;
  background: var(--gold);
  border-color: var(--gold);
}

.btn-primary:hover {
  background: #ffe5a3;
}

.btn-danger {
  color: var(--danger);
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* --- liste publique --- */

.year-section {
  margin-top: 36px;
}

.year-title {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 16px;
  font-size: 1.5rem;
  font-weight: 700;
}

.year-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 20px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 215, 122, 0.5);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.thumb {
  display: block;
  aspect-ratio: 455 / 588;
  background: var(--panel-2);
  overflow: hidden;
}

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

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 16px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--gold);
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  padding: 14px 16px 16px;
}

.card-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.2;
}

.card-desc {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: pre-line;
}

.card-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.variants {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: auto;
  padding-top: 10px;
}

.empty {
  margin-top: 48px;
  text-align: center;
  color: var(--muted);
}

/* --- édition --- */

.panel {
  margin-top: 24px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.dropzone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px;
  border: 2px dashed rgba(255, 215, 122, 0.4);
  border-radius: var(--radius);
  background: rgba(255, 215, 122, 0.05);
}

.dropzone p {
  margin: 0;
  color: var(--muted);
}

.dropzone strong {
  color: var(--cream);
}

body.dragging .dropzone,
.course-row.drop-target {
  border-color: var(--gold);
  background: rgba(255, 215, 122, 0.14);
}

.course-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

.course-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.row-thumb {
  width: 64px;
  aspect-ratio: 455 / 588;
  border-radius: 6px;
  background: var(--panel-2);
  object-fit: cover;
}

.row-info h3 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.row-info .badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gold);
  border: 1px solid rgba(255, 215, 122, 0.5);
  border-radius: 999px;
  vertical-align: middle;
}

.row-info p {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.row-info .row-desc {
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.row-info .row-links a {
  margin-right: 10px;
  font-size: 0.82rem;
  color: var(--violet);
}

.row-info .row-error {
  color: var(--danger);
}

.row-info .row-warn {
  color: var(--gold);
}

.row-info .row-busy {
  color: var(--gold);
}

.row-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.row-actions .btn-primary {
  padding: 10px 16px;
  font-size: 1rem;
}

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

.row-actions .secondary .btn {
  flex: 1;
}

.bar {
  height: 6px;
  margin-top: 6px;
  overflow: hidden;
  background: rgba(246, 239, 226, 0.12);
  border-radius: 999px;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--gold);
  transition: width 0.15s;
}

.bar.indeterminate > span {
  width: 40%;
  animation: slide 1.1s ease-in-out infinite alternate;
}

@keyframes slide {
  from { margin-left: 0; }
  to { margin-left: 60%; }
}

/* --- boîtes de dialogue --- */

dialog {
  width: min(560px, 100% - 24px);
  max-height: calc(100vh - 24px);
  padding: 0;
  color: var(--cream);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
}

dialog::backdrop {
  background: rgba(5, 2, 12, 0.7);
}

dialog form,
.dialog-inner {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
}

dialog h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--gold);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--cream);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input:focus,
textarea:focus {
  outline: 2px solid rgba(255, 215, 122, 0.6);
  outline-offset: 1px;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

input[type="file"] {
  font: inherit;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.palette h3 {
  margin: 4px 0 2px;
  font-size: 1rem;
}

.palette .hint {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.palette-row {
  display: grid;
  grid-template-columns: 26px 1fr auto 44px auto;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--line);
}

.palette-row .arrow {
  color: var(--muted);
}

.palette-row input[type="color"] {
  width: 44px;
  height: 30px;
  padding: 0;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
}

.palette-row .count {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
}

.login-box {
  max-width: 380px;
  margin: 64px auto 0;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  max-width: min(520px, 100% - 32px);
  padding: 10px 16px;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  color: var(--cream);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  transition: opacity 0.2s, transform 0.2s;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.error {
  border-color: var(--danger);
  color: var(--danger);
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .course-row {
    grid-template-columns: 52px 1fr;
  }

  .row-thumb {
    width: 52px;
  }

  .row-actions {
    grid-column: 1 / -1;
  }

  .palette-row {
    grid-template-columns: 26px 1fr 44px auto;
  }

  .palette-row .arrow {
    display: none;
  }
}
