/* MiaowMiaowLand UI */
:root {
	--ink: #2b2622;
	--paper: #fbf9f3;
	--orange: #f88c00;
	--orange-dark: #d86f00;
	--shade: rgba(43, 38, 34, .55);
	--wobble: 255px 15px 225px 15px / 15px 225px 15px 255px;
	--safe-l: env(safe-area-inset-left, 0px);
	--safe-r: env(safe-area-inset-right, 0px);
	--safe-t: env(safe-area-inset-top, 0px);
	--safe-b: env(safe-area-inset-bottom, 0px);
	--tbtn: clamp(62px, 20vh, 104px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
	margin: 0;
	padding: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
	background: #efece4;
	color: var(--ink);
	font-family: "Patrick Hand", "Comic Sans MS", "Chalkboard SE", "Marker Felt", cursive, sans-serif;
	-webkit-user-select: none;
	user-select: none;
	-webkit-touch-callout: none;
	touch-action: manipulation;
	overscroll-behavior: none;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; margin: 0 auto; touch-action: none; }

#ui { position: fixed; inset: 0; pointer-events: none; z-index: 10; }

button { font-family: inherit; color: inherit; }

/* ---------- Screens ---------- */
.screen {
	position: absolute;
	inset: 0;
	display: none;
	opacity: 0;
	transition: opacity .25s ease;
}
.screen.active { display: flex; pointer-events: auto; }
.screen.visible { opacity: 1; }

/* ---------- Splash ---------- */
#screen-splash {
	background: #fff;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 28px;
	z-index: 50;
}
.splash-logo { width: min(60vw, 400px); animation: pop .8s ease both; }
.loadbar { width: min(50vw, 260px); height: 10px; border: 2px solid var(--ink); border-radius: var(--wobble); overflow: hidden; }
#loadbar-fill { height: 100%; width: 0; background: var(--orange); transition: width .2s; }

