* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
	--bg: #f7f5f0;
	--panel: #ffffff;
	--ink: #26221c;
	--muted: #6f675c;
	--line: #e2dccf;
	--accent: #a4552c;
	--accent-ink: #fff;
	--bad: #9c3b30;
}

html, body { height: 100%; }

body {
	font-family: Georgia, 'Times New Roman', serif;
	background: var(--bg);
	color: var(--ink);
	line-height: 1.55;
}

.wrapper { max-width: 860px; margin: 0 auto; padding: 0 1rem; }

header { border-bottom: 1px solid var(--line); background: var(--panel); }
header .wrapper { display: flex; align-items: baseline; justify-content: space-between; padding: 0.9rem 1rem; }
header .title { font-size: 1.25rem; font-weight: bold; color: var(--ink); text-decoration: none; }
header nav a { margin-left: 1.2rem; color: var(--muted); text-decoration: none; font-size: 0.95rem; }
header nav a:hover { color: var(--accent); }

a { color: var(--accent); }
h2 { margin: 0.4rem 0; font-weight: bold; }
h3 { margin: 0 0 0.4rem; }

.list, .settings { padding: 1.6rem 1rem 3rem; }
.intro { color: var(--muted); margin-bottom: 1.2rem; }
.meta, .note { color: var(--muted); font-size: 0.85rem; margin: 0.3rem 0; }
.loading, .error { color: var(--muted); padding: 1rem 0; }
.error { color: var(--bad); }

.button {
	display: inline-block; cursor: pointer; user-select: none;
	background: var(--accent); color: var(--accent-ink);
	padding: 0.35rem 1.1rem; border-radius: 4px; margin: 0.6rem 0.4rem 0.6rem 0;
	text-decoration: none; font-family: inherit; font-size: 1rem;
}
.button:hover { filter: brightness(1.1); }
.button.secondary { background: var(--panel); color: var(--accent); border: 1px solid var(--accent); }

.world-card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 1rem 1.2rem; margin-bottom: 1rem; }
.world-card h2 a { text-decoration: none; }
.world-card .actions a { cursor: pointer; margin-right: 1rem; font-size: 0.85rem; }

.form .field { margin: 0.5rem 0; }
.form .field label { display: inline-block; width: 11rem; color: var(--muted); }
.form .field input[type="text"], .form .field input[type="password"], .form .field input[type="number"], .form .field select {
	font-family: inherit; font-size: 0.95rem; padding: 0.3rem 0.5rem;
	border: 1px solid var(--line); border-radius: 4px; width: min(28rem, 90%);
}
.form .field input[type="number"] { width: 6rem; }
.form fieldset { border: 1px solid var(--line); border-radius: 6px; margin: 0.8rem 0; padding: 0.6rem 1rem; }
.form legend { color: var(--muted); padding: 0 0.4rem; }

.world { position: fixed; inset: 0; background: var(--bg); overflow: hidden; }
.world .canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.world .canvas:active { cursor: grabbing; }

.entity { transition: opacity 1.4s ease; cursor: pointer; }
.entity.entering, .entity.leaving { opacity: 0; }
.entity.leaving { pointer-events: none; }
.entity.selected { filter: drop-shadow(0 0 5px var(--accent)); }

.world .foot {
	position: fixed; left: 0; right: 0; bottom: 0; padding: 0 1.2rem 1.2rem;
	display: flex; flex-direction: column; gap: 0.45rem; pointer-events: none;
}
.world .composer { pointer-events: auto; }
.world .composer input {
	width: 100%; font-family: inherit; font-size: 1.15rem; padding: 0.55rem 0.8rem;
	border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); outline: none;
	transition: opacity 0.4s ease;
}
.world .composer input:focus { border-color: var(--accent); }
.world.running .composer input { opacity: 0.45; }
.world .reply { color: var(--muted); font-style: italic; font-size: 1.05rem; white-space: pre-wrap; pointer-events: auto; }
.world .reply:empty { display: none; }
.world .happened { color: var(--ink); font-size: 0.95rem; }
.world .happened:empty { display: none; }
.world .happened.refused { color: var(--bad); }

.world .actions { display: flex; flex-wrap: wrap; gap: 0.4rem; pointer-events: auto; }
.world .actions[hidden] { display: none; }
.world .actions a {
	cursor: pointer; user-select: none; background: var(--panel); color: var(--accent);
	border: 1px solid var(--accent); border-radius: 4px; padding: 0.2rem 0.8rem;
	font-size: 0.9rem; text-decoration: none;
}
.world .actions a:hover { background: var(--accent); color: var(--accent-ink); }
.world.running .actions { opacity: 0.4; pointer-events: none; }

