:root {
  --bg: #080b12;
  --panel: #0e1522;
  --panel-2: #131b2a;
  --panel-3: #17202f;
  --line: #1e2a3d;
  --line-soft: #17202f;
  --text: #e6ebf4;
  --muted: #8b98ad;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --ok: #3ecf8e;
  --danger: #ff7a7a;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", -apple-system, BlinkMacSystemFont, Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

code,
pre {
  font-family: "Cascadia Code", "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.hidden {
  display: none !important;
}

/* ------------------------------- topbar ---------------------------------- */

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0c1220, #0a0f19);
}

.brand {
  display: flex;
  gap: 11px;
  align-items: center;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(150deg, #4c8dff, #2f6ae0);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(76, 141, 255, 0.35);
}

.brand strong {
  display: block;
  font-size: 14px;
  letter-spacing: 0.2px;
}

.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.3px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid #1f3a2e;
  background: #0d1a15;
  color: #9ee7c4;
  font-size: 11.5px;
  letter-spacing: 0.3px;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.7);
}

/* ------------------------------- layout ---------------------------------- */

.layout {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: 264px minmax(420px, 1fr) minmax(380px, 0.95fr);
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 14px 14px 10px;
}

.sidebar-head input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0a111c;
  color: var(--text);
  font-size: 12.5px;
  outline: none;
}

.sidebar-head input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.templates {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 16px;
}

.group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: #6c7a91;
  padding: 14px 6px 6px;
}

.template {
  width: 100%;
  text-align: left;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}

.template:hover {
  background: var(--panel-2);
}

.template.active {
  background: var(--accent-soft);
  border-color: rgba(76, 141, 255, 0.35);
}

.template-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.template-meta {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 7px;
  flex: none;
  background: #3d4a60;
}

.template.active .dot {
  background: var(--accent);
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 16px 16px;
}

.hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ------------------------------ composer --------------------------------- */

.composer {
  padding: 26px 30px 40px;
  overflow-y: auto;
  min-height: 0;
}

.composer-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 20px;
}

.composer-title h1 {
  margin: 0 0 4px;
  font-size: 20px;
  letter-spacing: -0.2px;
}

.composer-title p {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  max-width: 46ch;
}

.formats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.format {
  border: 1px solid var(--line);
  background: #0a111c;
  color: var(--muted);
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  cursor: pointer;
}

.format[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: rgba(76, 141, 255, 0.5);
  color: #cfe0ff;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-width: 720px;
}

.field label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #93a1b8;
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 11px;
  background: #0a111c;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.field textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.55;
}

