:root {
	--ink: #17264a;
	--muted: #53627f;
	--blue: #284ad7;
	--blue-soft: #edf1ff;
	--line: rgba(210, 222, 240, 0.85);
	--glass: rgba(255, 255, 255, 0.88);
	--gold: #f5b429;
	--green: #269e5c;
	--red: #d93854;
}

* { box-sizing: border-box; }
html, body {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
	color: var(--ink);
	background: #23472c;
	user-select: none;
	-webkit-user-select: none;
}

.ranch-app {
	position: relative;
	width: 100vw;
	height: 100dvh;
	overflow: hidden;
}

.ranch-canvas {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	display: block;
	touch-action: none;
}

.hidden { display: none !important; }
.px { image-rendering: pixelated; }

.glass {
	background: var(--glass);
	backdrop-filter: blur(12px);
	-webkit-backdrop-filter: blur(12px);
	border: 1px solid var(--line);
	box-shadow: 0 8px 24px rgba(16, 30, 52, 0.16);
}

/* 顶部 HUD */
.hud-top {
	position: absolute;
	top: 10px;
	left: 12px;
	right: 12px;
	z-index: 20;
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 10px;
	pointer-events: none;
}

.hud-left, .hud-right {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	pointer-events: auto;
}

.badge-card {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 6px 12px 6px 8px;
	border-radius: 16px;
}

