:root {
  --ink: #f5efe4;
  --ink-soft: rgba(245, 239, 228, 0.74);
  --ink-muted: rgba(245, 239, 228, 0.54);
  --paper: #f2eadc;
  --paper-ink: #211f1a;
  --paper-muted: #70695b;
  --line: rgba(245, 239, 228, 0.18);
  --line-strong: rgba(245, 239, 228, 0.34);
  --shade: rgba(11, 10, 8, 0.74);
  --shade-soft: rgba(11, 10, 8, 0.48);
  --panel: rgba(21, 19, 15, 0.86);
  --panel-solid: #181611;
  --accent: #c7975b;
  --accent-strong: #e3b978;
  --green: #6f8f70;
  --danger: #bb6a58;
  --radius: 8px;
  --font: "Avenir Next", "Helvetica Neue", Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: #11100d;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  font-size: 14px;
  line-height: 1.25;
}

.setup-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 30% 24%, rgba(199, 151, 91, 0.12), transparent 28%),
    linear-gradient(140deg, #16130f, #0c0b09 62%, #17140f);
}

.setup-card {
  width: min(560px, 100%);
  border: 1px solid var(--line);
  background: rgba(18, 16, 12, 0.82);
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.24);
}

.setup-card p {
  color: var(--ink-soft);
  margin-top: 8px;
}

.setup-card form,
.field-grid,
.form-stack {
  display: grid;
  gap: 12px;
}

.setup-card form {
  margin-top: 20px;
}

.shell {
  height: 100vh;
  position: relative;
  overflow: hidden;
  background: #11100d;
}

.world-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.16), rgba(0, 0, 0, 0.54)),
    var(--bg-image, radial-gradient(circle at 50% 40%, #3d3529, #15120e 68%));
  background-size: cover;
  background-position: center;
  isolation: isolate;
}

.world-stage::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.22), transparent 22%, transparent 72%, rgba(0, 0, 0, 0.26)),
    radial-gradient(circle at 52% 45%, transparent, rgba(0, 0, 0, 0.36) 72%);
  pointer-events: none;
  z-index: 1;
}

.world-stage.empty {
  background:
    radial-gradient(circle at 50% 42%, rgba(199, 151, 91, 0.16), transparent 27%),
    linear-gradient(145deg, #221d16, #0f0e0b);
}

.world-stage.placing {
  cursor: crosshair;
}

.fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.fx-light {
  background:
    radial-gradient(circle at 24% 30%, rgba(255, 193, 110, 0.16), transparent 20%),
    radial-gradient(circle at 74% 72%, rgba(255, 172, 84, 0.12), transparent 24%);
  animation: breathe 5s ease-in-out infinite alternate;
}

.mood-pluie .fx-rain {
  background-image:
    linear-gradient(115deg, rgba(255, 255, 255, 0.15) 0 1px, transparent 1px 12px);
  background-size: 70px 70px;
  opacity: 0.26;
  animation: rain 0.8s linear infinite;
}

.mood-brume .fx-fog {
  background:
    radial-gradient(circle at 10% 70%, rgba(230, 222, 203, 0.12), transparent 24%),
    radial-gradient(circle at 84% 48%, rgba(230, 222, 203, 0.10), transparent 26%);
  filter: blur(12px);
  animation: drift 14s ease-in-out infinite alternate;
}

.mood-alerte .fx-light {
  background:
    radial-gradient(circle at 18% 28%, rgba(188, 78, 54, 0.22), transparent 19%),
    radial-gradient(circle at 75% 72%, rgba(255, 180, 82, 0.16), transparent 24%);
}

.mood-nuit::before {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.36), transparent 24%, transparent 70%, rgba(0, 0, 0, 0.42)),
    radial-gradient(circle at 52% 45%, rgba(21, 20, 28, 0.18), rgba(0, 0, 0, 0.64) 76%);
}

.no-effects .fx {
  display: none;
}

.topbar {
  position: relative;
  z-index: 8;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  pointer-events: none;
}

.topbar > * {
  pointer-events: auto;
}