/* ---------- Buttons ---------- */
.btn {
	display: block;
	width: 100%;
	margin: 8px 0;
	padding: 10px 20px;
	font-size: clamp(20px, 4.6vh, 28px);
	line-height: 1.1;
	background: #fff;
	border: 3px solid var(--ink);
	border-radius: var(--wobble);
	box-shadow: 3px 4px 0 var(--ink);
	cursor: pointer;
	transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { background: #fff5e6; }
.btn:active, .btn.pressed { transform: translate(3px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn-primary { background: var(--orange); color: #fff; text-shadow: 1px 1px 0 var(--orange-dark); }
.btn-primary:hover { background: #ff9c1a; }
.btn-big { font-size: clamp(26px, 6.5vh, 38px); padding: 10px 24px; }
.btn-small { font-size: clamp(18px, 4vh, 22px); padding: 8px 12px; }
.btn:disabled { opacity: .45; pointer-events: none; }

.icon-btn {
	width: clamp(40px, 10vh, 52px);
	height: clamp(40px, 10vh, 52px);
	padding: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: #fff;
	border: 3px solid var(--ink);
	border-radius: 50% 45% 52% 48% / 48% 52% 45% 50%;
	box-shadow: 2px 3px 0 var(--ink);
	cursor: pointer;
	pointer-events: auto;
	transition: transform .08s, box-shadow .08s;
	flex: none;
}
.icon-btn:active { transform: translate(2px, 3px); box-shadow: 0 0 0 var(--ink); }

.ico { width: 60%; height: 60%; display: block; background: center / contain no-repeat; }
.ico-pause   { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 5v14M16 5v14' stroke='%232b2622' stroke-width='3.5' stroke-linecap='round'/%3E%3C/svg%3E"); }
.ico-restart { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 12a8 8 0 1 0 2.5-5.8'/%3E%3Cpath d='M4 3v5h5'/%3E%3C/svg%3E"); }
.ico-back    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 4l-8 8 8 8'/%3E%3C/svg%3E"); }
.ico-home    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 11l9-7 9 7'/%3E%3Cpath d='M6 10v10h12V10'/%3E%3C/svg%3E"); }
.ico-full    { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='2.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5'/%3E%3C/svg%3E"); }
.ico-sound   { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9h4l5-4v14l-5-4H4z' fill='%232b2622'/%3E%3Cpath d='M16.5 8.5a5 5 0 0 1 0 7M19 6a8.5 8.5 0 0 1 0 12'/%3E%3C/svg%3E"); }
.muted .ico-sound { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%232b2622' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 9h4l5-4v14l-5-4H4z' fill='%232b2622'/%3E%3Cpath d='M16 9l5 6M21 9l-5 6'/%3E%3C/svg%3E"); }

/* ---------- Main menu ---------- */
#screen-menu { align-items: center; justify-content: center; }
.menu-card {
	width: min(88vw, 360px);
	padding: clamp(10px, 3vh, 22px) 26px clamp(12px, 3vh, 22px);
	background: rgba(255, 255, 255, .92);
	border: 3px solid var(--ink);
	border-radius: var(--wobble);
	box-shadow: 5px 6px 0 var(--ink);
	text-align: center;
	animation: pop .45s ease both;
}
.title-img { width: 100%; max-height: 38vh; object-fit: contain; display: block; margin: 0 auto 6px; }
.menu-progress { margin-top: 6px; font-size: clamp(16px, 3.8vh, 20px); opacity: .75; }
.corner-buttons { position: absolute; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); display: flex; gap: 10px; }
.editor-link {
	position: absolute;
	left: calc(14px + var(--safe-l));
	bottom: calc(10px + var(--safe-b));
	font-size: 18px;
	color: var(--ink);
	opacity: .6;
	text-decoration: underline dotted;
}
.editor-link:hover { opacity: 1; }

/* ---------- Level select ---------- */
#screen-levels {
	flex-direction: column;
	background: rgba(251, 249, 243, .88);
	padding: calc(10px + var(--safe-t)) calc(14px + var(--safe-r)) calc(10px + var(--safe-b)) calc(14px + var(--safe-l));
}
.screen-header { display: flex; align-items: center; gap: 14px; flex: none; }
.screen-header h2 { margin: 0; font-size: clamp(26px, 6vh, 38px); font-weight: normal; flex: 1; }
.header-stat { font-size: clamp(18px, 4vh, 22px); }
.level-grid {
	flex: 1;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	touch-action: pan-y;
	display: grid;
	grid-template-columns: repeat(10, minmax(0, 1fr));
	gap: clamp(8px, 2vh, 14px);
	padding: 12px 4px 20px;
	align-content: start;
	max-width: min(1000px, calc((100vh - 110px) * 3.1));
	width: 100%;
	margin: 0 auto;
}
@media (max-aspect-ratio: 4/3) {
	.level-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); max-width: 640px; }
}
.level-btn {
	position: relative;
	aspect-ratio: 1;
	border: 3px solid var(--ink);
	border-radius: var(--wobble);
	background: #fff;
	box-shadow: 3px 4px 0 var(--ink);
	font-size: clamp(24px, 6vh, 34px);
	cursor: pointer;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	line-height: 1;
	transition: transform .08s, box-shadow .08s;
}
.level-btn:active { transform: translate(3px, 4px); box-shadow: 0 0 0 var(--ink); }
.level-btn small { font-size: clamp(12px, 2.8vh, 15px); margin-top: 4px; opacity: .7; }
.level-btn.done { background: #fff1dc; }
.level-btn.done::after {
	content: "";
	position: absolute;
	top: -8px; right: -8px;
	width: 26px; height: 26px;
	border-radius: 50%;
	border: 2px solid var(--ink);
	background: #6cc04a url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12l5 5 9-10'/%3E%3C/svg%3E") center / 70% no-repeat;
}
.level-btn.current { background: var(--orange); color: #fff; animation: bob 1.6s ease-in-out infinite; }
.level-btn.locked { background: #e6e2da; color: #9a948b; box-shadow: none; border-style: dashed; cursor: default; }
.level-btn.locked span {
	width: 40%; height: 40%;
	background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%239a948b' stroke-width='2.6' stroke-linecap='round'%3E%3Crect x='5' y='11' width='14' height='10' rx='2' fill='%239a948b'/%3E%3Cpath d='M8 11V8a4 4 0 0 1 8 0v3'/%3E%3C/svg%3E") center / contain no-repeat;
	font-size: 0;
}

/* ---------- HUD ---------- */
#hud {
	pointer-events: none;
	padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) 0 calc(10px + var(--safe-l));
	align-items: flex-start;
	justify-content: space-between;
	z-index: 20;
}
#hud.active { pointer-events: none; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 8px; }
.hud-pill {
	background: rgba(255, 255, 255, .88);
	border: 2px solid var(--ink);
	border-radius: var(--wobble);
	padding: 3px 12px;
	font-size: clamp(17px, 4.4vh, 24px);
	line-height: 1.2;
	white-space: nowrap;
}
.hud-level { font-weight: bold; }
.hud-name { opacity: .7; margin-left: 6px; }
.hud-food { display: flex; align-items: center; gap: 6px; transition: transform .15s, background .2s; }
.hud-food.bump { transform: scale(1.18); }
.hud-food.full { background: #d9f5c9; }
.food-ico { width: 28px; height: 18px; object-fit: cover; object-position: left; }
.hud-time { min-width: 4.2em; text-align: center; font-variant-numeric: tabular-nums; }

.hint {
	position: absolute;
	left: 50%;
	top: calc(64px + var(--safe-t));
	transform: translateX(-50%);
	max-width: 80vw;
	text-align: center;
	background: rgba(255, 255, 255, .9);
	border: 2px dashed var(--ink);
	border-radius: var(--wobble);
	padding: 4px 16px;
	font-size: clamp(16px, 4vh, 22px);
	opacity: 0;
	transition: opacity .4s;
}
.hint.show { opacity: 1; }

.toast {
	position: absolute;
	left: 50%;
	top: 42%;
	transform: translate(-50%, -50%) scale(.8);
	background: var(--ink);
	color: #fff;
	padding: 8px 22px;
	border-radius: var(--wobble);
	font-size: clamp(20px, 5vh, 28px);
	opacity: 0;
	transition: opacity .2s, transform .2s;
	white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- Touch controls ---------- */
#touch-controls { position: absolute; inset: 0; display: none; pointer-events: none; z-index: 15; }
#touch-controls.active { display: block; }
.tbtn {
	position: absolute;
	width: var(--tbtn);
	height: var(--tbtn);
	bottom: calc(14px + var(--safe-b));
	background: url("../assets/arrow.png") 0 0 / 200% 100% no-repeat;
	opacity: .78;
	transition: transform .06s, opacity .06s;
}
.tbtn::before {
	content: "";
	position: absolute;
	inset: -8%;
	border-radius: 50%;
	background: rgba(255, 255, 255, .45);
	border: 2px solid rgba(43, 38, 34, .25);
	z-index: -1;
}
.tbtn.down { background-position: 100% 0; opacity: 1; }
.tbtn-left { left: calc(18px + var(--safe-l)); }
.tbtn-right { left: calc(18px + var(--safe-l) + var(--tbtn) * 1.35); transform: scaleX(-1); }
.tbtn-jump { right: calc(22px + var(--safe-r)); transform: rotate(90deg); width: calc(var(--tbtn) * 1.1); height: calc(var(--tbtn) * 1.1); }
.tbtn-left.down { transform: scale(.92); }
.tbtn-right.down { transform: scaleX(-1) scale(.92); }
.tbtn-jump.down { transform: rotate(90deg) scale(.92); }

/* ---------- Modals ---------- */
.modal { background: var(--shade); align-items: center; justify-content: center; z-index: 30; }
.panel {
	width: min(86vw, 340px);
	max-height: 94vh;
	overflow: auto;
	padding: clamp(10px, 3vh, 22px) 24px;
	background: var(--paper);
	border: 3px solid var(--ink);
	border-radius: var(--wobble);
	box-shadow: 5px 6px 0 var(--ink);
	text-align: center;
	animation: pop .3s ease both;
}
.panel h2 { margin: 0 0 6px; font-size: clamp(30px, 7.5vh, 44px); font-weight: normal; color: var(--orange-dark); }
.panel-row { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.panel-row .btn { margin: 4px 0; }
.win-stats { display: flex; justify-content: space-around; margin: 4px 0 8px; }
.win-stats div { display: flex; flex-direction: column; }
.win-stats small { font-size: 16px; opacity: .65; }
.win-stats b { font-size: clamp(22px, 5.5vh, 30px); font-weight: normal; }
.win-badge {
	display: none;
	margin: 0 auto 6px;
	width: max-content;
	padding: 2px 14px;
	background: #ffe07a;
	border: 2px solid var(--ink);
	border-radius: var(--wobble);
	transform: rotate(-3deg);
	font-size: 20px;
}
.win-badge.show { display: block; animation: pop .4s .2s ease both; }

/* ---------- Rotate hint ---------- */
#rotate {
	position: absolute;
	inset: 0;
	display: none;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: var(--paper);
	z-index: 100;
	font-size: 24px;
	text-align: center;
	pointer-events: auto;
}
.rotate-phone {
	width: 60px;
	height: 100px;
	border: 4px solid var(--ink);
	border-radius: 12px;
	animation: turn 2s ease-in-out infinite;
}
@media (orientation: portrait) and (pointer: coarse) {
	#rotate { display: flex; }
}

@keyframes pop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes turn { 0%, 20% { transform: rotate(0); } 50%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }

@media (max-height: 380px) {
	.btn { padding: 6px 16px; margin: 6px 0; }
	.hint { top: calc(52px + var(--safe-t)); }
}
