/* 拾光 — quiet bookshop palette: deep ink, warm paper, lamplight amber. */
:root {
	--ink: #14110e;
	--ink-2: #1e1a15;
	--paper: #f3ead8;
	--paper-dim: #d9cdb4;
	--amber: #d9a05b;
	--amber-soft: #b98a4e;
	--text: #e8dfc9;
	--text-dim: #a99e86;
	--user-bubble: #2c3a4a;
	--radius: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
	margin: 0;
	background: var(--ink);
	color: var(--text);
	font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
	font-size: 15px;
}

/* ── login ─────────────────────────────────────────────── */
.login-body {
	display: flex;
	align-items: center;
	justify-content: center;
	background: radial-gradient(ellipse at 50% 30%, #241d13 0%, var(--ink) 70%);
}
.login-card {
	width: min(360px, 90vw);
	background: var(--ink-2);
	border: 1px solid #352c20;
	border-radius: 18px;
	padding: 40px 36px;
	text-align: center;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.login-mark {
	font-size: 40px;
	color: var(--amber);
	letter-spacing: 0.3em;
	text-indent: 0.3em;
	font-family: "Songti SC", "SimSun", serif;
}
.login-card h1 { font-size: 17px; font-weight: 600; margin: 18px 0 6px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 26px; }
.login-card input {
	width: 100%;
	padding: 12px 14px;
	border-radius: 10px;
	border: 1px solid #4a3d2a;
	background: #120f0b;
	color: var(--text);
	font-size: 15px;
	outline: none;
}
.login-card input:focus { border-color: var(--amber-soft); }
.login-card button {
	margin-top: 14px;
	width: 100%;
	padding: 12px;
	border: none;
	border-radius: 10px;
	background: var(--amber);
	color: #241708;
	font-size: 15px;
	font-weight: 600;
	cursor: pointer;
}
.login-card button:hover { background: var(--amber-soft); }
.login-error { color: #e07a5f; font-size: 13px; margin-top: 14px; }

/* ── chat layout ───────────────────────────────────────── */
.chat-body { display: flex; flex-direction: column; height: 100vh; }
.topbar {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 10px 18px;
	border-bottom: 1px solid #2a2318;
	background: var(--ink-2);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.persona-name {
	font-family: "Songti SC", "SimSun", serif;
	font-size: 18px;
	color: var(--amber);
	white-space: nowrap;
}
.chips { display: flex; gap: 8px; min-width: 0; }
.chip {
	background: #2a2318;
	color: var(--text-dim);
	font-size: 12px;
	padding: 4px 10px;
	border-radius: 999px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	max-width: 46vw;
}
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar-right select {
	background: #120f0b;
	color: var(--text);
	border: 1px solid #3a3020;
	border-radius: 8px;
	padding: 6px 8px;
	max-width: 220px;
}
button.ghost {
	background: transparent;
	border: 1px solid #4a3d2a;
	color: var(--text-dim);
	padding: 6px 12px;
	border-radius: 8px;
	cursor: pointer;
	font-size: 13px;
}
button.ghost:hover { color: var(--text); border-color: var(--amber-soft); }
button.ghost.danger:hover { color: #e07a5f; border-color: #8a4b3a; }

.layout { flex: 1; display: flex; min-height: 0; }
.messages {
	flex: 1;
	overflow-y: auto;
	padding: 24px clamp(16px, 6vw, 90px);
	display: flex;
	flex-direction: column;
	gap: 18px;
	background:
		radial-gradient(ellipse at 20% 0%, rgba(217, 160, 91, 0.05) 0%, transparent 50%),
		var(--ink);
}

.msg { display: flex; flex-direction: column; max-width: 78%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg-label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; padding: 0 6px; }
.bubble {
	padding: 12px 16px;
	border-radius: var(--radius);
	line-height: 1.75;
	white-space: pre-wrap;
	word-break: break-word;
}
.msg.user .bubble {
	background: var(--user-bubble);
	color: #dfe8f2;
	border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
	background: var(--paper);
	color: #33291c;
	border-bottom-left-radius: 4px;
	font-family: "Songti SC", "STSong", "SimSun", serif;
	font-size: 15.5px;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}
.bubble .action {
	font-style: normal;
	color: #8a7350;
	font-size: 0.93em;
}

/* ── scene panel ───────────────────────────────────────── */
.scene-panel {
	width: 250px;
	border-left: 1px solid #2a2318;
	background: var(--ink-2);
	padding: 18px 16px;
	overflow-y: auto;
}
.scene-panel h2 {
	font-size: 13px;
	color: var(--text-dim);
	font-weight: 600;
	margin: 0 0 12px;
	letter-spacing: 0.2em;
}
.scene-panel dl { margin: 0; }
.scene-panel dt { font-size: 11px; color: var(--text-dim); margin-top: 10px; }
.scene-panel dd { margin: 2px 0 0; font-size: 13.5px; color: var(--text); }
.affinity { margin-top: 18px; }
.affinity-label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.affinity-bar {
	height: 8px;
	background: #120f0b;
	border-radius: 999px;
	overflow: hidden;
	border: 1px solid #3a3020;
}
#affinity-fill {
	height: 100%;
	width: 0%;
	background: linear-gradient(90deg, var(--amber-soft), var(--amber));
	transition: width 0.6s ease;
}
.scene-events { font-size: 12.5px; color: var(--text-dim); margin-top: 16px; line-height: 1.6; }
.tool-indicator {
	margin-top: 16px;
	font-size: 12px;
	color: var(--amber-soft);
	animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }

/* ── composer ──────────────────────────────────────────── */
.composer {
	display: flex;
	gap: 10px;
	padding: 14px clamp(16px, 6vw, 90px);
	border-top: 1px solid #2a2318;
	background: var(--ink-2);
	align-items: flex-end;
}
.composer textarea {
	flex: 1;
	resize: none;
	background: #120f0b;
	color: var(--text);
	border: 1px solid #3a3020;
	border-radius: 12px;
	padding: 12px 14px;
	font-size: 15px;
	font-family: inherit;
	line-height: 1.5;
	outline: none;
	max-height: 140px;
}
.composer textarea:focus { border-color: var(--amber-soft); }
.composer button {
	background: var(--amber);
	border: none;
	color: #241708;
	font-weight: 600;
	font-size: 15px;
	padding: 12px 26px;
	border-radius: 12px;
	cursor: pointer;
}
.composer button:disabled { opacity: 0.5; cursor: default; }
.composer button:not(:disabled):hover { background: var(--amber-soft); }

/* ── new story modal ──────────────────────────────────── */
.modal-mask {
	position: fixed;
	inset: 0;
	background: rgba(10, 8, 5, 0.72);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 50;
}
.modal-mask[hidden] { display: none; }
.modal {
	width: min(680px, 94vw);
	max-height: 88vh;
	overflow-y: auto;
	background: var(--ink-2);
	border: 1px solid #3a3020;
	border-radius: 16px;
	padding: 22px 26px;
	box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.modal-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 8px;
}
.modal-head h2 { margin: 0; font-size: 18px; color: var(--amber); }
.modal-section h3 { font-size: 13px; color: var(--text-dim); margin: 14px 0 8px; letter-spacing: 0.08em; }
.modal-tip { font-size: 12px; color: var(--text-dim); margin: 4px 0 10px; }
.modal-row { display: flex; gap: 10px; align-items: center; }
.modal-row select {
	flex: 1;
	background: #120f0b;
	color: var(--text);
	border: 1px solid #3a3020;
	border-radius: 8px;
	padding: 9px 10px;
	font-size: 14px;
}
.modal-hr { border: none; border-top: 1px solid #2a2318; margin: 18px 0; }
.tabs {
	display: flex;
	gap: 6px;
	margin: 8px 0 14px;
	border-bottom: 1px solid #2a2318;
	padding-bottom: 10px;
}
.tabs .tab {
	background: transparent;
	border: 1px solid transparent;
	color: var(--text-dim);
	padding: 6px 16px;
	border-radius: 999px;
	cursor: pointer;
	font-size: 13.5px;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active {
	background: rgba(217, 160, 91, 0.14);
	border-color: var(--amber-soft);
	color: var(--amber);
	font-weight: 600;
}
.more-toggle {
	background: transparent;
	border: none;
	color: var(--amber-soft);
	font-size: 12.5px;
	cursor: pointer;
	padding: 8px 0 4px;
}
.more-toggle:hover { color: var(--amber); }
.form-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px 14px;
}
.form-grid[hidden] { display: none; }
.form-grid label {
	display: flex;
	flex-direction: column;
	gap: 4px;
	font-size: 12.5px;
	color: var(--text-dim);
}
.form-grid label.span2 { grid-column: span 2; }
.form-grid input,
.form-grid textarea {
	background: #120f0b;
	color: var(--text);
	border: 1px solid #3a3020;
	border-radius: 8px;
	padding: 8px 10px;
	font-size: 13.5px;
	font-family: inherit;
	resize: vertical;
	outline: none;
}
.form-grid input:focus,
.form-grid textarea:focus { border-color: var(--amber-soft); }
.modal-actions { margin-top: 16px; text-align: right; }
button.primary {
	background: var(--amber);
	border: none;
	color: #241708;
	font-weight: 600;
	font-size: 14px;
	padding: 10px 20px;
	border-radius: 10px;
	cursor: pointer;
}
button.primary:hover { background: var(--amber-soft); }
button.primary:disabled { opacity: 0.5; cursor: default; }

@media (max-width: 860px) {
	.scene-panel { display: none; }
	.msg { max-width: 92%; }
	.form-grid { grid-template-columns: 1fr; }
	.form-grid label.span2 { grid-column: span 1; }
}
