@font-face {
  font-family: "Anime Ace";
  src: url("../fonts/animeace2_reg.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Anime Ace";
  src: url("../fonts/animeace2_bld.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Anime Ace";
  src: url("../fonts/animeace2_ital.ttf") format("truetype");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #12141a;
  --panel: #1a1d26;
  --panel-2: #222632;
  --border: #2e3444;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #6c9eff;
  --accent-2: #3d6fd4;
  --danger: #e85d5d;
  --ok: #5dce8a;
  --used: #3a4255;
  --placed: #3ecf9a;
  --placed-bg: rgba(62, 207, 154, 0.1);
  --placed-border: #3ecf9a;
  --radius: 10px;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100vh;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.brand {
  gap: 0.75rem;
  min-width: 9rem;
}

.brand strong {
  letter-spacing: 0.02em;
}

#page-indicator {
  color: var(--muted);
  font-size: 0.9rem;
}

.chapter-select {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.chapter-select.hidden {
  display: none;
}

.chapter-select select {
  max-width: 14rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.25rem 0.35rem;
}

.opts label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.opts input[type="number"] {
  width: 4.2rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.4rem;
}

.gray-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Left panel: label/swatch/value/pipette on first row, slider full-width below */
.gray-control.stack {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  grid-template-areas:
    "label . swatch val pipette"
    "range range range range range";
  align-items: center;
  column-gap: 0.4rem;
  row-gap: 0.35rem;
  width: 100%;
  min-width: 0;
  margin-bottom: 0.65rem;
  box-sizing: border-box;
}

.gray-control.stack .gray-label {
  grid-area: label;
}

.gray-control.stack .gray-range {
  grid-area: range;
  width: 100%;
  min-width: 0;
  max-width: none;
}

.gray-control.stack .gray-swatch {
  grid-area: swatch;
  justify-self: end;
}

.gray-control.stack .gray-val {
  grid-area: val;
}

.gray-control.stack .btn-pipette {
  grid-area: pipette;
}

.gray-label {
  min-width: 2.4rem;
  font-size: 0.78rem;
}

.gray-range {
  width: 5.5rem;
  min-width: 4.5rem;
  accent-color: #9aa3b5;
  cursor: pointer;
}

.gray-swatch {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #000;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.gray-val {
  min-width: 1.6rem;
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: right;
}

.btn-pipette {
  width: 1.7rem;
  height: 1.7rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  border-radius: 6px;
}

.btn-pipette .icon-pipette {
  display: block;
  flex-shrink: 0;
}

.btn-pipette.active {
  background: var(--accent-2);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 1px var(--accent);
}

.canvas-wrap.pipette-active {
  cursor: crosshair !important;
}

.canvas-wrap.pipette-active::after {
  content: "Pipette — clic pour prélever";
  position: absolute;
  top: 0.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(26, 29, 38, 0.92);
  border: 1px solid var(--accent);
  color: var(--text);
  font-size: 0.78rem;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  pointer-events: none;
  z-index: 4;
  white-space: nowrap;
}

.check {
  gap: 0.35rem !important;
  cursor: pointer;
  user-select: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: #2a3142;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent-2);
  border-color: var(--accent);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
  color: #0b1020;
}

.btn.danger {
  border-color: #7a3030;
  color: #ffb4b4;
}

.btn.danger:hover:not(:disabled) {
  background: #4a2020;
  border-color: var(--danger);
}

.menu-wrap {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 17.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.dropdown-menu.hidden {
  display: none;
}

.dropdown-item {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  width: 100%;
}

.dropdown-item:hover {
  background: #2a3142;
}

.dropdown-item .hint,
.dropdown-check .hint {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 400;
  max-width: 15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-item .hint.set {
  color: var(--ok);
}

.dropdown-sep {
  height: 1px;
  background: var(--border);
  margin: 0.25rem 0.4rem;
}

.dropdown-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  margin-top: 0.1rem;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.dropdown-check input {
  margin-top: 0.2rem;
  accent-color: var(--placed);
}

/* —— Modal load project —— */
.modal.hidden {
  display: none;
}

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

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

.modal-panel {
  position: relative;
  width: min(32rem, 100%);
  max-height: min(90vh, 40rem);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-body {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.load-field {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem;
}

.load-field-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.load-field-head .req {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #ffb4b4;
  background: #3a2020;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.load-field-head .opt {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.load-field-hint {
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.load-field-hint code {
  font-size: 0.85em;
  color: var(--accent);
}

.load-field-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.load-status {
  font-size: 0.82rem;
  max-width: 100%;
  word-break: break-word;
}

.load-status.ready {
  color: var(--ok);
}

body.modal-open {
  overflow: hidden;
}

.bubble-hint {
  margin: 0 0 0.55rem;
  line-height: 1.35;
}

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  min-height: 0;
}

.side {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 1rem;
}

.text-panel {
  border-right: none;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
}

.text-panel-header {
  padding: 0.9rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.text-panel-header h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.text-edit-hint {
  margin: 0.4rem 0 0;
  line-height: 1.35;
}

.text-edit-hint kbd {
  font-size: 0.75em;
  padding: 0.05rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel-2);
}

.hint-card,
.bubble-editor {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin-bottom: 1rem;
}

.hint-card h3,
.bubble-editor h3 {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
}

.hint-card ol {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.hint-card li + li {
  margin-top: 0.35rem;
}

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

.bubble-editor label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}

.bubble-editor .gray-control.stack {
  min-width: 0;
  width: 100%;
}

.bubble-editor label.check {
  flex-direction: row;
  align-items: center;
}

.bubble-editor input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.45rem;
}

.bubble-editor.hidden {
  display: none;
}

.canvas-panel {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: stretch;
  min-width: 0;
  min-height: 0;
  background: #0c0e13;
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 2rem;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.nav-btn:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: crosshair;
}

#main-canvas {
  max-width: 100%;
  max-height: 100%;
  box-shadow: var(--shadow);
  background: #fff;
}

.drop-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  pointer-events: none;
  font-size: 1rem;
}

.drop-hint.hidden {
  display: none;
}

.text-list {
  flex: 1;
  overflow: auto;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.text-item {
  text-align: left;
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  transition: border-color 0.15s, background 0.15s, opacity 0.15s;
}

.text-item:hover {
  border-color: var(--accent);
}

.text-item.active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Placé = contour bien visible pour repérer l’avancement */
.text-item.used {
  background: var(--placed-bg);
  border: 2px solid var(--placed-border);
  box-shadow:
    0 0 0 1px rgba(62, 207, 154, 0.25),
    inset 3px 0 0 0 var(--placed);
}

.text-item.used:hover {
  border-color: #6ee0b0;
  box-shadow:
    0 0 0 2px rgba(62, 207, 154, 0.35),
    inset 3px 0 0 0 #6ee0b0;
}

.text-item.used.active {
  border-color: var(--accent);
  box-shadow:
    0 0 0 1px var(--accent),
    inset 3px 0 0 0 var(--placed);
}

.text-item.used .fr-edit {
  border-color: rgba(62, 207, 154, 0.35);
  background: rgba(0, 0, 0, 0.25);
}

/* Édité mais pas encore placé */
.text-item.edited:not(.used) {
  border-color: #c9a227;
  box-shadow: inset 3px 0 0 0 #c9a227;
}

/* Placé + modifié : vert placé prioritaire, badge reste */
.text-item.used.edited {
  border-color: var(--placed-border);
}

.text-item .meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  align-items: center;
}

.text-item .ids {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.text-item .placed-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #0b1a12;
  background: var(--placed);
  border-radius: 4px;
  padding: 0.12rem 0.35rem;
  font-weight: 700;
}

.text-item .edited-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #f0e0a0;
  background: #3d3420;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
}

.text-item .orig {
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--muted);
  font-style: italic;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.35rem;
  opacity: 0.9;
}

.text-item .fr-edit {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 2.6rem;
  max-height: 180px;
  box-sizing: border-box;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
  white-space: pre-wrap;
}

.text-item .fr-edit:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(108, 158, 255, 0.35);
}

.text-item .text-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.text-item .text-actions-left {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  min-width: 0;
}

.text-item .btn-place {
  font-size: 0.78rem;
  padding: 0.28rem 0.55rem;
  background: #2a3a55;
  border-color: #4a6a9a;
}

.text-item .btn-place:hover {
  background: var(--accent-2);
  border-color: var(--accent);
}

.text-item .btn-reset {
  font-size: 0.75rem;
  padding: 0.28rem 0.5rem;
  color: var(--muted);
}

/* + insert after this script card */
.text-item .btn-add-after {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border-radius: 999px;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border-color: #4a6a9a;
  background: #1a2438;
  margin-left: auto;
}

.text-item .btn-add-after:hover {
  background: var(--accent-2);
  border-color: var(--accent);
  color: #fff;
}

.text-item.custom {
  border-style: dashed;
}

.text-item .custom-badge {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #c5d4ff;
  background: #2a3550;
  border-radius: 4px;
  padding: 0.1rem 0.3rem;
}

.text-item .custom-hint {
  font-style: italic;
  opacity: 0.75;
}

.text-list-empty {
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-start;
}

.text-list-empty .btn-add-line {
  font-size: 0.85rem;
}

.text-item .speaker {
  color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #2a3142;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.65rem 1rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: 0.9rem;
  max-width: min(90vw, 32rem);
  text-align: center;
}

.toast.hidden {
  display: none;
}

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

.toast.ok {
  border-color: var(--ok);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr 280px;
  }

  .left-hint {
    display: none;
  }
}

@media (max-width: 760px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 40vh;
  }

  .text-panel {
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .canvas-panel {
    grid-template-columns: 36px 1fr 36px;
    min-height: 45vh;
  }
}

/* —— Login page ———————————————————————————————— */

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(108, 158, 255, 0.12), transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(61, 111, 212, 0.1), transparent 45%),
    var(--bg);
}

.login-card {
  width: min(100%, 380px);
  padding: 1.75rem 1.5rem 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.login-card > .muted {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-card input[type="text"],
.login-card input[type="password"] {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 158, 255, 0.2);
}

.login-submit {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
}

.login-error {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--danger);
  background: rgba(232, 93, 93, 0.12);
  color: #ffc9c9;
  font-size: 0.85rem;
}

.login-error.hidden {
  display: none;
}

.btn-logout {
  font-size: 0.8rem;
  opacity: 0.85;
}