.place-line {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.navigation-label {
  color: var(--ink-muted);
}

.place-line button {
  color: inherit;
  border: 0;
  background: transparent;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.top-actions,
.dock-actions,
.row-actions,
.modal-actions,
.switch-row,
.hotspot-actions,
.quick-list {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button,
.icon-button,
.chip-button,
.ghost-link {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(20, 18, 14, 0.72);
  min-height: 34px;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  font-weight: 650;
}

.button.primary {
  color: #19150f;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button.paper {
  color: var(--paper-ink);
  background: var(--paper);
  border-color: #cfc4af;
}

.button.danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.button:hover,
.icon-button:hover,
.chip-button:hover,
.ghost-link:hover {
  border-color: rgba(245, 239, 228, 0.56);
}

.icon-button {
  width: 34px;
  display: grid;
  place-items: center;
  padding: 0;
}

.chip-button {
  padding: 6px 9px;
}

.chip-button.is-active {
  color: #19150f;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ghost-link {
  padding: 6px 9px;
  text-decoration: none;
}

.empty-world {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  width: min(520px, calc(100vw - 36px));
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  background: rgba(18, 16, 12, 0.82);
  border-radius: 10px;
  padding: 22px;
}

.empty-world p {
  color: var(--ink-soft);
  margin-top: 8px;
}

.empty-world .button {
  margin-top: 16px;
}

.hotspot {
  --x: 50%;
  --y: 50%;
  position: absolute;
  left: var(--x);
  top: var(--y);
  z-index: 4;
  transform: translate(-50%, -50%);
  border: 0;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
  padding: 16px;
}

.hotspot::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255, 244, 216, 0.78);
  background: rgba(19, 16, 12, 0.62);
  box-shadow: 0 0 0 4px rgba(199, 151, 91, 0.11);
  rotate: 45deg;
  transition: background 140ms ease, scale 140ms ease, border-color 140ms ease;
}

.hotspot:hover::before,
.hotspot.is-active::before {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  scale: 1.18;
}

.hotspot-label {
  position: absolute;
  left: 50%;
  top: calc(100% - 5px);
  translate: -50% 0;
  min-width: max-content;
  max-width: 220px;
  border: 1px solid var(--line);
  background: rgba(17, 15, 11, 0.88);
  border-radius: 6px;
  padding: 5px 8px;
  opacity: 0;
  color: var(--ink);
  pointer-events: none;
  transition: opacity 140ms ease;
}

.hotspot:hover .hotspot-label,
.hotspot.is-active .hotspot-label {
  opacity: 1;
}

.location-switcher {
  position: absolute;
  left: 20px;
  top: 92px;
  z-index: 9;
  width: min(360px, calc(100vw - 40px));
  border: 1px solid var(--line);
  background: rgba(18, 16, 12, 0.92);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  gap: 4px;
}

.switcher-item,
.list-item,
.scene-item,
.character-choice {
  width: 100%;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 9px;
}

.switcher-item:hover,
.list-item:hover,
.scene-item:hover,
.character-choice:hover {
  background: rgba(255, 255, 255, 0.06);
}

.switcher-item.is-active,
.list-item.is-active,
.scene-item.is-active,
.character-choice.is-active {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
}

.stage-note {
  position: absolute;
  left: 20px;
  bottom: 104px;
  z-index: 5;
  max-width: min(430px, calc(100vw - 40px));
  border: 1px solid var(--line);
  background: rgba(17, 15, 11, 0.72);
  border-radius: var(--radius);
  padding: 12px;
}

.stage-note p {
  color: var(--ink-soft);
  margin-top: 5px;
}

.hotspot-drawer,
.reader,
.mj-drawer,
.library-drawer {
  position: absolute;
  z-index: 10;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  border-radius: 10px;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.28);
}

.hotspot-drawer {
  left: 20px;
  bottom: 96px;
  width: min(480px, calc(100vw - 40px));
  max-height: calc(100vh - 180px);
  overflow: auto;
}