.world .composer { display: flex; gap: 0.5rem; align-items: stretch; }
.world .composer input { flex: 1; }
.world .commit {
	display: flex; align-items: center; cursor: pointer; user-select: none; white-space: nowrap;
	background: var(--accent); color: var(--accent-ink); border-radius: 6px; padding: 0 1rem; font-size: 0.95rem;
}
.world .commit[hidden] { display: none; }
.world.running .commit { opacity: 0.45; pointer-events: none; }

.entity.place { pointer-events: none; }
.entity .placeholder { color: var(--ink); }
.entity .placeholder.place { color: var(--muted); }
.world .tree-situation { white-space: pre-wrap; font-family: 'Courier New', monospace; font-size: 0.78rem; color: var(--muted); margin: 0.3rem 0; }
.world .tree-log li.pending { color: var(--accent); }
.world .status { color: var(--bad); font-size: 0.85rem; }
.world .status:empty { display: none; }

.world .thoughts { display: flex; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
.world .thoughts:empty { display: none; }
.world .thought {
	max-width: min(60%, 44rem); padding: 0.25rem 0.8rem;
	background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
	font-size: 0.85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
	opacity: 0; transform: translateY(5px); transition: opacity 0.35s ease, transform 0.35s ease;
}
.world .thought.shown { opacity: 1; transform: none; }
.world .thought.contradiction { border-color: var(--accent); color: var(--accent); }
.world .thought.failed { border-color: var(--bad); color: var(--bad); }
.world .thought.provenance { font-family: 'Courier New', monospace; font-size: 0.75rem; }
.world .corner { position: fixed; top: 0.6rem; left: 0.9rem; opacity: 0.45; font-size: 0.85rem; }
.world .corner:hover { opacity: 1; }
.world .corner a { margin-right: 1rem; color: var(--muted); text-decoration: none; }
.world .corner a:hover { color: var(--accent); }

.world .panel {
	position: absolute; width: 22rem; max-height: 60vh; overflow: auto;
	background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
	padding: 0.8rem 1rem; font-size: 0.9rem; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}
.world .tree {
	position: fixed; top: 0; right: 0; bottom: 0; width: min(38rem, 100vw);
	background: var(--panel); border-left: 1px solid var(--line); overflow: auto;
	padding: 0 1.2rem 1.2rem; font-size: 0.9rem; box-shadow: -2px 0 12px rgba(0, 0, 0, 0.06);
}
.world .tree-bar {
	position: sticky; top: 0; display: flex; align-items: baseline; gap: 1.2rem;
	padding: 0.8rem 0 0.6rem; margin-bottom: 0.4rem; background: var(--panel); border-bottom: 1px solid var(--line);
}
.world .tree-bar .tree-title { flex: 1; color: var(--muted); }
.world .tree-bar a { cursor: pointer; font-size: 0.85rem; }
.world .tree h3 { margin: 1rem 0 0.4rem; font-size: 0.95rem; color: var(--muted); }
.world .tree-line { padding: 0.15rem 0; line-height: 1.4; }
.world .tree-line .cost, .world .tree-line .id {
	display: inline-block; font-family: 'Courier New', monospace; font-size: 0.75rem; color: var(--muted); margin-right: 0.5rem;
}
.world .tree-line .cost { min-width: 1.6rem; text-align: right; }
.world .tree-line .id { min-width: 2.2rem; }
.world .tree-line.model { color: var(--muted); }
.world .tree-line.human { color: var(--ink); }
.world .tree-line.style { border-left: 2px solid var(--accent); padding-left: 0.5rem; }
.world .tree-line.visual { font-style: italic; }
.world .tree-line.apocryphal { text-decoration: line-through; opacity: 0.55; }
.world .tree-line .tags { color: var(--muted); font-size: 0.78rem; margin-left: 0.6rem; }
.world .tree-log { padding-left: 1.4rem; }
.world .tree-log li { margin: 0.3rem 0; color: var(--muted); }

.world .panel ul { list-style: none; }
.world .panel li { margin: 0.3rem 0; padding-left: 2.4rem; text-indent: -2.4rem; }
.world .panel .cost {
	display: inline-block; min-width: 1.9rem; margin-right: 0.5rem; text-indent: 0; text-align: right;
	font-family: 'Courier New', monospace; font-size: 0.75rem; color: var(--muted);
}

@media (max-width: 600px) {
	.form .field label { display: block; width: auto; }
	.world .panel { width: calc(100vw - 2rem); }
}