.lv-orb {
	width: 42px;
	height: 42px;
	border-radius: 12px;
	background: linear-gradient(145deg, #2d62ec, #1d3db5);
	color: #fff;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	line-height: 1.05;
}
.lv-orb small { font-size: 9px; opacity: 0.85; }
.lv-orb strong { font-size: 13px; font-weight: 850; }

.badge-info { display: flex; flex-direction: column; gap: 4px; }
.badge-title { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 820; }
.tag-pill {
	font-size: 11px;
	font-weight: 760;
	padding: 2px 7px;
	border-radius: 999px;
	background: var(--blue-soft);
	color: var(--blue);
}

.xp-bar { width: 150px; height: 6px; border-radius: 999px; background: #dde5f5; overflow: hidden; }
.xp-fill { height: 100%; width: 20%; background: linear-gradient(90deg, #34c759, #284ad7); border-radius: 999px; transition: width 0.25s; }

.pill-btn {
	min-height: 40px;
	padding: 0 14px;
	border-radius: 12px;
	font-size: 13px;
	font-weight: 800;
	color: var(--ink);
	cursor: pointer;
}
.pill-btn.accent-green {
	background: linear-gradient(135deg, #228a4f, #18683b);
	color: #e9ffdf;
	border-color: rgba(164, 244, 152, 0.55);
}

.res-bar {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 6px 14px;
	border-radius: 14px;
	min-height: 40px;
}
.res-item { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.res-item img { width: 18px; height: 18px; image-rendering: pixelated; }
.res-item b { font-size: 14px; font-weight: 850; }
.res-item small { font-size: 11px; color: var(--muted); }
.power-item { color: #b84214; font-weight: 800; }

.cam-tools { display: flex; gap: 5px; }
.icon-btn {
	min-height: 36px;
	min-width: 36px;
	padding: 0 10px;
	border-radius: 10px;
	font-size: 13px;
	font-weight: 800;
	color: var(--ink);
	cursor: pointer;
}
.icon-btn:hover { border-color: var(--blue); color: var(--blue); }

/* 放置模式顶部横幅（绝对置顶，永不被 Toast 遮挡！） */
.placement-banner {
	position: absolute;
	top: 68px;
	left: 50%;
	transform: translateX(-50%);
	z-index: 80;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 8px 16px;
	border-radius: 999px;
	background: rgba(16, 46, 28, 0.96);
	color: #d8ffbe;
	font-size: 13.5px;
	font-weight: 800;
	border: 1.5px solid #6bf092;
	box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
	pointer-events: auto;
}
.placement-banner button {
	padding: 5px 14px;
	border-radius: 999px;
	border: none;
	background: #ff526c;
	color: #fff;
	font-weight: 850;
	cursor: pointer;
	pointer-events: auto;
}
.placement-banner button:hover { background: #ff3654; }

.toast {
	position: absolute;
	bottom: 96px;
	top: auto;
	left: 50%;
	transform: translateX(-50%);
	z-index: 45;
	padding: 9px 18px;
	border-radius: 999px;
	font-size: 13.5px;
	font-weight: 800;
	color: var(--ink);
	pointer-events: none;
	max-width: min(560px, calc(100vw - 24px));
	text-align: center;
}
.toast.is-error { background: rgba(255, 236, 240, 0.96); border-color: #f08ca0; color: #a81c36; }

/* 选中栖息地底部快捷操作条 */
.hab-bar {
	position: absolute;
	left: 50%;
	bottom: 84px;
	transform: translateX(-50%);
	z-index: 22;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 9px 14px;
	border-radius: 16px;
	max-width: min(820px, calc(100vw - 20px));
}
.hab-bar-pets { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hab-pet-chip {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 4px 10px 4px 6px;
	border-radius: 999px;
	border: 1px solid #cfd8ee;
	background: #f5f8ff;
	color: var(--ink);
	font-size: 12.5px;
	font-weight: 800;
	cursor: pointer;
}
.hab-pet-chip:hover { border-color: var(--blue); background: var(--blue-soft); }
.hab-pet-chip img { width: 28px; height: 28px; image-rendering: pixelated; }
.hab-pet-chip .star-txt { color: #d68a00; font-size: 11px; }
.hab-bar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* 一键全收 */
.sweep-btn {
	position: absolute;
	right: 16px;
	bottom: 86px;
	z-index: 21;
	display: inline-flex;
	align-items: center;
	gap: 7px;
	padding: 0 16px;
	min-height: 44px;
	border-radius: 999px;
	border: 2px solid #ffe484;
	background: linear-gradient(135deg, #2b58eb, #1e3cb5);
	color: #fff;
	font-size: 13.5px;
	font-weight: 850;
	cursor: pointer;
	box-shadow: 0 10px 24px rgba(30, 60, 181, 0.35);
}
.sweep-btn img { width: 18px; height: 18px; image-rendering: pixelated; }

/* 底部 Dock */
.dock {
	position: absolute;
	left: 50%;
	bottom: 12px;
	transform: translateX(-50%);
	z-index: 22;
	display: flex;
	gap: 6px;
	padding: 6px;
	border-radius: 18px;
}
.dock-btn {
	position: relative;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	min-width: 78px;
	min-height: 54px;
	padding: 6px 10px;
	border: 1px solid transparent;
	border-radius: 13px;
	background: transparent;
	color: var(--ink);
	font-size: 12px;
	font-weight: 800;
	cursor: pointer;
}
.dock-btn:hover { background: rgba(40, 74, 215, 0.08); }
.dock-btn.is-active { background: var(--blue); color: #fff; }
.dock-btn img { width: 22px; height: 22px; image-rendering: pixelated; }
.dock-dot {
	position: absolute;
	top: 4px;
	right: 8px;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 999px;
	background: #ff4757;
	color: #fff;
	font-style: normal;
	font-size: 10.5px;
	font-weight: 850;
	display: flex;
	align-items: center;
	justify-content: center;
}

/* 抽屉面板 */
.drawer {
	position: absolute;
	left: 50%;
	bottom: 82px;
	transform: translateX(-50%);
	z-index: 30;
	width: min(880px, calc(100vw - 20px));
	max-height: min(68vh, 560px);
	border-radius: 20px;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
.drawer-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 12px 16px;
	border-bottom: 1px solid var(--line);
	background: rgba(244, 247, 255, 0.82);
}
.drawer-head h2 { margin: 0; font-size: 16px; font-weight: 850; display: flex; align-items: center; gap: 8px; }
.drawer-close {
	width: 34px;
	height: 34px;
	border-radius: 10px;
	border: 1px solid var(--line);
	background: #fff;
	font-size: 20px;
	cursor: pointer;
	color: var(--ink);
}
.drawer-body {
	padding: 14px 16px 18px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.sec-title {
	font-size: 13px;
	font-weight: 850;
	color: var(--muted);
	margin: 2px 0 4px;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.card-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
	gap: 10px;
}
.item-card {
	display: flex;
	flex-direction: column;
	gap: 8px;
	padding: 10px 12px;
	border-radius: 14px;
	border: 1px solid #d8e2f4;
	background: rgba(255, 255, 255, 0.92);
}
.item-card.is-high { border-color: #d8b566; background: linear-gradient(180deg, #fffdf5, #fff8e4); }
.item-card.is-locked { opacity: 0.72; background: #f3f5fa; border-style: dashed; }

.item-top { display: flex; gap: 10px; align-items: center; }
.item-thumb {
	width: 64px;
	height: 56px;
	object-fit: contain;
	flex-shrink: 0;
	border-radius: 10px;
	background: #f2f6ff;
	padding: 3px;
}
.item-thumb.px { image-rendering: pixelated; }
.item-meta { min-width: 0; flex: 1; }
.item-name { font-size: 14px; font-weight: 850; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item-desc { font-size: 11.5px; color: var(--muted); line-height: 1.38; margin-top: 2px; }
.elem-row { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.elem-tag {
	font-size: 10.5px;
	font-weight: 800;
	padding: 1px 6px;
	border-radius: 6px;
}

.tier-badge { font-size: 10px; font-weight: 850; padding: 2px 6px; border-radius: 6px; }
.tier-badge.low { background: #e3f7e8; color: #197a42; }
.tier-badge.high { background: #fff0c2; color: #9c5c00; }
.tier-badge.locked { background: #e4e9f4; color: #546482; }

.btn {
	min-height: 36px;
	padding: 0 12px;
	border-radius: 10px;
	border: 1px solid #cad6ee;
	background: #fff;
	color: var(--ink);
	font-size: 12.5px;
	font-weight: 800;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 5px;
}
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: 0.48; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1e3cb8; color: #fff; }
.btn.gold { background: linear-gradient(135deg, #ffca3a, #f09418); border-color: #d47b08; color: #361d00; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }

/* 喂养进化台 */
.pet-detail-box {
	display: grid;
	grid-template-columns: 180px 1fr;
	gap: 14px;
	padding: 12px;
	border-radius: 16px;
	border: 1px solid #d5e0f4;
	background: linear-gradient(135deg, #f8fbff, #eef5ff);
}
.pet-stage {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 10px;
	border-radius: 14px;
	background: radial-gradient(circle at 50% 62%, #d8f3d2, #eef8eb);
	border: 1px solid #c5e6be;
}
.pet-stage img { width: 88px; height: 88px; image-rendering: pixelated; object-fit: contain; }
.stars-display { font-size: 15px; letter-spacing: 1px; color: #eb9d00; font-weight: 900; }

.stat-grid {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 8px;
	margin: 8px 0;
}
.stat-box {
	padding: 7px 9px;
	border-radius: 10px;
	background: #fff;
	border: 1px solid #dde6f6;
}
.stat-box small { display: block; font-size: 10.5px; color: var(--muted); }
.stat-box strong { font-size: 15px; font-weight: 850; }

.berry-feed-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.evo-banner {
	margin-top: 8px;
	padding: 10px 12px;
	border-radius: 12px;
	background: linear-gradient(135deg, #fff4cc, #ffe08a);
	border: 1.5px solid #e69d10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	flex-wrap: wrap;
}

/* 树洞开垦浮层 */
.cave-overlay {
	position: absolute;
	inset: 0;
	z-index: 50;
	background: #102418;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
.cave-topbar {
	position: absolute;
	top: 12px;
	left: 12px;
	right: 12px;
	display: flex;
	align-items: center;
	gap: 10px;
	z-index: 5;
}
.cave-title {
	padding: 8px 14px;
	border-radius: 12px;
	font-size: 13.5px;
	font-weight: 800;
}
.cave-canvas {
	max-width: min(94vw, 840px);
	max-height: 74vh;
	border-radius: 14px;
	box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
	image-rendering: pixelated;
	cursor: pointer;
}
.cave-hint {
	position: absolute;
	bottom: 16px;
	padding: 8px 16px;
	border-radius: 999px;
	font-size: 12.5px;
	font-weight: 760;
}

@media (max-width: 720px) {
	.hud-top { top: 8px; left: 8px; right: 8px; flex-direction: column; gap: 6px; }
	.hud-left, .hud-right { width: 100%; justify-content: space-between; }
	.tag-pill { display: none; }
	.xp-bar { width: 110px; }
	.cam-tools { display: none; }
	.dock { width: calc(100vw - 14px); bottom: 8px; justify-content: space-between; gap: 2px; padding: 4px; }
	.dock-btn { min-width: 0; flex: 1; padding: 6px 2px; font-size: 11px; min-height: 50px; }
	.sweep-btn { right: 8px; bottom: 68px; min-height: 40px; padding: 0 12px; font-size: 12px; }
	.hab-bar { bottom: 68px; left: 8px; right: 8px; transform: none; flex-direction: column; align-items: stretch; }
	.drawer { bottom: 68px; width: calc(100vw - 12px); max-height: 66vh; }
	.pet-detail-box { grid-template-columns: 1fr; }
}