.drawer-head,
.reader-head,
.mj-head,
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-body,
.mj-body,
.library-body {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.muted {
  color: var(--ink-soft);
}

.tiny {
  color: var(--ink-muted);
  font-size: 12px;
}

.scene-list {
  display: grid;
  gap: 7px;
}

.scene-item {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.scene-item p {
  color: var(--ink-soft);
  margin-top: 4px;
}

.meta-line {
  color: var(--ink-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 7px;
  font-size: 12px;
}

.reader {
  inset: 72px 20px 96px auto;
  width: min(720px, calc(100vw - 40px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.mj-open .reader {
  left: 20px;
  right: 430px;
  width: auto;
}

.reader-body {
  overflow: auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.post {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 16px;
  border-bottom: 1px solid rgba(245, 239, 228, 0.12);
  padding-bottom: 18px;
}

.post:last-child {
  border-bottom: 0;
}

.avatar {
  width: 52px;
  height: 68px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 750;
  background-size: cover;
  background-position: center;
  border: 1px solid rgba(245, 239, 228, 0.2);
}

.avatar.small {
  width: 38px;
  height: 48px;
  font-size: 12px;
}

.avatar.portrait {
  color: transparent;
}

.post-avatar {
  width: 78px;
  height: 108px;
}

.composer-avatar,
.choice-avatar,
.list-avatar {
  width: 44px;
  height: 58px;
}

.dock-avatar {
  width: 64px;
  height: 84px;
}

.post-copy {
  color: rgba(255, 249, 236, 0.88);
  white-space: pre-wrap;
}

.composer {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
  display: grid;
  gap: 10px;
  background: rgba(12, 11, 9, 0.42);
}

.composer textarea {
  min-height: 118px;
  resize: vertical;
}

.character-dock {
  position: absolute;
  left: 50%;
  bottom: 18px;
  z-index: 12;
  translate: -50% 0;
  width: min(820px, calc(100vw - 36px));
  border: 1px solid var(--line);
  background: rgba(17, 15, 11, 0.86);
  backdrop-filter: blur(14px);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.character-active {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.character-active strong,
.character-active span,
.post strong,
.post span,
.list-title,
.list-subtitle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-active span {
  color: var(--ink-soft);
  font-size: 12px;
}

.mj-drawer,
.library-drawer {
  top: 72px;
  right: 20px;
  bottom: 96px;
  width: min(390px, calc(100vw - 40px));
  overflow: auto;
}

.mj-body h3 {
  margin-bottom: 8px;
}

.quick-list {
  align-items: stretch;
}

.quick-list .button {
  flex: 1 1 160px;
  justify-content: center;
}

.section-box {
  border: 1px solid rgba(245, 239, 228, 0.14);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, 0.035);
}

.list-stack {
  display: grid;
  gap: 6px;
}

.list-item {
  display: grid;
  gap: 3px;
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.035);
}

.location-row {
  gap: 8px;
}

.location-main {
  width: 100%;
  display: grid;
  gap: 3px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0;
}

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

.location-controls .chip-button {
  min-height: 30px;
  padding: 4px 8px;
}

.danger-text {
  color: #f1b2a6;
  border-color: rgba(187, 106, 88, 0.42);
}

.list-title {
  font-weight: 700;
}

.list-subtitle {
  color: var(--ink-muted);
  font-size: 12px;
}

.form-label {
  display: grid;
  gap: 5px;
  color: var(--ink-soft);
  font-size: 12px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(13, 12, 10, 0.72);
  color: var(--ink);
  min-height: 36px;
  padding: 8px 9px;
}

input[type="file"] {
  padding: 7px;
}

textarea {
  min-height: 92px;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(227, 185, 120, 0.42);
  outline-offset: 1px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: 18px;
}

.modal {
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  background: #17140f;
  border-radius: 10px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.36);
}

.modal-body {
  padding: 14px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 4px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.character-choice {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-color: var(--line);
}

.character-list-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.character-list-row > span:last-child {
  min-width: 0;
}

.paper-panel {
  background: var(--paper);
  color: var(--paper-ink);
}

.paper-panel .muted,
.paper-panel .tiny {
  color: var(--paper-muted);
}

.paper-panel input,
.paper-panel textarea,
.paper-panel select {
  color: var(--paper-ink);
  background: #fffaf0;
  border-color: #cfc4af;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 50;
  translate: -50% 0;
  max-width: min(520px, calc(100vw - 36px));
  border-radius: var(--radius);
  background: #f4ead9;
  color: #211f1a;
  padding: 9px 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

#toast.is-visible {
  opacity: 1;
}

@keyframes rain {
  from {
    background-position: 0 0;
  }
  to {
    background-position: -70px 70px;
  }
}

@keyframes breathe {
  from {
    opacity: 0.7;
  }
  to {
    opacity: 1;
  }
}

@keyframes drift {
  from {
    translate: -2% 0;
  }
  to {
    translate: 3% -1%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .shell {
    min-height: 100vh;
    height: auto;
    overflow: visible;
  }

  .world-stage {
    position: fixed;
    min-height: 100vh;
    background-image:
      linear-gradient(180deg, rgba(0, 0, 0, 0.14), rgba(0, 0, 0, 0.62)),
      var(--bg-image-mobile, var(--bg-image));
  }

  .topbar {
    position: relative;
    padding: 14px;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions .button,
  .top-actions .chip-button {
    flex: 1;
    justify-content: center;
  }

  .location-switcher,
  .stage-note,
  .hotspot-drawer,
  .reader,
  .mj-drawer,
  .library-drawer,
  .character-dock,
  .empty-world {
    position: relative;
    inset: auto;
    left: auto;
    right: auto;
    bottom: auto;
    top: auto;
    width: calc(100vw - 28px);
    margin: 14px;
    translate: 0 0;
  }

  .mj-open .reader {
    left: auto;
    right: auto;
    width: calc(100vw - 28px);
  }

  .empty-world {
    transform: none;
  }

  .reader,
  .mj-drawer,
  .library-drawer {
    max-height: none;
    overflow: visible;
  }

  .reader {
    min-height: 520px;
  }

  .character-dock {
    display: grid;
  }

  .dock-actions .button {
    flex: 1;
    justify-content: center;
  }

  .character-grid {
    grid-template-columns: 1fr;
  }

  .hotspot-label {
    opacity: 1;
  }
}