.field textarea.mono {
  font-family: "Cascadia Code", "JetBrains Mono", ui-monospace, monospace;
  font-size: 12.5px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field .help {
  margin-top: 5px;
  font-size: 11px;
  color: #6f7d93;
}

.field .invalid {
  border-color: var(--danger) !important;
}

.field-error {
  color: var(--danger);
  font-size: 11.5px;
  margin-top: 4px;
}

/* éditeur de lignes */

.rows {
  border: 1px solid var(--line);
  border-radius: 9px;
  overflow: hidden;
  background: #0a111c;
}

.rows-head,
.rows-row {
  display: grid;
  gap: 6px;
  padding: 6px 8px;
  align-items: center;
}

.rows-head {
  background: #0d1522;
  border-bottom: 1px solid var(--line);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: #7c8ba2;
}

.rows-row {
  border-bottom: 1px solid var(--line-soft);
}

.rows-row:last-child {
  border-bottom: 0;
}

.rows-row input {
  padding: 5px 7px;
  font-size: 12.5px;
  background: #0c1420;
}

.row-del {
  border: 0;
  background: transparent;
  color: #5d6a80;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 4px;
  border-radius: 5px;
}

.row-del:hover {
  color: var(--danger);
  background: rgba(255, 122, 122, 0.1);
}

.rows-foot {
  padding: 7px 8px;
  border-top: 1px solid var(--line-soft);
}

.add-row {
  border: 1px dashed #2b3a52;
  background: transparent;
  color: #8fb2ee;
  border-radius: 7px;
  padding: 5px 11px;
  font-size: 12px;
  cursor: pointer;
}

.add-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* actions */

.composer-foot {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: 18px;
  padding: 14px 0 6px;
  max-width: 720px;
  background: linear-gradient(180deg, rgba(8, 11, 18, 0) 0%, rgba(8, 11, 18, 0.92) 42%, var(--bg) 100%);
}

.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

button.primary {
  border: 0;
  border-radius: 9px;
  padding: 10px 20px;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(160deg, #4c8dff, #2f6ae0);
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(47, 106, 224, 0.35);
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.07);
}

button.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

button.small {
  padding: 6px 12px;
  font-size: 12px;
}

button.ghost,
a.ghost {
  border: 1px solid var(--line);
  background: #0d1523;
  color: #c3cfe2;
  border-radius: 8px;
  padding: 8px 13px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button.ghost:hover,
a.ghost:hover {
  border-color: #33445f;
  color: #e6ebf4;
}

.kbd-hint {
  margin: 10px 0 0;
  font-size: 11px;
  color: #64718a;
}

.status {
  font-size: 12.5px;
  color: var(--muted);
}

.status[data-state="ok"] {
  color: #9ee7c4;
}

.status[data-state="err"] {
  color: var(--danger);
}

/* ------------------------------- aperçu ---------------------------------- */

.preview {
  border-left: 1px solid var(--line);
  background: #0b111c;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.preview-head h2 {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #8fa0b8;
}

.preview-body {
  flex: 1;
  overflow: auto;
  padding: 16px 18px;
  min-height: 0;
}

.empty {
  width: 100%;
  height: 100%;
  min-height: 220px;
  padding: 0 18px;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 4px;
  border: 1px dashed #1f2b3d;
  border-radius: 12px;
  color: #6b7a90;
}

.empty p {
  margin: 0;
}

.muted {
  color: #64718a;
}

.small-pad {
  padding: 6px 2px;
}

.artifact-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  overflow: hidden;
}

.artifact-canvas {
  background: #ffffff;
  display: grid;
  place-items: center;
  padding: 10px;
}

.artifact-canvas.flat {
  background: #0b111c;
  padding: 14px;
}

.artifact-canvas img {
  max-width: 100%;
  max-height: 46vh;
  height: auto;
  display: block;
  border-radius: 4px;
}

.artifact-canvas iframe {
  width: 100%;
  height: 430px;
  border: 0;
  border-radius: 4px;
  background: #fff;
}

.artifact-meta {
  padding: 12px 14px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.artifact-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 13px;
  min-width: 0;
}

.artifact-title span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 11.5px;
  color: var(--muted);
}

.artifact-actions {
  display: flex;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  background: #1b2a45;
  color: #9fc0ff;
  border: 1px solid #27395a;
  flex: none;
}

.chip[data-kind="image"] {
  background: #16302a;
  color: #7fe0bb;
  border-color: #1f463b;
}

.chip[data-kind="sheet"] {
  background: #1d2f22;
  color: #a5e6a5;
  border-color: #2a4530;
}

.chip[data-kind="deck"] {
  background: #352117;
  color: #ffb894;
  border-color: #4a2e20;
}

/* historique */

.history {
  border-top: 1px solid var(--line);
  padding: 12px 18px 18px;
  max-height: 260px;
  overflow-y: auto;
  flex: none;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.history h3 {
  margin: 0;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7c8ba2;
}

.link {
  border: 0;
  background: transparent;
  color: #75839a;
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 5px;
}

.link:hover {
  color: #ff9b9b;
  background: rgba(255, 122, 122, 0.08);
}

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

.history-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.history-item:hover {
  background: var(--panel-2);
  border-color: var(--line);
}

.history-item .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12.5px;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
}

.history-item .name:hover {
  color: #9fc0ff;
  text-decoration: underline;
}

.history-item .when {
  font-size: 11px;
  color: #64718a;
  flex: none;
}

/* --------------------------------- toast --------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #16233a;
  border: 1px solid #2b3f5f;
  color: #dbe6f6;
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 60;
  box-shadow: var(--shadow);
}

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

.toast.error {
  border-color: #5a2a2a;
  background: #2a1618;
  color: #ffb3b3;
}

/* ----------------------------- responsive -------------------------------- */

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
    overflow: visible;
    min-height: calc(100vh - 58px);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .templates {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 12px 14px;
  }

  .group-label {
    display: none;
  }

  .template {
    width: auto;
    flex: none;
    border: 1px solid var(--line);
  }

  .dot {
    display: none;
  }

  .preview {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .artifact-canvas iframe {
    height: 420px;
  }
}
